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 OOX_HELPER_PROPERTYMAP_HXX
21 : #define 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 > PropertyMapBase;
43 :
44 : /** A helper that maps property identifiers to property values.
45 :
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
49 : property sets.
50 : */
51 16077 : class OOX_DLLPUBLIC PropertyMap : public PropertyMapBase
52 : {
53 : public:
54 : explicit PropertyMap();
55 :
56 : /** Returns the name of the passed property identifier. */
57 : static const ::rtl::OUString& getPropertyName( sal_Int32 nPropId );
58 :
59 : /** Returns true, if the map contains a property with the passed identifier. */
60 93 : inline bool hasProperty( sal_Int32 nPropId ) const
61 93 : { return find( nPropId ) != end(); }
62 :
63 : /** Sets the specified property to the passed value. Does nothing, if the
64 : identifier is invalid. */
65 0 : inline bool setAnyProperty( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue )
66 0 : { if( nPropId < 0 ) return false; (*this)[ nPropId ] = rValue; return true; }
67 :
68 : /** Sets the specified property to the passed value. Does nothing, if the
69 : identifier is invalid. */
70 : template< typename Type >
71 132 : inline bool setProperty( sal_Int32 nPropId, const Type& rValue )
72 132 : { if( nPropId < 0 ) return false; (*this)[ nPropId ] <<= rValue; return true; }
73 :
74 : /** Inserts all properties contained in the passed property map. */
75 106 : inline void assignUsed( const PropertyMap& rPropMap )
76 106 : { insert( rPropMap.begin(), rPropMap.end() ); }
77 :
78 : /** Inserts all properties contained in the passed property map */
79 : void assignAll( const PropertyMap& rPropMap );
80 :
81 : /** Returns a sequence of property values, filled with all contained properties. */
82 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >
83 : makePropertyValueSequence() const;
84 :
85 : /** Fills the passed sequences of names and anys with all contained properties. */
86 : void fillSequences(
87 : ::com::sun::star::uno::Sequence< ::rtl::OUString >& rNames,
88 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rValues ) const;
89 :
90 : /** Creates a property set supporting the XPropertySet interface and inserts all properties. */
91 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
92 : makePropertySet() const;
93 :
94 : #if OSL_DEBUG_LEVEL > 0
95 : #ifdef DBG_UTIL
96 : static void dump( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet);
97 : #endif
98 : static void dumpCode( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet);
99 : void dumpCode();
100 : #endif
101 : private:
102 : const PropertyNameVector* mpPropNames;
103 : };
104 :
105 : // ============================================================================
106 :
107 : } // namespace oox
108 :
109 : #endif
110 :
111 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|