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 _PROPMAP_HXX_
25 #define _PROPMAP_HXX_
26 
27 #include <hash_map>
28 #include <rtl/ustring.hxx>
29 #include <sal/types.h>
30 
31 typedef ::std::hash_map< ::rtl::OUString                    ,
32                          void*                              ,
33                          ::rtl::OUStringHash                ,
34                          ::std::equal_to< ::rtl::OUString > > TPropMapBase;
35 
36 class TPropMap
37 {
38     private:
39 
40         TPropMapBase m_aMap;
41 
42     public:
43 
44         template< class TValueType >
put(const::rtl::OUString & sKey,const TValueType & rValue)45         void put(const ::rtl::OUString& sKey  ,
46                  const TValueType&      rValue)
47         {
48             void* pValue = (void*)&rValue;
49             m_aMap[sKey] = pValue;
50         }
51 
52         template< class TValueType >
put_copy(const::rtl::OUString & sKey,const TValueType & rValue)53         void put_copy(const ::rtl::OUString& sKey  ,
54                       const TValueType&      rValue)
55         {
56             TValueType* pCopy = new TValueType(rValue);
57             m_aMap[sKey] = (void*)pCopy;
58         }
59 
60         template< class TValueType >
get(const::rtl::OUString & sKey,TValueType ** pValue)61         sal_Bool get(const ::rtl::OUString& sKey  ,
62                            TValueType**     pValue)
63         {
64             TPropMapBase::iterator pIt = m_aMap.find(sKey);
65             if (pIt == m_aMap.end())
66                 return sal_False;
67 
68             void*  pItem  = pIt->second;
69                   *pValue = (TValueType*)pItem;
70             return (pItem != 0);
71         }
72 
73         template< class TValueType >
get_copy(const::rtl::OUString & sKey,TValueType & rValue)74         sal_Bool get_copy(const ::rtl::OUString& sKey  ,
75                                 TValueType&      rValue)
76         {
77             TPropMapBase::iterator pIt = m_aMap.find(sKey);
78             if (pIt == m_aMap.end())
79                 return sal_False;
80 
81             void* pValue = pIt->second;
82             if ( ! pValue)
83                 return sal_False;
84 
85             rValue = *((TValueType*)pValue);
86             //delete pValue;
87             m_aMap.erase(pIt);
88             return sal_True;
89         }
90 
clear()91         void clear()
92         {
93             m_aMap.clear();
94         }
95 };
96 
97 #endif
98