128 template<
class TKey,
class TValue,
class TSize=SizeT>
144 IterKey(Size a=0, Size b=0) : a(a), b(b)
146 IterKey(
const IterKey& src)
147 { memcpy(
this, &src,
sizeof(src)); }
149 { memcpy(
this, &src,
sizeof(src));
return *
this; }
157 #if defined(EVO_CPP11) 184 Map() : size_(0), ordered_(true)
201 virtual const Item*
getiter(IterKey& iterkey,
const Key& key)
const = 0;
227 virtual MapBaseType&
set() = 0;
235 virtual MapBaseType&
set(
const MapBaseType& src) = 0;
240 virtual MapBaseType&
setempty() = 0;
247 virtual MapBaseType&
clear() = 0;
261 virtual bool null()
const = 0;
267 {
return (size_ == 0); }
280 virtual bool shared()
const = 0;
297 else if (this->
null())
301 else if (size_ == map.
size_) {
307 if (val == NULL || !(*val ==
iter->second)) {
328 {
return Iter(*
this); }
336 {
return IterM(*
this); }
340 {
return Iter(*
this); }
356 virtual bool contains(
const Key& key)
const = 0;
362 virtual const Value*
find(
const Key& key)
const = 0;
368 virtual Value*
findM(
const Key& key) = 0;
374 Iter
iter(
const Key& key)
const {
376 const Item* item = this->
getiter(iterkey, key);
377 return (item != NULL ?
Iter(*
this, iterkey, (IterItem*)item) :
Iter(*
this,
iterEND));
386 Item* item = (Item*)this->
getiter(iterkey, key);
387 return (item != NULL ?
IterM(*
this, iterkey, (IterItem*)item) :
IterM(*
this,
iterEND));
397 virtual Item&
getitem(
const Key& key,
bool* created=NULL) = 0;
406 Value&
get(
const Key& key,
bool* created=NULL)
429 virtual MapBaseType&
unshare() = 0;
475 virtual Item&
add(
const Key& key,
const Value& value,
bool update=
true) = 0;
482 virtual Item&
add(
const Item& item,
bool update=
true) = 0;
489 virtual MapBaseType&
add(
const MapBaseType& map,
bool update=
true) = 0;
503 Size
addsplit(
const T& str,
char delim=
',',
char kvdelim=
'=') {
505 delims_buf[0] = delim;
506 delims_buf[1] = kvdelim;
513 for (; tok.
nextany(delims); ++count) {
534 virtual bool remove(
const Key& key) = 0;
550 virtual void iterInitMutable() = 0;
551 virtual const IterItem* iterFirst(IterKey& key)
const = 0;
552 virtual const IterItem* iterNext(IterKey& key)
const = 0;
553 virtual const IterItem* iterLast(IterKey& key)
const = 0;
554 virtual const IterItem* iterPrev(IterKey& key)
const = 0;
569 template<
class T>
inline bool map_contains(
const T& map,
const typename T::Key& key,
const typename T::Value& value) {
570 const typename T::Value* p = map.find(key);
571 return (p != NULL && *p == value);
590 const typename TMap::Value* val = map.
find(key);
613 typename TMap::const_iterator i = map.
find(key);
627 inline const typename TMap::mapped_type*
stdlookup(
const TMap& map,
const typename TMap::key_type& key) {
628 typename TMap::const_iterator i = map.find(key);
629 return (i != map.end() ? &i->second : NULL);
642 inline typename TMap::mapped_type*
stdlookupM(TMap& map,
const typename TMap::key_type& key) {
643 typename TMap::iterator i = map.find(key);
644 return (i != map.end() ? &i->second : NULL);
typename DataCopy< SigNumType >::PassType KeyPass
Key type for passing through InitPair (C++11)
Definition: map.h:158
C convert() const
Convert string to value of given type.
Definition: substring.h:1427
Iter iter(const Key &key) const
Find (lookup) iterator for given key (const).
Definition: map.h:374
virtual bool null() const =0
Get whether map is null.
Pair< Key, Value > Item
Item type (key/value pair)
Definition: map.h:137
Iter cend() const
Get iterator at end (const).
Definition: map.h:331
Map(bool ordered)
Constructor.
Definition: map.h:190
Map< TKey, TValue, TSize > ThisType
This type.
Definition: map.h:132
Map< TKey, TValue, TSize > MapBaseType
Map base type
Definition: map.h:133
SubString lookupsub(const TMap &map, const typename TMap::Key &key)
Lookup (find) map value as SubString for given key.
Definition: map.h:589
bool null() const
Get whether null.
Definition: type.h:318
Size size_
Map size (number of items, automatically updated by concrete set members)
Definition: map.h:180
Iter cbegin() const
Get iterator at first item (const).
Definition: map.h:327
virtual Item & getitem(const Key &key, bool *created=NULL)=0
Get map item for key (mutable).
Size addsplit(const T &str, char delim=',', char kvdelim='=')
Split delimited string into map key/value items.
Definition: map.h:503
#define EVO_ONCPP11(EXPR)
Compile EXPR only if C++11 support is detected, otherwise this is a no-op.
Definition: sys.h:259
IterM end()
Get iterator at end.
Definition: map.h:343
Optimized data copy helpers.
Definition: container.h:543
virtual bool contains(const Key &key) const =0
Get whether map contains the given key.
bool operator==(const MapBaseType &map) const
Equality operator.
Definition: map.h:293
virtual const Item * getiter(IterKey &iterkey, const Key &key) const =0
Used by base class to get data to initialize iterator.
KeyPass key
Map key value
Definition: map.h:163
bool first()
Go to first item (used internally).
Definition: iter.h:465
virtual MapBaseType & clear()=0
Clear by removing all items.
Iter begin() const
Get iterator at first item (const).
Definition: map.h:339
MapBaseType & reserve(Size size)
Reserve space for new items.
Definition: map.h:464
IteratorBi< ThisType > IterM
Iterator (mutable) - IteratorBi.
Definition: map.h:155
TKey Key
Key type.
Definition: map.h:135
virtual Size capacity() const =0
Get map capacity.
virtual ~Map()
Destructor.
Definition: map.h:205
typename DataCopy< Handler >::PassType ValuePass
Value type for passing through InitPair (C++11)
Definition: map.h:159
virtual MapBaseType & setempty()=0
Set as empty but not null.
Bidirectional iterator.
Definition: iter.h:611
Key find(char ch) const
Find first occurrence of character with forward search.
Definition: substring.h:681
TValue Value
Value type.
Definition: map.h:136
const SubString & value() const
Get current token value from last call to next().
Definition: strtok.h:42
ValuePass value
Map value
Definition: map.h:164
MapBaseType & operator=(const MapBaseType &src)
Assignment operator.
Definition: map.h:219
SubString stdlookupsub(const TMap &map, const typename TMap::key_type &key)
Lookup (find) STL map value as SubString for given key.
Definition: map.h:612
IteratorDir
Iterator direction value.
Definition: iter.h:27
static void set_default(T &val)
Set value to default.
Definition: container.h:559
bool ordered() const
Get whether map is ordered.
Definition: map.h:255
const TMap::mapped_type * stdlookup(const TMap &map, const typename TMap::key_type &key)
Lookup (find) STL map value for given key (const).
Definition: map.h:627
Evo C++ Library namespace.
Definition: alg.h:11
No iterator direction.
Definition: iter.h:28
IteratorBi< ThisType >::Const Iter
Iterator (const) - IteratorBi.
Definition: map.h:154
bool operator!=(const MapBaseType &map) const
Inequality operator.
Definition: map.h:321
const MapBaseType & asconst() const
Explicitly use a const reference to this.
Definition: map.h:209
TSize Size
Size type for size values (must be unsigned integer) – default: SizeT.
Definition: map.h:134
virtual MapBaseType & capacitymin(Size min)=0
Set map capacity to at least given minimum.
bool nextany(const StringBase &delims)
Find next token using any of given delimiters.
Definition: strtok.h:321
Char delim() const
Get current delimiter before next token.
Definition: strtok.h:36
Size size() const
Get map size (number of items).
Definition: map.h:272
bool next(char delim)
Find next token using delimiter.
Definition: strtok.h:184
Iter end() const
Get iterator at end (const).
Definition: map.h:347
virtual const Value * find(const Key &key) const =0
Find (lookup) value for given key (const).
End iterator position.
Definition: iter.h:23
virtual Value * findM(const Key &key)=0
Find (lookup) value for given key (mutable).
virtual MapBaseType & unshare()=0
Make data unique by allocating new buffer, if needed (modifier).
String forward tokenizer.
Definition: strtok.h:112
virtual MapBaseType & compact()
Reduce capacity to fit current size (modifier).
Definition: map.h:453
virtual Item & add(const Key &key, const Value &value, bool update=true)=0
Add or update using given key and value.
bool ordered_
Whether map is ordered (items are kept in order by key)
Definition: map.h:181
bool empty() const
Get whether map is empty (size is 0).
Definition: map.h:266
IterM iterM(const Key &key)
Find (lookup) iterator for given key (mutable).
Definition: map.h:384
TMap::mapped_type * stdlookupM(TMap &map, const typename TMap::key_type &key)
Lookup (find) STL map value for given key (mutable).
Definition: map.h:642
Stores a key/value pair of independent objects or values.
Definition: pair.h:32
Reference and access existing string data.
Definition: substring.h:229
Value & operator[](const Key &key)
Get item value for key (mutable).
Definition: map.h:418
Associative container holding key/value pairs for fast lookup.
Definition: map.h:129
T & min(T &a, T &b)
Returns lowest of given values.
Definition: alg.h:26
TB second
Second value (same as b() and value())
Definition: pair.h:43
Initializer key/value pair, used with initializer (C++11).
Definition: map.h:162
virtual bool shared() const =0
Get whether shared.
bool map_contains(const T &map, const typename T::Key &key, const typename T::Value &value)
Check whether map contains key with matching value.
Definition: map.h:569
IterM begin()
Get iterator at first item (mutable).
Definition: map.h:335
InitPair(KeyPass key, ValuePass value)
Constructor with key and value.
Definition: map.h:170
Evo basic types and traits.
Map()
Constructor.
Definition: map.h:184