11 #include <Sawyer/Map.h>
12 #include <Sawyer/Sawyer.h>
13 #include <boost/foreach.hpp>
25 template<
class S,
class T>
51 BOOST_FOREACH (
const typename Forward::Node &anode, a.forward_.
nodes()) {
52 if (b.forward_.
exists(anode.value())) {
53 const Target &target = b.forward_[anode.value()];
54 forward_.
insert(anode.key(), target);
55 reverse_.
insert(target, anode.key());
73 if (!forward_.
exists(source))
75 reverse_.
erase(forward_[source]);
76 forward_.
erase(source);
85 if (!reverse_.
exists(target))
87 forward_.
erase(reverse_[target]);
88 reverse_.
erase(target);
98 if (!forward_.
exists(source) || forward_[source]!=target)
100 forward_.
erase(source);
101 reverse_.
erase(target);
113 forward_.
insert(source, target);
114 reverse_.
insert(target, source);
const Forward & forward() const
Return forward mapping.
Sawyer::Container::Map< Source, Target > Forward
Type for domain-to-range map.
BiMap(const BiMap< Source, U > &a, const BiMap< U, Target > &b)
Construct a new map by composition of two maps.
bool erase(const Source &source, const Target &target)
Erase a specific map entry.
const Reverse & reverse() const
Return reverse mapping.
bool eraseTarget(const Target &target)
Erase range value and its associated domain value.
void clear()
Erase all mappings.
Map & insert(const Key &key, const Value &value)
Insert or update a key/value pair.
boost::iterator_range< NodeIterator > nodes()
Iterators for container nodes.
One-to-one mapping between source and target values.
bool eraseSource(const Source &source)
Erase domain value and its associated range value.
T Target
Type of values in the range.
S Source
Type of values in the domain.
Name space for the entire library.
void insert(const Source &source, const Target &target)
Insert a new mapping.
Sawyer::Container::Map< Target, Source > Reverse
Type for range-to-domain map.
BiMap()
Default constructor.
bool exists(const Key &key) const
Determine if a key exists.
Map & erase(const Key &key)
Remove a node with specified key.
Map & clear()
Remove all nodes.