20 #ifndef ANTKEEPER_GEOM_BREP_ATTRIBUTE_MAP_HPP
21 #define ANTKEEPER_GEOM_BREP_ATTRIBUTE_MAP_HPP
28 #include <type_traits>
29 #include <unordered_map>
40 template <
class Iter,
bool Const>
49 using pointer = std::conditional<Const, const value_type*, value_type*>::type;
50 using reference = std::conditional<Const, const value_type&, value_type&>::type;
59 return &(*m_it->second);
107 return m_it == other.m_it;
112 return m_it <=> other.m_it;
117 return m_it - rhs.m_it;
157 it.m_it = m_attributes.begin();
163 it.m_it = m_attributes.begin();
177 it.m_it = m_attributes.end();
183 it.m_it = m_attributes.end();
197 [[nodiscard]]
inline bool empty() const noexcept
199 return m_attributes.empty();
203 [[nodiscard]]
inline std::size_t
size() const noexcept
205 return m_attributes.size();
217 m_attributes.clear();
232 if (
auto i = m_attributes.find(name); i != m_attributes.end())
235 i->second = std::make_unique<brep_attribute<T>>(name, m_element_count);
243 it.m_it = m_attributes.emplace(name, std::make_unique<
brep_attribute<T>>(name, m_element_count)).first;
257 it.m_it = m_attributes.erase(pos.m_it);
270 return m_attributes.erase(name);
285 if (
auto i = m_attributes.find(name); i != m_attributes.end())
292 auto pair = m_attributes.emplace(name, std::make_unique<
brep_attribute<T>>(name, m_element_count));
294 it.m_it = pair.first;
295 return {it, pair.second};
315 auto it =
find(name);
318 throw std::out_of_range(
"B-rep attribute not found");
326 auto it =
find(name);
329 throw std::out_of_range(
"B-rep attribute not found");
347 it.m_it = m_attributes.find(name);
353 it.m_it = m_attributes.find(name);
367 return m_attributes.contains(name);
379 m_element_count = other.m_element_count;
380 m_attributes.clear();
381 for (
const auto& [key, value]: other.m_attributes)
383 m_attributes.emplace(key, value->clone());
389 std::size_t m_element_count{};
390 std::unordered_map<hash::fnv1a32_t, std::unique_ptr<brep_attribute_base>> m_attributes;
Abstract base class for B-rep element attributes.
std::iter_difference_t< Iter > difference_type
iterator_template operator++(int) noexcept
iterator_template operator--(int) noexcept
constexpr pointer operator->() const noexcept
std::bidirectional_iterator_tag iterator_concept
iterator_template & operator--() noexcept
std::conditional< Const, const value_type &, value_type & >::type reference
std::conditional< Const, const value_type *, value_type * >::type pointer
iterator_template operator+(difference_type n) const noexcept
iterator_template operator-(difference_type n) const noexcept
difference_type operator-(const iterator_template &rhs) const noexcept
std::bidirectional_iterator_tag iterator_category
iterator_template & operator+=(difference_type n) noexcept
constexpr reference operator[](difference_type i) const noexcept
iterator_template & operator-=(difference_type n) noexcept
std::weak_ordering operator<=>(const iterator_template &other) const noexcept
friend iterator_template operator-(difference_type lhs, const iterator_template &rhs) noexcept
friend iterator_template operator+(difference_type lhs, const iterator_template &rhs) noexcept
iterator_template & operator++() noexcept
bool operator==(const iterator_template &other) const noexcept
constexpr reference operator*() const noexcept
Maps names to B-rep attributes.
const_iterator cbegin() const noexcept
Returns an iterator to the first attribute.
bool empty() const noexcept
Returns true if the container is empty, false otherwise.
iterator find(hash::fnv1a32_t name)
Finds an attribute with the given name.
const_iterator find(hash::fnv1a32_t name) const
Finds an attribute with the given name.
std::size_t size() const noexcept
Returns the number of attributes in the container.
iterator erase(iterator pos)
Removes an attribute from the container.
std::pair< iterator, bool > try_emplace(hash::fnv1a32_t name)
Constructs a new attribute if an attribute with the given name does not exist.
const_iterator begin() const noexcept
Returns an iterator to the first attribute.
std::size_t erase(hash::fnv1a32_t name)
Removes an attribute from the container.
iterator end() noexcept
Returns an iterator to the attribute following the last attribute.
const brep_attribute< T > & at(hash::fnv1a32_t name) const
Returns a reference to the attribute with the given name.
iterator emplace(hash::fnv1a32_t name)
Constructs a new attribute.
const_iterator end() const noexcept
Returns an iterator to the attribute following the last attribute.
void clear() noexcept
Removes all attributes from the container.
brep_attribute< T > & at(hash::fnv1a32_t name)
Returns a reference to the attribute with the given name.
iterator begin() noexcept
Returns an iterator to the first attribute.
iterator_template< std::unordered_map< hash::fnv1a32_t, std::unique_ptr< brep_attribute_base > >::const_iterator, true > const_iterator
bool contains(hash::fnv1a32_t name) const
Checks if there is an attribute with a given name in the container.
iterator_template< std::unordered_map< hash::fnv1a32_t, std::unique_ptr< brep_attribute_base > >::iterator, false > iterator
const_iterator cend() const noexcept
Returns an iterator to the attribute following the last attribute.
Container for B-rep elements.
Boundary representation (B-rep) of a mesh.
32-bit FNV-1a hash value.