1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: autoreferencemap.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef CONFIGMGR_AUTOREFERENCEMAP_HXX
32 #define CONFIGMGR_AUTOREFERENCEMAP_HXX
34 #include <rtl/ref.hxx>
42 //-----------------------------------------------------------------------------
44 template < class Key
, class Object
, class KeyCompare
= std::less
<Key
> >
45 class AutoReferenceMap
48 typedef std::map
<Key
,rtl::Reference
<Object
>,KeyCompare
> Map
;
51 ~AutoReferenceMap() {}
57 void swap(Map
& _rOtherData
)
59 m_aMap
.swap( _rOtherData
);
61 void swap(AutoReferenceMap
& _rOther
)
63 this->swap( _rOther
.m_aMap
);
67 bool has(Key
const & _aKey
) const;
68 rtl::Reference
<Object
> get(Key
const & _aKey
) const;
70 rtl::Reference
<Object
> insert(Key
const & _aKey
, rtl::Reference
<Object
> const & _anEntry
);
71 rtl::Reference
<Object
> remove(Key
const & _aKey
);
74 rtl::Reference
<Object
> internalGet(Key
const & _aKey
) const
76 typename
Map::const_iterator it
= m_aMap
.find(_aKey
);
78 return it
!= m_aMap
.end() ? it
->second
: rtl::Reference
<Object
>();
81 rtl::Reference
<Object
> internalAdd(Key
const & _aKey
, rtl::Reference
<Object
> const & _aNewRef
)
83 return m_aMap
[_aKey
] = _aNewRef
;
86 void internalDrop(Key
const & _aKey
)
93 //-----------------------------------------------------------------------------
95 template < class Key
, class Object
, class KeyCompare
>
96 bool AutoReferenceMap
<Key
,Object
,KeyCompare
>::has(Key
const & _aKey
) const
98 return internalGet(_aKey
).is();
100 //-----------------------------------------------------------------------------
102 template < class Key
, class Object
, class KeyCompare
>
103 rtl::Reference
<Object
> AutoReferenceMap
<Key
,Object
,KeyCompare
>::get(Key
const & _aKey
) const
105 return internalGet(_aKey
);
107 //-----------------------------------------------------------------------------
109 template < class Key
, class Object
, class KeyCompare
>
110 rtl::Reference
<Object
> AutoReferenceMap
<Key
,Object
,KeyCompare
>::insert(Key
const & _aKey
, rtl::Reference
<Object
> const & _anEntry
)
112 rtl::Reference
<Object
> aRef
= internalAdd(_aKey
,_anEntry
);
116 //-----------------------------------------------------------------------------
118 template < class Key
, class Object
, class KeyCompare
>
119 rtl::Reference
<Object
> AutoReferenceMap
<Key
,Object
,KeyCompare
>::remove(Key
const & _aKey
)
121 rtl::Reference
<Object
> aRef
= internalGet(_aKey
);
125 //-----------------------------------------------------------------------------
127 ////////////////////////////////////////////////////////////////////////////////
129 } // namespace configmgr