1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_OOX_HELPER_PROPERTYMAP_HXX
21 #define INCLUDED_OOX_HELPER_PROPERTYMAP_HXX
27 #include <com/sun/star/uno/Any.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include <oox/dllapi.h>
31 #include <rtl/ustring.hxx>
32 #include <sal/types.h>
34 namespace com::sun::star::beans
{
42 typedef ::std::map
< OUString
, css::uno::Any
> PropertyNameMap
;
44 /** A helper that maps property identifiers to property values.
46 The property identifiers are generated on compile time and refer to the
47 property name strings that are held by a static vector. The identifier to
48 name mapping is done internally while the properties are written to
51 class OOX_DLLPUBLIC PropertyMap
56 /** Returns the name of the passed property identifier. */
57 static const OUString
& getPropertyName( sal_Int32 nPropId
);
59 /** Returns the property identifier of the passed name. */
60 static sal_Int32
getPropertyId( std::u16string_view sPropName
);
62 /** Returns true, if the map contains a property with the passed identifier. */
63 bool hasProperty( sal_Int32 nPropId
) const;
65 /** Sets the specified property to the passed value. Does nothing, if the
66 identifier is invalid. */
67 bool setAnyProperty( sal_Int32 nPropId
, const css::uno::Any
& rValue
);
69 /** Sets the specified property to the passed value. Does nothing, if the
70 identifier is invalid. */
71 template< typename Type
>
72 bool setProperty( sal_Int32 nPropId
, Type
&& rValue
)
77 maProperties
[ nPropId
] <<= std::forward
<Type
>(rValue
);
81 /** setAnyProperty should be used */
82 bool setProperty( sal_Int32
, const css::uno::Any
& ) = delete;
84 css::uno::Any
getProperty( sal_Int32 nPropId
);
86 void erase( sal_Int32 nPropId
);
90 /** Inserts all properties contained in the passed property map. */
91 void assignUsed( const PropertyMap
& rPropMap
);
93 /** Inserts all properties contained in the passed property map */
94 void assignAll( const PropertyMap
& rPropMap
);
96 /** Returns a sequence of property values, filled with all contained properties. */
97 css::uno::Sequence
< css::beans::PropertyValue
>
98 makePropertyValueSequence() const;
100 /** Fills the passed sequences of names and anys with all contained properties. */
102 css::uno::Sequence
< OUString
>& rNames
,
103 css::uno::Sequence
< css::uno::Any
>& rValues
) const;
105 void fillPropertyNameMap(PropertyNameMap
& rMap
) const;
107 /** Creates a property set supporting the XPropertySet interface and inserts all properties. */
108 css::uno::Reference
< css::beans::XPropertySet
>
109 makePropertySet() const;
111 #if OSL_DEBUG_LEVEL > 0
113 static void dump( const css::uno::Reference
< css::beans::XPropertySet
>& rXPropSet
);
115 static void dumpCode( const css::uno::Reference
< css::beans::XPropertySet
>& rXPropSet
);
116 static void dumpData( const css::uno::Reference
<css::beans::XPropertySet
>& rXPropSet
);
119 const std::vector
<OUString
>* mpPropNames
;
120 std::map
< sal_Int32
, css::uno::Any
> maProperties
;
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */