From 203db8ffe8d4ee82ca126926232f4d4de21b7aec Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 9 Jun 2022 18:46:00 +0200 Subject: refactor: rename ObjectType to ObjectIdentifier --- src/container.cpp | 6 +++--- src/object_identifier.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++ src/object_type.cpp | 52 ----------------------------------------------- 3 files changed, 51 insertions(+), 55 deletions(-) create mode 100644 src/object_identifier.cpp delete mode 100644 src/object_type.cpp (limited to 'src') diff --git a/src/container.cpp b/src/container.cpp index 044d487..f8c4931 100644 --- a/src/container.cpp +++ b/src/container.cpp @@ -7,19 +7,19 @@ namespace yacppdic { void Container::add( - const ObjectType &type, + const ObjectIdentifier &type, const WrapperPtr &wrapper ) noexcept { _bindings.insert({ type, wrapper }); } -void Container::remove(const ObjectType &type) noexcept +void Container::remove(const ObjectIdentifier &type) noexcept { _bindings.erase(type); } -auto Container::at(const ObjectType &type) const noexcept +auto Container::at(const ObjectIdentifier &type) const noexcept -> Container::WrapperPtr { return _bindings.at(type); diff --git a/src/object_identifier.cpp b/src/object_identifier.cpp new file mode 100644 index 0000000..a743271 --- /dev/null +++ b/src/object_identifier.cpp @@ -0,0 +1,48 @@ +#include "yacppdic/object_identifier.hpp" + +#include "yacppdic/detail/internal/hash.hpp" + +#include + +namespace yacppdic +{ + +ObjectIdentifier::ObjectIdentifier(const std::type_info &type_info) noexcept + : _type_info(type_info) +{ +} + +ObjectIdentifier::ObjectIdentifier( + const std::type_info &type_info, + const std::string_view tag +) noexcept + : _type_info(type_info), _tag(tag) +{ +} + +auto ObjectIdentifier::operator==(const ObjectIdentifier &object_type) const noexcept + -> bool +{ + return hash() == object_type.hash(); +} + +auto ObjectIdentifier::hash() const noexcept -> std::size_t +{ + const auto type_hash = _type_info.hash_code(); + + return _tag.empty() ? type_hash + : combine_hashes(type_hash, std::hash()(_tag)); +} + +auto ObjectIdentifier::name() const noexcept -> std::string_view +{ + return { _type_info.name() }; +} + +auto ObjectIdentifier::tag() const noexcept -> std::string_view +{ + return _tag; +} + +} // namespace yacppdic + diff --git a/src/object_type.cpp b/src/object_type.cpp deleted file mode 100644 index 15b798c..0000000 --- a/src/object_type.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "yacppdic/object_type.hpp" - -#include "yacppdic/detail/internal/hash.hpp" - -#include - -namespace yacppdic -{ - -ObjectType::ObjectType(const std::type_info &type_info) noexcept : _type_info(type_info) -{ -} - -ObjectType::ObjectType( - const std::type_info &type_info, - const std::string_view tag -) noexcept - : _type_info(type_info), _tag(tag) -{ -} - -auto ObjectType::operator==(const ObjectType &object_type) const noexcept -> bool -{ - return hash() == object_type.hash(); -} - -auto ObjectType::hash() const noexcept -> std::size_t -{ - const auto type_hash = _type_info.hash_code(); - - return _tag == "" ? type_hash - : combine_hashes(type_hash, std::hash()(_tag)); -} - -auto ObjectType::name() const noexcept -> std::string_view -{ - return { _type_info.name() }; -} - -auto ObjectType::tag() const noexcept -> std::string_view -{ - return _tag; -} - -auto ObjectTypeHasher::operator()(const ObjectType &object_type) const noexcept - -> std::size_t -{ - return object_type.hash(); -} - -} // namespace yacppdic - -- cgit v1.2.3-18-g5258