3 #include "g_cont_common.h"
4 #include "g_cont_lst.h"
15 typedef bool (*Operator_t) (
const T& a1 ,
const T& a2 );
17 static bool less (
const T& a1 ,
const T& a2 ) {
return (a1 < a2); }
18 static bool more (
const T& a1 ,
const T& a2 ) {
return (a1 > a2); }
21 template <
class KEY ,
class T >
class gpair
27 gpair (
const Key_t& aKey ,
const Value_t& aValue ) : mKey ( aKey ) , mValue ( aValue ) {}
29 gpair& operator = (
const gpair& aPair ) { mKey = aPair.mKey ; mValue = aPair.mValue;
return *
this; }
31 const Key_t& key ( )
const {
return mKey; };
32 const Value_t& value ( )
const {
return mValue; }
34 Key_t& key ( ) {
return mKey; };
35 Value_t& value ( ) {
return mValue; }
42 template <
class KEY ,
class T ,
template<
class,
class,
class>
class SRC ,
class REF_C =
const T& >
class gmap_common :
protected lst < gpair <KEY,T> >
51 typedef REF_C ConstRef_t;
58 Value_t& operator [] (
const Key_t& aKey );
59 ConstRef_t operator [] (
const Key_t& aKey )
const;
61 bool isValueContained (
const Value_t& )
const;
62 bool isKeyContained (
const Key_t& )
const;
63 bool tryToGet (
const Key_t& , Value_t& );
65 virtual void setEmpty ( ) { PairLst_t::setEmpty ( ); }
67 bool tryRemove (
const Key_t& , Value_t& );
68 bool tryRemove (
const Key_t& );
69 Value_t doRemove (
const Key_t& );
72 virtual bool doAdd (
const Key_t& ,
const Value_t& ) = 0;
74 size_t getSize ( )
const {
return PairLst_t::getLen ( ); }
78 const PairLst_t& getPairList ( )
const {
return (
const PairLst_t&)(*this); }
81 virtual KeyComparer_t getComparer ( )
const {
return 0; }
84 template <
class KEY ,
class T ,
template<
class,
class,
class>
class SRC ,
class REF_C >
87 G_EXC_SET_CONTEXT (
"gmap_common<KEY,T,SRC,REF_C>::Value_t& gmap_common<KEY,T,SRC,REF_C>::operator [] ( const Key_t& aKey )" );
89 It_t
it = PairLst_t::getIterator ( );
91 if ( SRC<Key_t,Value_t,It_t>::search_Key ( aKey , it , this->getComparer() ) )
100 template <
class KEY ,
class T ,
template<
class,
class,
class>
class SRC ,
class REF_C >
101 typename gmap_common<KEY,T,SRC,REF_C>::ConstRef_t gmap_common<KEY,T,SRC,REF_C>::operator [] (
const Key_t& aKey )
const
103 G_EXC_SET_CONTEXT (
"gmap_common<KEY,T,SRC,REF_C>::ConstRef_t gmap_common<KEY,T,SRC,REF_C>::operator [] ( const Key_t& aKey ) const " );
105 ItConst_t it = PairLst_t::getIterator ( );
107 if ( SRC<Key_t,Value_t,ItConst_t>::search_Key ( aKey , it , this->getComparer() ) )
115 template <
class KEY ,
class T ,
template<
class,
class,
class>
class SRC ,
class REF_C >
116 bool gmap_common<KEY,T,SRC,REF_C>::tryToGet (
const Key_t& aKey , Value_t& aValue )
118 It_t it = PairLst_t::getIterator ( );
120 if ( SRC<Key_t,Value_t,It_t>::search_Key ( aKey , it , this->getComparer() ) )
122 aValue = it->value();
131 template <
class KEY ,
class T ,
template<
class,
class,
class>
class SRC ,
class REF_C >
132 bool gmap_common<KEY,T,SRC,REF_C>::isValueContained (
const Value_t& aValue )
const
134 ItConst_t it = PairLst_t::getIterator ( );
136 return SRC<Key_t,Value_t,ItConst_t>::search_Value ( aValue , it );
139 template <
class KEY ,
class T ,
template<
class,
class,
class>
class SRC ,
class REF_C >
140 bool gmap_common<KEY,T,SRC,REF_C>::isKeyContained (
const Key_t& aKey )
const
142 ItConst_t it = PairLst_t::getIterator ( );
144 return SRC<Key_t,Value_t,ItConst_t>::search_Key ( aKey , it , this->getComparer() );
147 template <
class KEY ,
class T ,
template<
class,
class,
class>
class SRC ,
class REF_C >
148 typename gmap_common<KEY,T,SRC,REF_C>::Value_t gmap_common<KEY,T,SRC,REF_C>::doRemove (
const Key_t& aKey )
150 G_EXC_SET_CONTEXT (
"gmap_common<KEY,T,SRC,REF_C>::Value_t gmap_common<KEY,T,SRC,REF_C>::doRemove ( const Key_t& aKey )" );
152 It_t it = PairLst_t::getIterator ( );
154 if ( SRC<Key_t,Value_t,It_t>::search_Key ( aKey , it , this->getComparer() ) )
156 return this->
remove ( it ).value();
166 template <
class KEY ,
class T ,
template<
class,
class,
class>
class SRC ,
class REF_C >
167 bool gmap_common<KEY,T,SRC,REF_C>::tryRemove (
const Key_t& aKey , Value_t& aValue )
169 It_t it = PairLst_t::getIterator ( );
171 if ( SRC<Key_t,Value_t,It_t>::search_Key ( aKey , it , this->getComparer() ) )
173 aValue = it->value ( );
183 template <
class KEY ,
class T ,
template<
class,
class,
class>
class SRC ,
class REF_C >
184 bool gmap_common<KEY,T,SRC,REF_C>::tryRemove (
const Key_t& aKey )
186 It_t it = PairLst_t::getIterator ( );
188 if ( SRC<Key_t,Value_t,It_t>::search_Key ( aKey , it , this->getComparer() ) )
Definition: g_cont_gmap_common.h:13
Definition: g_cont_AllocationPolicyAbstract.h:16
Definition: g_cont_lst.h:10
#define G_EXC_DEFINE(aexctypename, abaseexctypename)
Definition: g_exception_macros.h:39
Definition: g.mthread.ThreadSimpleEvent.h:5
#define G_EXC_RAISE_MSG(aexctype, amessage)
Raises an exception specifying the message.
Definition: g_exception_macros.h:58
Definition: g_cont_it.h:39
Definition: g_cont_gmap_common.h:42
Definition: g_cont_it.h:10
Definition: g_cont_gmap_common.h:21
#define G_EXC_SET_CONTEXT(acontextstr)
Sets the method context.
Definition: g_exception_macros.h:52