Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / oox / helper / propertymap.hxx
blobbadcf0d5e49b76de7291b8f3ce98a4c36f100a8e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #include <map>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <oox/dllapi.h>
29 #include <rtl/ustring.hxx>
30 #include <sal/types.h>
32 namespace com { namespace sun { namespace star { namespace beans {
33 struct PropertyValue;
34 class XPropertySet;
35 } } } }
37 namespace oox {
39 struct PropertyNameVector;
42 typedef ::std::map< sal_Int32, css::uno::Any > PropertyMapType;
43 typedef ::std::map< OUString, css::uno::Any > PropertyNameMap;
45 /** A helper that maps property identifiers to property values.
47 The property identifiers are generated on compile time and refer to the
48 property name strings that are held by a static vector. The identifier to
49 name mapping is done internally while the properties are written to
50 property sets.
52 class OOX_DLLPUBLIC PropertyMap
54 public:
55 PropertyMap();
57 /** Returns the name of the passed property identifier. */
58 static const OUString& getPropertyName( sal_Int32 nPropId );
60 /** Returns true, if the map contains a property with the passed identifier. */
61 bool hasProperty( sal_Int32 nPropId ) const;
63 /** Sets the specified property to the passed value. Does nothing, if the
64 identifier is invalid. */
65 bool setAnyProperty( sal_Int32 nPropId, const css::uno::Any& rValue );
67 /** Sets the specified property to the passed value. Does nothing, if the
68 identifier is invalid. */
69 template< typename Type >
70 bool setProperty( sal_Int32 nPropId, const Type& rValue )
72 if( nPropId < 0 )
73 return false;
75 maProperties[ nPropId ] <<= rValue;
76 return true;
79 /** setAnyProperty should be used */
80 bool setProperty( sal_Int32, const css::uno::Any& ) = delete;
82 css::uno::Any getProperty( sal_Int32 nPropId );
84 void erase( sal_Int32 nPropId );
86 bool empty() const;
88 /** Inserts all properties contained in the passed property map. */
89 void assignUsed( const PropertyMap& rPropMap );
91 /** Inserts all properties contained in the passed property map */
92 void assignAll( const PropertyMap& rPropMap );
94 /** Returns a sequence of property values, filled with all contained properties. */
95 css::uno::Sequence< css::beans::PropertyValue >
96 makePropertyValueSequence() const;
98 /** Fills the passed sequences of names and anys with all contained properties. */
99 void fillSequences(
100 css::uno::Sequence< OUString >& rNames,
101 css::uno::Sequence< css::uno::Any >& rValues ) const;
103 void fillPropertyNameMap(PropertyNameMap& rMap) const;
105 /** Creates a property set supporting the XPropertySet interface and inserts all properties. */
106 css::uno::Reference< css::beans::XPropertySet >
107 makePropertySet() const;
109 #if OSL_DEBUG_LEVEL > 0
110 #ifdef DBG_UTIL
111 static void dump( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet);
112 #endif
113 static void dumpCode( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet);
114 static void dumpData( const css::uno::Reference<css::beans::XPropertySet>& rXPropSet);
115 #endif
116 private:
117 const PropertyNameVector* mpPropNames;
119 protected:
120 PropertyMapType maProperties;
124 } // namespace oox
126 #endif
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */