15 #ifndef _DATAT_BITS_INCLUDE_TAG
16 #error Must only be included from sag_connectivity_cpp.hpp, use that instead
49 template<
typename DATA,
typename UNDERLYING,
typename PAIR>
56 _iterator(
const UNDERLYING &tabledata,
size_t capacity, int64_t offs,
bool stepToItem=
false)
57 : map_iterator(tabledata, capacity, offs, stepToItem)
59 _iterator(
const map_iterator &other): map_iterator(other) {}
60 iterator &operator=(
const map_iterator &other)
62 map_iterator::tabledata = other.tabledata;
63 map_iterator::offs = other.offs;
64 map_iterator::step = other.step;
65 map_iterator::capacity = other.capacity;
69 std::string key()
const
71 assert(map_iterator::tabledata[map_iterator::offs].key.tag ==
SAG_DATA_STRING);
72 if (map_iterator::tabledata[map_iterator::offs].key.tag !=
SAG_DATA_STRING)
throw std::runtime_error(
"Metadata key not a string");
73 return map_iterator::tabledata[map_iterator::offs].key.string;
75 std::string value()
const
78 return(convert_to<std::string>(map_iterator::operator*().second));
80 throw std::runtime_error(
"Non-stringifiable data in metadata");
84 typename map_iterator::element_t &operator*()
const
86 return reinterpret_cast<typename map_iterator::element_t &
>(map_iterator::tabledata[map_iterator::offs]);
88 typename map_iterator::element_t *operator->()
const
90 return reinterpret_cast<typename map_iterator::element_t *
>(map_iterator::tabledata + map_iterator::offs);
107 swap(std::move(tmp));
108 swap(std::move(other));
121 return static_cast<const map_t&
>(*this) ==
static_cast<const map_t&
>(other);
129 return static_cast<map_t&
>(*this).
swap(static_cast<map_t&&>(other));
137 iterator it =
find(k);
139 throw std::runtime_error(
"Element not in map");
148 const_iterator it =
find(k);
150 throw std::runtime_error(
"Element not in map");
160 iterator it =
find(k);
162 throw std::runtime_error(
"Element not in map");
171 const_iterator it =
find(k);
173 throw std::runtime_error(
"Element not in map");
186 const_iterator
find(
const char *k)
const
192 iterator
find(
const std::string &k)
198 const_iterator
find(
const std::string &k)
const
223 std::pair<iterator, bool>
insert(
const std::pair<std::string, std::string> &v)
236 std::pair<iterator, bool>
insert(
const std::pair<const char*, const char*> &v)
270 iterator
begin() {
return iterator(table?table->table:0, table?table->capacity:0, 0,
true); }
272 iterator
end() {
return iterator(table?table->table:0, table?table->capacity:0, table?table->capacity:0,
false); }
274 const_iterator
begin()
const {
return const_iterator(table?table->table:0, table?table->capacity:0, 0,
true); }
276 const_iterator
end()
const {
return const_iterator(table?table->table:0, table?table->capacity:0, table?table->capacity:0,
false); }
278 const_iterator
cbegin()
const {
return const_iterator(table?table->table:0, table?table->capacity:0, 0,
true); }
280 const_iterator
cend()
const {
return const_iterator(table?table->table:0, table?table->capacity:0, table?table->capacity:0,
false); }
iterator find(const data_t &k)
Searches the map for an item with the given key and returns an iterator to that position in the map...
std::pair< iterator, bool > insert(const std::pair< data_t &&, data_t && > &v)
Insert a new key/value pair into the map.
A container for an payload and associated metadata.
Definition: message.hpp:27
A map class which implements many of the functions on std::map.
Definition: map_t.hpp:36
size_t size() const
Returns the number of key/value pairs in the map.
Definition: map_t.hpp:285
void swap(map_t &&other)
Swap the contents of this map and other.
Definition: map_t.hpp:193
Forward/reverse and const/non-const iterators are implemented using this class.
Definition: map_t.hpp:62
void clear()
Empty the map, clean the name and free the underlying data.
bool empty() const
Returns true if the map is empty (size() == 0)
Definition: map_t.hpp:288
size_t erase(const data_t &k)
Remove the item with the specified key.
utf8-encoded const char*
Definition: sag_connectivity_c.h:46
A variant type which can be one of the following:
Definition: data_t.hpp:42