gatelib  2.1
g_cont_gmap.h
1 #pragma once
2 
3 #include "g_cont_ref.h"
4 #include "g_cont_gmap_common.h"
5 
6 namespace g
7 {
8 namespace cont
9 {
10 
11 template < class KEY , class T , class IT > struct gmap_searcher
12 {
13  typedef T Value_t;
14  typedef KEY Key_t;
15  typedef typename comparer<KEY>::Operator_t KeyComparer_t;
16 
17  static bool search_Value ( const Value_t& aValue , IT& aIterator )
18  {
19  for ( ; aIterator.isIn ( ) ; aIterator++ )
20  {
21  if ( aIterator->value ( ) == aValue )
22  {
23  return true;
24  }
25  }
26 
27  return false;
28  }
29 
30  static bool search_Key ( const Key_t& aKey , IT& aIterator , KeyComparer_t /*not used*/ )
31  {
32  for ( ; aIterator.isIn ( ) ; aIterator++ )
33  {
34  if ( aIterator->key ( ) == aKey )
35  {
36  return true;
37  }
38  }
39 
40  return false;
41  }
42 };
43 
44 template < class KEY , class T , class REF_C = const T&> class gmap : public gmap_common <KEY,T,gmap_searcher,REF_C>
45 {
46 public:
47  typedef gpair <KEY,T> Pair_t;
48  typedef lst <Pair_t> PairLst_t;
49  typedef typename PairLst_t::It_t It_t;
50  typedef typename PairLst_t::ItConst_t ItConst_t;
51  typedef KEY Key_t;
52  typedef T Value_t;
53  typedef REF_C ConstRef_t;
55 
56  gmap (
57  AllocationPolicyAbstract* aAllocPolicyP = AllocationPolicyAbstract::get_FromStandardPolicy() ,
58  int aListPageRightBits = G_LST_PAGE_MASK_BITS ,
59  int aVectorAllocDeltaRightBits = G_VECT_AL_DELTA_MASK_BITS ) :
60  Base_t(aAllocPolicyP,aListPageRightBits,aVectorAllocDeltaRightBits) {}
61 
62 
63  //returns true if the value is added, otherwise the value is updated
64  virtual bool doAdd ( const Key_t& , const Value_t& );
65 };
66 
67 template < class KEY , class T , class REF=ref<T> , class REF_C = ref_const<T> > class ref_gmap : public gmap <KEY,REF,REF_C>
68 {
69 public:
70  typedef gpair <KEY,REF> Pair_t;
71  typedef lst <Pair_t> PairLst_t;
72  typedef typename PairLst_t::It_t It_t;
73  typedef typename PairLst_t::ItConst_t ItConst_t;
74  typedef KEY Key_t;
75  typedef T Value_t;
76  typedef REF Ref_t;
77  typedef REF_C ConstRef_t;
79 
80  ref_gmap (
81  AllocationPolicyAbstract* aAllocPolicyP = AllocationPolicyAbstract::get_FromStandardPolicy() ,
82  int aListPageRightBits = G_LST_PAGE_MASK_BITS ,
83  int aVectorAllocDeltaRightBits = G_VECT_AL_DELTA_MASK_BITS ) :
84  Base_t(aAllocPolicyP,aListPageRightBits,aVectorAllocDeltaRightBits) {}
85 
86 };
87 
88 template < class KEY , class T , class REF_C > bool gmap<KEY,T,REF_C>::doAdd ( const Key_t& aKey, const Value_t& aValue)
89 {
90  It_t it = PairLst_t::getIterator ( );
91 
92  if ( gmap_searcher<Key_t,Value_t,It_t>::search_Key ( aKey , it , this->getComparer() ) )
93  {
94  it->value ( ) = aValue;
95  return false;
96  }
97  else
98  {
99  this->pushTail ( Pair_t(aKey,aValue) );
100  return true;
101  }
102 }
103 
104 }//namespace cont
105 }//namespace g
106 
Definition: g_cont_gmap_common.h:13
Definition: g_cont_gmap.h:11
Definition: g_cont_gmap.h:44
Definition: g_cont_AllocationPolicyAbstract.h:16
Definition: g_cont_lst.h:10
Definition: g.mthread.ThreadSimpleEvent.h:5
Definition: g_cont_gmap.h:67
Definition: g_cont_gmap_common.h:42
Definition: g_cont_it.h:10
Definition: g_cont_gmap_common.h:21