1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef OOX_HELPER_PROPERTYMAP_HXX 25 #define OOX_HELPER_PROPERTYMAP_HXX 26 27 #include <vector> 28 #include <map> 29 #include <com/sun/star/uno/Any.hxx> 30 #include <com/sun/star/uno/Sequence.hxx> 31 #include <rtl/ustring.hxx> 32 #include "oox/token/properties.hxx" 33 34 namespace com { namespace sun { namespace star { namespace beans { 35 struct PropertyValue; 36 class XPropertySet; 37 } } } } 38 39 namespace oox { 40 41 struct PropertyNameVector; 42 43 // ============================================================================ 44 45 typedef ::std::map< sal_Int32, ::com::sun::star::uno::Any > PropertyMapBase; 46 47 /** A helper that maps property identifiers to property values. 48 49 The property identifiers are generated on compile time and refer to the 50 property name strings that are held by a static vector. The identifier to 51 name mapping is done internally while the properties are written to 52 property sets. 53 */ 54 class PropertyMap : public PropertyMapBase 55 { 56 public: 57 explicit PropertyMap(); 58 59 /** Returns the name of the passed property identifier. */ 60 static const ::rtl::OUString& getPropertyName( sal_Int32 nPropId ); 61 62 /** Returns true, if the map contains a property with the passed identifier. */ hasProperty(sal_Int32 nPropId) const63 inline bool hasProperty( sal_Int32 nPropId ) const 64 { return find( nPropId ) != end(); } 65 66 /** Returns the property value of the specified property, or 0 if not found. */ 67 const ::com::sun::star::uno::Any* getProperty( sal_Int32 nPropId ) const; 68 69 /** Sets the specified property to the passed value. Does nothing, if the 70 identifier is invalid. */ setAnyProperty(sal_Int32 nPropId,const::com::sun::star::uno::Any & rValue)71 inline bool setAnyProperty( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue ) 72 { if( nPropId < 0 ) return false; (*this)[ nPropId ] = rValue; return true; } 73 74 /** Sets the specified property to the passed value. Does nothing, if the 75 identifier is invalid. */ 76 template< typename Type > setProperty(sal_Int32 nPropId,const Type & rValue)77 inline bool setProperty( sal_Int32 nPropId, const Type& rValue ) 78 { if( nPropId < 0 ) return false; (*this)[ nPropId ] <<= rValue; return true; } 79 80 /** Inserts all properties contained in the passed property map. */ assignUsed(const PropertyMap & rPropMap)81 inline void assignUsed( const PropertyMap& rPropMap ) 82 { insert( rPropMap.begin(), rPropMap.end() ); } 83 84 /** Returns a sequence of property values, filled with all contained properties. */ 85 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > 86 makePropertyValueSequence() const; 87 88 /** Fills the passed sequences of names and anys with all contained properties. */ 89 void fillSequences( 90 ::com::sun::star::uno::Sequence< ::rtl::OUString >& rNames, 91 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rValues ) const; 92 93 /** Creates a property set supporting the XPropertySet interface and inserts all properties. */ 94 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > 95 makePropertySet() const; 96 97 private: 98 const PropertyNameVector* mpPropNames; 99 }; 100 101 // ============================================================================ 102 103 } // namespace oox 104 105 #endif 106