20 #ifndef INCLUDED_OOX_HELPER_REFMAP_HXX
21 #define INCLUDED_OOX_HELPER_REFMAP_HXX
38 template<
typename KeyType,
typename ObjType,
typename CompType = std::less< KeyType > >
39 class RefMap :
public std::map< KeyType, std::shared_ptr< ObjType >, CompType >
42 typedef std::map< KeyType, std::shared_ptr< ObjType >, CompType >
container_type;
43 typedef typename container_type::key_type
key_type;
51 bool has( key_type nKey )
const
53 const mapped_type* pxRef =
getRef( nKey );
54 return pxRef && pxRef->get();
59 mapped_type
get( key_type nKey )
const
61 if(
const mapped_type* pxRef =
getRef( nKey ) )
return *pxRef;
67 template<
typename FunctorType >
68 void forEach(
const FunctorType& rFunctor )
const
70 std::for_each( this->
begin(), this->
end(), ForEachFunctor< FunctorType >( rFunctor ) );
75 template<
typename FuncType >
78 forEach( ::std::bind( pFunc, std::placeholders::_1 ) );
83 template<
typename FuncType,
typename ParamType1,
typename ParamType2 >
84 void forEachMem( FuncType pFunc, ParamType1 aParam1, ParamType2 aParam2 )
const
86 forEach( ::std::bind( pFunc, std::placeholders::_1, aParam1, aParam2 ) );
91 template<
typename FuncType,
typename ParamType1,
typename ParamType2,
typename ParamType3 >
92 void forEachMem( FuncType pFunc, ParamType1 aParam1, ParamType2 aParam2, ParamType3 aParam3 )
const
94 forEach( ::std::bind( pFunc, std::placeholders::_1, aParam1, aParam2, aParam3 ) );
100 template<
typename FunctorType >
103 std::for_each( this->
begin(), this->
end(), ForEachFunctorWithKey< FunctorType >( rFunctor ) );
108 template<
typename FuncType >
111 forEachWithKey( ::std::bind( pFunc, std::placeholders::_2, std::placeholders::_1 ) );
116 template<
typename FunctorType >
120 explicit ForEachFunctor(
const FunctorType& rFunctor ) : maFunctor( rFunctor ) {}
124 template<
typename FunctorType >
129 void operator()(
const value_type& rValue ) {
if( rValue.second.get() )
maFunctor( rValue.first, *rValue.second ); }
132 const mapped_type*
getRef( key_type nKey )
const
134 typename container_type::const_iterator aIt = this->
find( nKey );
135 return (aIt == this->
end()) ?
nullptr : &aIt->second;
ForEachFunctorWithKey(const FunctorType &rFunctor)
void forEachMem(FuncType pFunc, ParamType1 aParam1, ParamType2 aParam2, ParamType3 aParam3) const
Calls the passed member function of ObjType on every contained object, automatically skips all elemen...
void forEachMemWithKey(FuncType pFunc) const
Calls the passed member function of ObjType on every contained object.
std::map< KeyType, std::shared_ptr< ObjType >, CompType > container_type
void operator()(const value_type &rValue)
Template for a map of ref-counted objects with additional accessor functions.
OSQLColumns::const_iterator find(const OSQLColumns::const_iterator &first, const OSQLColumns::const_iterator &last, std::u16string_view _rVal, const ::comphelper::UStringMixEqual &_rCase)
void forEachMem(FuncType pFunc, ParamType1 aParam1, ParamType2 aParam2) const
Calls the passed member function of ObjType on every contained object, automatically skips all elemen...
enumrange< T >::Iterator begin(enumrange< T >)
bool has(key_type nKey) const
Returns true, if the object associated to the passed key exists.
container_type::mapped_type mapped_type
container_type::value_type value_type
enumrange< T >::Iterator end(enumrange< T >)
void operator()(const value_type &rValue)
container_type::key_compare key_compare
ForEachFunctor(const FunctorType &rFunctor)
void forEachWithKey(const FunctorType &rFunctor) const
Calls the passed functor for every contained object.
container_type::key_type key_type
const mapped_type * getRef(key_type nKey) const
void forEach(const FunctorType &rFunctor) const
Calls the passed functor for every contained object, automatically skips all elements that are empty ...
void forEachMem(FuncType pFunc) const
Calls the passed member function of ObjType on every contained object, automatically skips all elemen...