xref: /trunk/main/oox/inc/oox/helper/propertymap.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef OOX_HELPER_PROPERTYMAP_HXX
29 #define OOX_HELPER_PROPERTYMAP_HXX
30 
31 #include <vector>
32 #include <map>
33 #include <com/sun/star/uno/Any.hxx>
34 #include <com/sun/star/uno/Sequence.hxx>
35 #include <rtl/ustring.hxx>
36 #include "oox/token/properties.hxx"
37 
38 namespace com { namespace sun { namespace star { namespace beans {
39     struct PropertyValue;
40     class XPropertySet;
41 } } } }
42 
43 namespace oox {
44 
45 struct PropertyNameVector;
46 
47 // ============================================================================
48 
49 typedef ::std::map< sal_Int32, ::com::sun::star::uno::Any > PropertyMapBase;
50 
51 /** A helper that maps property identifiers to property values.
52 
53     The property identifiers are generated on compile time and refer to the
54     property name strings that are held by a static vector. The identifier to
55     name mapping is done internally while the properties are written to
56     property sets.
57  */
58 class PropertyMap : public PropertyMapBase
59 {
60 public:
61     explicit            PropertyMap();
62 
63     /** Returns the name of the passed property identifier. */
64     static const ::rtl::OUString& getPropertyName( sal_Int32 nPropId );
65 
66     /** Returns true, if the map contains a property with the passed identifier. */
67     inline bool         hasProperty( sal_Int32 nPropId ) const
68                             { return find( nPropId ) != end(); }
69 
70     /** Returns the property value of the specified property, or 0 if not found. */
71     const ::com::sun::star::uno::Any* getProperty( sal_Int32 nPropId ) const;
72 
73     /** Sets the specified property to the passed value. Does nothing, if the
74         identifier is invalid. */
75     inline bool         setAnyProperty( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue )
76                             { if( nPropId < 0 ) return false; (*this)[ nPropId ] = rValue; return true; }
77 
78     /** Sets the specified property to the passed value. Does nothing, if the
79         identifier is invalid. */
80     template< typename Type >
81     inline bool         setProperty( sal_Int32 nPropId, const Type& rValue )
82                             { if( nPropId < 0 ) return false; (*this)[ nPropId ] <<= rValue; return true; }
83 
84     /** Inserts all properties contained in the passed property map. */
85     inline void         assignUsed( const PropertyMap& rPropMap )
86                             { insert( rPropMap.begin(), rPropMap.end() ); }
87 
88     /** Returns a sequence of property values, filled with all contained properties. */
89     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >
90                         makePropertyValueSequence() const;
91 
92     /** Fills the passed sequences of names and anys with all contained properties. */
93     void                fillSequences(
94                             ::com::sun::star::uno::Sequence< ::rtl::OUString >& rNames,
95                             ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rValues ) const;
96 
97     /** Creates a property set supporting the XPropertySet interface and inserts all properties. */
98     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
99                         makePropertySet() const;
100 
101 private:
102     const PropertyNameVector* mpPropNames;
103 };
104 
105 // ============================================================================
106 
107 } // namespace oox
108 
109 #endif
110