20 #ifndef _TLPMUTABLECONTAINER_ 21 #define _TLPMUTABLECONTAINER_ 29 #include <tulip/tulipconf.h> 30 #include <tulip/tuliphash.h> 31 #include <tulip/StoredType.h> 32 #include <tulip/DataSet.h> 33 #include <tulip/Iterator.h> 42 class IteratorValue :
public Iterator<unsigned int> {
45 ~IteratorValue()
override {}
46 virtual unsigned int nextValue(DataMem &) = 0;
50 template <
typename TYPE>
51 class MutableContainer {
52 friend class MutableContainerTest;
53 friend class GraphUpdatesRecorder;
62 void setDefault(
typename StoredType<TYPE>::ReturnedConstValue value);
66 void setAll(
typename StoredType<TYPE>::ReturnedConstValue value);
70 void set(
const unsigned int i,
typename StoredType<TYPE>::ReturnedConstValue value,
71 bool forceDefaultValueRemoval =
false);
75 void add(
const unsigned int i, TYPE val);
79 typename StoredType<TYPE>::ReturnedConstValue
get(
const unsigned int i)
const;
83 typename StoredType<TYPE>::ReturnedValue
get(
const unsigned int i,
bool &isNotDefault)
const;
87 typename StoredType<TYPE>::ReturnedValue getDefault()
const;
91 bool hasNonDefaultValue(
const unsigned int i)
const;
98 Iterator<unsigned int> *findAll(
typename StoredType<TYPE>::ReturnedConstValue value,
99 bool equal =
true)
const;
103 unsigned int numberOfNonDefaultValues()
const;
108 bool hasNonDefaultValues()
const {
109 return numberOfNonDefaultValues() != 0;
113 MutableContainer(
const MutableContainer<TYPE> &) {}
114 void operator=(
const MutableContainer<TYPE> &) {}
115 typename StoredType<TYPE>::ReturnedConstValue operator[](
const unsigned int i)
const;
118 void compress(
unsigned int min,
unsigned int max,
unsigned int nbElements);
119 inline void vectset(
const unsigned int i,
typename StoredType<TYPE>::Value value);
120 IteratorValue *findAllValues(
typename StoredType<TYPE>::ReturnedConstValue value,
121 bool equal =
true)
const;
124 std::deque<typename StoredType<TYPE>::Value> *vData;
125 TLP_HASH_MAP<unsigned int, typename StoredType<TYPE>::Value> *hData;
126 unsigned int minIndex, maxIndex;
127 typename StoredType<TYPE>::Value defaultValue;
128 enum State { VECT = 0, HASH = 1 };
130 unsigned int elementInserted;
139 template <
typename TYPE>
140 class IteratorVect :
public tlp::IteratorValue {
142 IteratorVect(
const TYPE &value,
bool equal, std::deque<
typename StoredType<TYPE>::Value> *vData,
143 unsigned int minIndex)
144 : _value(value), _equal(equal), _pos(minIndex), vData(vData), it(vData->begin()) {
145 while (it != (*vData).end() && StoredType<TYPE>::equal((*it), _value) != _equal) {
150 bool hasNext()
override {
151 return (_pos < UINT_MAX && it != (*vData).end());
153 unsigned int next()
override {
154 unsigned int tmp = _pos;
159 }
while (it != (*vData).end() && StoredType<TYPE>::equal((*it), _value) != _equal);
163 unsigned int nextValue(DataMem &val)
override {
164 static_cast<TypedValueContainer<TYPE> &
>(val).value = StoredType<TYPE>::get(*it);
165 unsigned int pos = _pos;
170 }
while (it != (*vData).end() && StoredType<TYPE>::equal((*it), _value) != _equal);
179 std::deque<typename StoredType<TYPE>::Value> *vData;
180 typename std::deque<typename StoredType<TYPE>::Value>::const_iterator it;
185 template <
typename TYPE>
186 class IteratorHash :
public IteratorValue {
188 IteratorHash(
const TYPE &value,
bool equal,
189 TLP_HASH_MAP<
unsigned int,
typename StoredType<TYPE>::Value> *hData)
190 : _value(value), _equal(equal), hData(hData) {
191 it = (*hData).begin();
193 while (it != (*hData).end() && StoredType<TYPE>::equal((*it).second, _value) != _equal)
196 bool hasNext()
override {
197 return (it != (*hData).end());
199 unsigned int next()
override {
200 unsigned int tmp = (*it).first;
204 }
while (it != (*hData).end() && StoredType<TYPE>::equal((*it).second, _value) != _equal);
208 unsigned int nextValue(DataMem &val)
override {
209 static_cast<TypedValueContainer<TYPE> &
>(val).value = StoredType<TYPE>::get((*it).second);
210 unsigned int pos = (*it).first;
214 }
while (it != (*hData).end() && StoredType<TYPE>::equal((*it).second, _value) != _equal);
222 TLP_HASH_MAP<unsigned int, typename StoredType<TYPE>::Value> *hData;
223 typename TLP_HASH_MAP<unsigned int, typename StoredType<TYPE>::Value>::const_iterator it;
229 #include "cxx/MutableContainer.cxx"