diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-10-17 02:31:29 +0200 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-10-17 02:31:29 +0200 |
commit | a0fd3902ebd44b71505c71ab9efcf1b8da74d104 (patch) | |
tree | 79b5d85e566c5b37364a459978d6aa089c1bdadc | |
parent | e933ccb59c7f032d2ffc5c5f7046317a06e85e14 (diff) |
core: Experimental idea for describing object relations with IDs
-rw-r--r-- | c++/core/id.h | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/c++/core/id.h b/c++/core/id.h index f23d206..cebb3bc 100644 --- a/c++/core/id.h +++ b/c++/core/id.h @@ -1,13 +1,25 @@ #pragma once namespace saw { +/** + * ID class which is tied to it's representing class + */ template<typename T> class id { private: + /** + * Alias for the value type representing the ID + */ using type = uint64_t; + /** + * The low level value + */ type value_; public: + /** + * Basic constructor for the id class + */ id(type val): value_{val} {} @@ -15,16 +27,45 @@ public: SAW_DEFAULT_COPY(id); SAW_DEFAULT_MOVE(id); + /** + * Equal operator for the id. + * Returns true if equal, false otherwise. + */ bool operator==(const id<T>& rhs) const { return value_ == rhs.value_; } + /** + * Unequal operator for the id. + * Returns false if equal, true otherwise. + */ bool operator!=(const id<T>& rhs) const { return !(*this == rhs); } - type get_value() const { + /** + * Returns a const ref of the underlying base type. + * Mostly used for internal purposes. + */ + const type& get_value() const { return value_; } }; + +/** + * @experimental + * Container for a class which has relations to the provided id classes. + * Meant as an idea for a generic class which uses this + */ +template<typename T, typename... Ids> +class obj_owns_ids { +private: + std::tuple<Ids...> children_; + T obj_; +public: + obj_owns_ids(T obj, Ids... children): + obj_{std::move(obj)}, + children_{std::move(children)} + {} +}; } |