diff options
author | HampusM <hampus@hampusmat.com> | 2022-05-06 18:23:11 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-05-06 18:23:11 +0200 |
commit | d8ea3721d83254e91c5617d83f2aac5a897107fb (patch) | |
tree | 19b90c6d27e9bc75457ae6a5385db6b252d77b21 /src | |
parent | b83e94a05efd4dc4d0836bbb59cb500d0c0b219a (diff) |
feat: implement tagging in container
Diffstat (limited to 'src')
-rw-r--r-- | src/container.cpp | 13 | ||||
-rw-r--r-- | src/object_type.cpp | 22 |
2 files changed, 33 insertions, 2 deletions
diff --git a/src/container.cpp b/src/container.cpp index d906f1e..00efc27 100644 --- a/src/container.cpp +++ b/src/container.cpp @@ -7,11 +7,22 @@ namespace yacppdic { void Container::add( - BaseObjectType type, + const BaseObjectType &type, const WrapperPtr<IGenericWrapper> &wrapper ) noexcept { _bindings.insert({ type, wrapper }); } +void Container::remove(const BaseObjectType &type) noexcept +{ + _bindings.erase(type); +} + +Container::WrapperPtr<IGenericWrapper> Container::at(const BaseObjectType &type +) const noexcept +{ + return _bindings.at(type); +} + } // namespace yacppdic diff --git a/src/object_type.cpp b/src/object_type.cpp index 4384e37..ee0fe66 100644 --- a/src/object_type.cpp +++ b/src/object_type.cpp @@ -1,10 +1,22 @@ #include "yacppdic/object_type.hpp" +#include "yacppdic/detail/internal/hash.hpp" + +#include <functional> + BaseObjectType::BaseObjectType(const std::type_info &type_info) noexcept : _type_info(type_info) { } +BaseObjectType::BaseObjectType( + const std::type_info &type_info, + const std::string_view tag +) noexcept + : _type_info(type_info), _tag(tag) +{ +} + auto BaseObjectType::operator==(const BaseObjectType &object_type) const noexcept -> bool { return hash() == object_type.hash(); @@ -12,7 +24,10 @@ auto BaseObjectType::operator==(const BaseObjectType &object_type) const noexcep auto BaseObjectType::hash() const noexcept -> std::size_t { - return _type_info.hash_code(); + const auto type_hash = _type_info.hash_code(); + + return _tag == "" ? type_hash + : combine_hashes(type_hash, std::hash<std::string_view>()(_tag)); } auto BaseObjectType::name() const noexcept -> std::string_view @@ -20,6 +35,11 @@ auto BaseObjectType::name() const noexcept -> std::string_view return { _type_info.name() }; } +auto BaseObjectType::tag() const noexcept -> std::string_view +{ + return _tag; +} + auto ObjectTypeHasher::operator()(const BaseObjectType &object_type) const noexcept -> std::size_t { |