21 #ifndef _TLPMUTABLECONTAINER_
22 #define _TLPMUTABLECONTAINER_
30 #include <tulip/tulipconf.h>
31 #include <tulip/tuliphash.h>
32 #include <tulip/StoredType.h>
33 #include <tulip/DataSet.h>
34 #include <tulip/Iterator.h>
38 #ifndef DOXYGEN_NOTFOR_DEVEL
43 class IteratorValue:
public Iterator<unsigned int> {
46 virtual ~IteratorValue() {}
47 virtual unsigned int nextValue(DataMem&) = 0;
49 #endif // DOXYGEN_NOTFOR_DEVEL
51 template <
typename TYPE>
52 class MutableContainer {
53 friend class MutableContainerTest;
54 friend class GraphUpdatesRecorder;
61 void setAll(
const TYPE &value);
65 void set(
const unsigned int i,
const TYPE &value);
69 void add(
const unsigned int i, TYPE val);
73 typename StoredType<TYPE>::ReturnedConstValue
get(
const unsigned int i)
const;
77 typename StoredType<TYPE>::ReturnedValue
get(
const unsigned int i,
bool& isNotDefault)
const;
81 typename StoredType<TYPE>::ReturnedValue getDefault()
const;
85 bool hasNonDefaultValue(
const unsigned int i)
const;
92 Iterator<unsigned int>* findAll(
const TYPE &value,
bool equal =
true)
const;
94 MutableContainer(
const MutableContainer<TYPE> &) {}
95 void operator=(
const MutableContainer<TYPE> &) {}
96 typename StoredType<TYPE>::ReturnedConstValue operator[](
const unsigned int i)
const;
99 void compress(
unsigned int min,
unsigned int max,
unsigned int nbElements);
100 inline void vectset(
const unsigned int i,
typename StoredType<TYPE>::Value value);
101 IteratorValue* findAllValues(
const TYPE &value,
bool equal =
true)
const;
103 std::deque<typename StoredType<TYPE>::Value> *vData;
104 TLP_HASH_MAP<unsigned int, typename StoredType<TYPE>::Value> *hData;
105 unsigned int minIndex,maxIndex;
106 typename StoredType<TYPE>::Value defaultValue;
107 enum State { VECT=0, HASH=1 };
109 unsigned int elementInserted;
118 template <
typename TYPE>
119 class IteratorVect :
public tlp::IteratorValue {
121 IteratorVect(
const TYPE &value,
bool equal, std::deque<
typename StoredType<TYPE>::Value> *vData,
unsigned int minIndex):
127 while (it!=(*vData).end() &&
128 StoredType<TYPE>::equal((*it), _value) != _equal) {
134 return (_pos<UINT_MAX && it!=(*vData).end());
136 unsigned int next() {
137 unsigned int tmp = _pos;
143 while (it!=(*vData).end() &&
144 StoredType<TYPE>::equal((*it), _value) != _equal);
148 unsigned int nextValue(DataMem& val) {
149 ((TypedValueContainer<TYPE>&) val).value = StoredType<TYPE>::get(*it);
150 unsigned int pos = _pos;
156 while (it!=(*vData).end() &&
157 StoredType<TYPE>::equal((*it), _value) != _equal);
165 std::deque<typename StoredType<TYPE>::Value> *vData;
166 typename std::deque<typename StoredType<TYPE>::Value>::const_iterator it;
170 template <
typename TYPE>
171 class IteratorHash :
public IteratorValue {
173 IteratorHash(
const TYPE &value,
bool equal, TLP_HASH_MAP<
unsigned int,
typename StoredType<TYPE>::Value> *hData):
179 while (it!=(*hData).end() &&
180 StoredType<TYPE>::equal((*it).second,_value) != _equal)
184 return (it!=(*hData).end());
186 unsigned int next() {
187 unsigned int tmp = (*it).first;
192 while (it!=(*hData).end() &&
193 StoredType<TYPE>::equal((*it).second,_value) != _equal);
197 unsigned int nextValue(DataMem& val) {
198 ((TypedValueContainer<TYPE>&) val).value =
199 StoredType<TYPE>::get((*it).second);
200 unsigned int pos = (*it).first;
205 while (it!=(*hData).end() &&
206 StoredType<TYPE>::equal((*it).second,_value) != _equal);
213 TLP_HASH_MAP<unsigned int, typename StoredType<TYPE>::Value> *hData;
214 typename TLP_HASH_MAP<unsigned int, typename StoredType<TYPE>::Value>::const_iterator it;
217 #ifndef DOXYGEN_NOTFOR_DEVEL
221 #include "cxx/MutableContainer.cxx"
223 #endif // DOXYGEN_NOTFOR_DEVEL