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