1818 ******************************************************************************/
1919
2020#include " sbg/pw_map.hpp"
21+ #include " sbg/set_fact.hpp"
2122#include " util/debug.hpp"
23+ #include " util/defs.hpp"
2224
2325#include < iostream>
2426
2527namespace SBG {
2628
2729namespace LIB {
2830
31+ // //////////////////////////////////////////////////////////////////////////////
32+ // PWMap Iterator --------------------------------------------------------------
33+ // //////////////////////////////////////////////////////////////////////////////
34+
35+ PWMap::ConstIt::ConstIt (detail::UnordPWMap::ConstIt it) : _it(it) {}
36+
37+ PWMap::ConstIt::ConstIt (detail::OrdPWMap::ConstIt it) : _it(it) {}
38+
39+ const Map& PWMap::ConstIt::operator *()
40+ {
41+ auto it_visitor = SBG::Util::Overload {
42+ [](const detail::UnordPWMap::ConstIt& i) -> const Map& { return *i; },
43+ [](const detail::OrdPWMap::ConstIt& i) -> const Map& { return i->map (); }
44+ };
45+ return std::visit (it_visitor, _it);
46+ }
47+
48+ PWMap::ConstIt PWMap::ConstIt::operator ++()
49+ {
50+ std::visit ([](auto & i) { ++i; }, _it);
51+ return *this ;
52+ }
53+
54+ bool PWMap::ConstIt::operator ==(const ConstIt& other)
55+ {
56+ return _it == other._it ;
57+ }
58+
59+ bool PWMap::ConstIt::operator !=(const ConstIt& other)
60+ {
61+ return _it != other._it ;
62+ }
63+
2964// //////////////////////////////////////////////////////////////////////////////
3065// PWMap implementations -------------------------------------------------------
3166// //////////////////////////////////////////////////////////////////////////////
@@ -72,6 +107,7 @@ PWMap::PWMap(const PWMapKind kind) : _impl()
72107 }
73108
74109 case PWMapKind::kOrdered : {
110+ _impl = detail::OrdPWMap{};
75111 break ;
76112 }
77113
@@ -95,6 +131,7 @@ PWMap::PWMap(const PWMapKind kind, Set s) : _impl()
95131 }
96132
97133 case PWMapKind::kOrdered : {
134+ _impl = detail::UnordPWMap{s};
98135 break ;
99136 }
100137
@@ -118,6 +155,7 @@ PWMap::PWMap(const PWMapKind kind, Map m) : _impl()
118155 }
119156
120157 case PWMapKind::kOrdered : {
158+ _impl = detail::UnordPWMap{m};
121159 break ;
122160 }
123161
@@ -140,12 +178,14 @@ PWMap::PWMap(detail::PWMapImpl&& impl) : _impl(std::move(impl)) {}
140178
141179PWMap::ConstIt PWMap::begin ()
142180{
143- return std::visit ([](const auto & a) { return a.begin (); }, _impl);
181+ return std::visit ([](const auto & a) { return PWMap::ConstIt (a.begin ()); }
182+ , _impl);
144183}
145184
146185PWMap::ConstIt PWMap::end ()
147186{
148- return std::visit ([](const auto & a) { return a.end (); }, _impl);
187+ return std::visit ([](const auto & a) { return PWMap::ConstIt (a.end ()); }
188+ , _impl);
149189}
150190
151191// Setters ---------------------------------------------------------------------
@@ -394,7 +434,7 @@ Set PWMap::equalImage(const PWMap& other) const
394434 return a.equalImage (b);
395435 } else {
396436 Util::ERROR (" PWMap::equalImage: mismatched implementations\n " );
397- return PWMap{PWMapKind:: kUnordered } ;
437+ return SET_FACT. createSet () ;
398438 }
399439 }
400440 , _impl, other._impl );
@@ -410,7 +450,7 @@ Set PWMap::lessImage(const PWMap& other) const
410450 return a.lessImage (b);
411451 } else {
412452 Util::ERROR (" PWMap::lessImage: mismatched implementations\n " );
413- return PWMap{PWMapKind:: kUnordered } ;
453+ return SET_FACT. createSet () ;
414454 }
415455 }
416456 , _impl, other._impl );
0 commit comments