21 #ifndef _TLPMUTABLECONTAINER_
22 #define _TLPMUTABLECONTAINER_
28 #include <tulip/tulipconf.h>
29 #include <tulip/tuliphash.h>
30 #include <tulip/StoredType.h>
31 #include <tulip/DataSet.h>
32 #include <tulip/Iterator.h>
36 #ifndef DOXYGEN_NOTFOR_DEVEL
41 class IteratorValue:
public Iterator<unsigned int> {
44 virtual ~IteratorValue() {}
45 virtual unsigned int nextValue(DataMem&) = 0;
47 #endif // DOXYGEN_NOTFOR_DEVEL
49 template <
typename TYPE>
50 class MutableContainer {
51 friend class MutableContainerTest;
52 friend class GraphUpdatesRecorder;
59 void setAll(
const TYPE &value);
63 void set(
const unsigned int i,
const TYPE &value);
67 void add(
const unsigned int i, TYPE val);
71 typename StoredType<TYPE>::ReturnedConstValue
get(
const unsigned int i)
const;
75 typename StoredType<TYPE>::ReturnedValue
get(
const unsigned int i,
bool& isNotDefault)
const;
79 typename StoredType<TYPE>::ReturnedValue getDefault()
const;
83 bool hasNonDefaultValue(
const unsigned int i)
const;
90 Iterator<unsigned int>* findAll(
const TYPE &value,
bool equal =
true)
const;
92 MutableContainer(
const MutableContainer<TYPE> &) {}
93 void operator=(
const MutableContainer<TYPE> &) {}
94 typename StoredType<TYPE>::ReturnedConstValue operator[](
const unsigned int i)
const;
97 void compress(
unsigned int min,
unsigned int max,
unsigned int nbElements);
98 inline void vectset(
const unsigned int i,
typename StoredType<TYPE>::Value value);
99 IteratorValue* findAllValues(
const TYPE &value,
bool equal =
true)
const;
101 std::deque<typename StoredType<TYPE>::Value> *vData;
102 TLP_HASH_MAP<unsigned int, typename StoredType<TYPE>::Value> *hData;
103 unsigned int minIndex,maxIndex;
104 typename StoredType<TYPE>::Value defaultValue;
105 enum State { VECT=0, HASH=1 };
107 unsigned int elementInserted;
116 template <
typename TYPE>
117 class IteratorVect :
public tlp::IteratorValue {
119 IteratorVect(
const TYPE &value,
bool equal, std::deque<
typename StoredType<TYPE>::Value> *vData,
unsigned int minIndex):
125 while (it!=(*vData).end() &&
126 StoredType<TYPE>::equal((*it), _value) != _equal) {
132 return (_pos<UINT_MAX && it!=(*vData).end());
134 unsigned int next() {
135 unsigned int tmp = _pos;
141 while (it!=(*vData).end() &&
142 StoredType<TYPE>::equal((*it), _value) != _equal);
146 unsigned int nextValue(DataMem& val) {
147 ((TypedValueContainer<TYPE>&) val).value = StoredType<TYPE>::get(*it);
148 unsigned int pos = _pos;
154 while (it!=(*vData).end() &&
155 StoredType<TYPE>::equal((*it), _value) != _equal);
163 std::deque<typename StoredType<TYPE>::Value> *vData;
164 typename std::deque<typename StoredType<TYPE>::Value>::const_iterator it;
168 template <
typename TYPE>
169 class IteratorHash :
public IteratorValue {
171 IteratorHash(
const TYPE &value,
bool equal, TLP_HASH_MAP<
unsigned int,
typename StoredType<TYPE>::Value> *hData):
177 while (it!=(*hData).end() &&
178 StoredType<TYPE>::equal((*it).second,_value) != _equal)
182 return (it!=(*hData).end());
184 unsigned int next() {
185 unsigned int tmp = (*it).first;
190 while (it!=(*hData).end() &&
191 StoredType<TYPE>::equal((*it).second,_value) != _equal);
195 unsigned int nextValue(DataMem& val) {
196 ((TypedValueContainer<TYPE>&) val).value =
197 StoredType<TYPE>::get((*it).second);
198 unsigned int pos = (*it).first;
203 while (it!=(*hData).end() &&
204 StoredType<TYPE>::equal((*it).second,_value) != _equal);
211 TLP_HASH_MAP<unsigned int, typename StoredType<TYPE>::Value> *hData;
212 typename TLP_HASH_MAP<unsigned int, typename StoredType<TYPE>::Value>::const_iterator it;
215 #ifndef DOXYGEN_NOTFOR_DEVEL
219 #include "cxx/MutableContainer.cxx"
221 #endif // DOXYGEN_NOTFOR_DEVEL