Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_OOX_HELPER_PROPERTYMAP_HXX
21 : #define INCLUDED_OOX_HELPER_PROPERTYMAP_HXX
22 :
23 : #include <vector>
24 : #include <map>
25 : #include <com/sun/star/uno/Any.hxx>
26 : #include <com/sun/star/uno/Sequence.hxx>
27 : #include <rtl/ustring.hxx>
28 : #include <oox/token/properties.hxx>
29 : #include <oox/dllapi.h>
30 :
31 : namespace com { namespace sun { namespace star { namespace beans {
32 : struct PropertyValue;
33 : class XPropertySet;
34 : } } } }
35 :
36 : namespace oox {
37 :
38 : struct PropertyNameVector;
39 :
40 :
41 :
42 : typedef ::std::map< sal_Int32, ::com::sun::star::uno::Any > PropertyMapType;
43 : typedef ::std::map< OUString, ::com::sun::star::uno::Any > PropertyNameMap;
44 :
45 : /** A helper that maps property identifiers to property values.
46 :
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.
51 : */
52 0 : class OOX_DLLPUBLIC PropertyMap
53 : {
54 : public:
55 : PropertyMap();
56 :
57 : /** Returns the name of the passed property identifier. */
58 : static const OUString& getPropertyName( sal_Int32 nPropId );
59 :
60 : /** Returns true, if the map contains a property with the passed identifier. */
61 : bool hasProperty( sal_Int32 nPropId ) const;
62 :
63 : /** Sets the specified property to the passed value. Does nothing, if the
64 : identifier is invalid. */
65 : bool setAnyProperty( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue );
66 :
67 : /** Sets the specified property to the passed value. Does nothing, if the
68 : identifier is invalid. */
69 : template< typename Type >
70 0 : bool setProperty( sal_Int32 nPropId, const Type& rValue )
71 : {
72 0 : if( nPropId < 0 )
73 0 : return false;
74 :
75 0 : maProperties[ nPropId ] <<= rValue;
76 0 : return true;
77 : }
78 :
79 : com::sun::star::uno::Any getProperty( sal_Int32 nPropId );
80 :
81 : void erase( sal_Int32 nPropId );
82 :
83 : bool empty() const;
84 : size_t size() const;
85 :
86 : /** Inserts all properties contained in the passed property map. */
87 : void assignUsed( const PropertyMap& rPropMap );
88 :
89 : /** Inserts all properties contained in the passed property map */
90 : void assignAll( const PropertyMap& rPropMap );
91 :
92 : /** Returns a sequence of property values, filled with all contained properties. */
93 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >
94 : makePropertyValueSequence() const;
95 :
96 : /** Fills the passed sequences of names and anys with all contained properties. */
97 : void fillSequences(
98 : ::com::sun::star::uno::Sequence< OUString >& rNames,
99 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rValues ) const;
100 :
101 : void fillPropertyNameMap(PropertyNameMap& rMap) const;
102 :
103 : /** Creates a property set supporting the XPropertySet interface and inserts all properties. */
104 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
105 : makePropertySet() const;
106 :
107 : #if OSL_DEBUG_LEVEL > 0
108 : #ifdef DBG_UTIL
109 : static void dump( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet);
110 : #endif
111 : static void dumpCode( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet);
112 : void dumpCode();
113 : #endif
114 : private:
115 : const PropertyNameVector* mpPropNames;
116 :
117 : protected:
118 : PropertyMapType maProperties;
119 : };
120 :
121 :
122 :
123 : } // namespace oox
124 :
125 : #endif
126 :
127 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|