ActiveLib
Loading...
Searching...
No Matches
Identity.h
1
6#ifndef ACTIVE_SERIALISE_IDENTITY
7#define ACTIVE_SERIALISE_IDENTITY
8
9#include "Active/Utility/String.h"
10
11namespace active::serialise {
12
18 struct Identity {
19
20 // MARK: - Constructors
21
27 name = nameIn;
28 }
29
35 Identity(const utility::String& nameIn, const utility::String::Option groupIn) {
36 name = nameIn;
37 group = groupIn;
38 }
39
41 virtual ~Identity() = default;
42
43 // MARK: - Variables
44
49 };
50
51 // MARK: - Operators
52
54 inline bool operator< (const Identity& lhs, const Identity& rhs) {
55 return (lhs.group == rhs.group) ? lhs.name < rhs.name : lhs.group < rhs.group;
56 }
57
59 inline bool operator== (const Identity& lhs, const Identity& rhs) {
60 return (lhs.name == rhs.name) && (lhs.group == rhs.group);
61 }
62
64 inline bool operator!= (const Identity& lhs, const Identity& rhs) {
65 return !(lhs == rhs);
66 }
67
68}
69
71template<>
72struct std::hash<active::serialise::Identity> {
73 std::size_t operator()(const active::serialise::Identity& identity) const noexcept {
74 std::size_t h1 = std::hash<active::utility::String>{}(identity.name);
75 if (!identity.group)
76 return h1;
77 std::size_t h2 = std::hash<active::utility::String>{}(*identity.group);
78 return h1 ^ (h2 << 1);
79 }
80};
81
82#endif //ACTIVE_SERIALISE_IDENTITY
A Unicode-aware string class.
Definition String.h:51
std::optional< String > Option
Optional.
Definition String.h:63
Definition Cargo.h:12
bool operator!=(const Identity &lhs, const Identity &rhs)
Equality operator.
Definition Identity.h:64
bool operator==(const Identity &lhs, const Identity &rhs)
Equality operator.
Definition Identity.h:59
bool operator<(const Identity &lhs, const Identity &rhs)
Less-than operator.
Definition Identity.h:54
Definition Identity.h:18
virtual ~Identity()=default
Destructor.
utility::String::Option group
Optional named group (in which the name is unique, i.e. to avoid name clashes)
Definition Identity.h:48
utility::String name
An identifying name.
Definition Identity.h:46
Identity(const utility::String &nameIn=utility::String{})
Definition Identity.h:26
Identity(const utility::String &nameIn, const utility::String::Option groupIn)
Definition Identity.h:35