From e1496a87178d925277aceed0ebcbab06920e15ee Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Mon, 25 Dec 2023 02:42:11 -0500 Subject: Add `https://github.com/Tessil/ordered-map` Add is_specialization_of to Utility.hpp Add OpenVic::ordered_map and OpenVic::ordered_set Change `std::map` to `ordered_map` Change `std::set to use `ordered_set` Add `set_callback_pointer(tsl::ordered_set& set)` Add mutable_iterator to enable mutable value iterator for `tsl::ordered_map` Add std::hash implementation Enable deps/SCsub to expose dependency includes neccessary for inclusion --- src/openvic-simulation/utility/TslHelper.hpp | 129 +++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/openvic-simulation/utility/TslHelper.hpp (limited to 'src/openvic-simulation/utility/TslHelper.hpp') diff --git a/src/openvic-simulation/utility/TslHelper.hpp b/src/openvic-simulation/utility/TslHelper.hpp new file mode 100644 index 0000000..9d1ae77 --- /dev/null +++ b/src/openvic-simulation/utility/TslHelper.hpp @@ -0,0 +1,129 @@ +#pragma once + +#include + +#include +#include + +#include "openvic-simulation/types/OrderedContainers.hpp" +#include "openvic-simulation/utility/Utility.hpp" + +namespace OpenVic { + template + struct _OrderedMapMutable { + using map_type = Map; + struct ordered_iterator { + using key_type = Key; + using mapped_type = Mapped; + using pair_type = std::pair; + using value_type = pair_type; + using iterator = typename map_type::iterator; + + using iterator_category = std::random_access_iterator_tag; + using difference_type = typename map_type::values_container_type::iterator::difference_type; + + pair_type operator*() { + return { m_iterator.key(), m_iterator.value() }; + } + + ordered_iterator& operator++() { + ++m_iterator; + return *this; + } + ordered_iterator& operator--() { + --m_iterator; + return *this; + } + + ordered_iterator operator++(int) { + ordered_iterator tmp(*this); + ++(*this); + return tmp; + } + ordered_iterator operator--(int) { + ordered_iterator tmp(*this); + --(*this); + return tmp; + } + + pair_type operator[](difference_type n) { + return *(*this + n); + } + + ordered_iterator& operator+=(difference_type n) { + m_iterator += n; + return *this; + } + ordered_iterator& operator-=(difference_type n) { + m_iterator -= n; + return *this; + } + + ordered_iterator operator+(difference_type n) { + ordered_iterator tmp(*this); + tmp += n; + return tmp; + } + ordered_iterator operator-(difference_type n) { + ordered_iterator tmp(*this); + tmp -= n; + return tmp; + } + + bool operator==(const ordered_iterator& rhs) const { + return m_iterator == rhs.m_iterator; + } + + bool operator!=(const ordered_iterator& rhs) const { + return m_iterator != rhs.m_iterator; + } + + bool operator<(const ordered_iterator& rhs) const { + return m_iterator < rhs.m_iterator; + } + + bool operator>(const ordered_iterator& rhs) const { + return m_iterator > rhs.m_iterator; + } + + bool operator<=(const ordered_iterator& rhs) const { + return m_iterator <= rhs.m_iterator; + } + + bool operator>=(const ordered_iterator& rhs) const { + return m_iterator >= rhs.m_iterator; + } + + friend ordered_iterator operator+(difference_type n, const ordered_iterator& it) { + return n + it.m_iterator; + } + + ordered_iterator operator+(const ordered_iterator& rhs) const { + return m_iterator + rhs.m_iterator; + } + + difference_type operator-(const ordered_iterator& rhs) const { + return m_iterator - rhs.m_iterator; + } + + iterator m_iterator; + }; + + _OrderedMapMutable(map_type& map) : _map(map) {} + + ordered_iterator begin() { + return ordered_iterator { _map.begin() }; + } + ordered_iterator end() { + return ordered_iterator { _map.end() }; + } + + private: + map_type& _map; + }; + + template + _OrderedMapMutable mutable_iterator(Map& map) { + return _OrderedMapMutable { map }; + } +} -- cgit v1.2.3-56-ga3b1