68 friend ostream&
operator<<(ostream& os,
const Id& val) {
return val.
_hash ? os << val.
_hash : os <<
"idnull"; }
70 friend ByteStream&
operator<<(ByteStream& os,
const Id& val);
103 constexpr
const char*
name()
const {
return _name; }
107 constexpr
operator szt()
const {
return _hash; }
110 friend ostream&
operator<<(ostream& os,
const IdLiteral& val) {
return val._hash ? os << val._name : os <<
"idnull"; }
112 friend ostream&
operator<<(ostream& os,
const IdLiteral& val) {
return val._hash ? os << val._hash : os <<
"idnull"; }
124 #define idnull IdLiteral()
133 inline Id::Id(
const IdLiteral& rhs) :
debug_if(_name(rhs._name),) _hash(rhs._hash) {}
134 inline Id& Id::operator=(
const IdLiteral& rhs) {
debug_if(_name = rhs._name;) _hash = rhs._hash; return *this; }
135 inline
bool Id::operator==(const IdLiteral& rhs)
const {
return _hash == rhs._hash; }
136 inline bool Id::operator!=(
const IdLiteral& rhs)
const {
return _hash != rhs._hash; }
137 inline bool Id::operator<=(
const IdLiteral& rhs)
const {
return _hash <= rhs._hash; }
138 inline bool Id::operator>=(
const IdLiteral& rhs)
const {
return _hash >= rhs._hash; }
139 inline bool Id::operator< (
const IdLiteral& rhs)
const {
return _hash < rhs._hash; }
140 inline bool Id::operator> (
const IdLiteral& rhs)
const {
return _hash > rhs._hash; }
143 class NameId :
public Id
149 NameId(
const char* name) :
Id(name), _name(name) {}
171 struct std::hash<
honey::Id>
173 size_t operator()(
const honey::Id& val)
const {
return val.
hash(); }
177 struct std::hash<
honey::IdLiteral>
183 struct std::hash<
honey::NameId>
szt fast(ByteBufConst bs, szt seed)
Quickly generate a small hash value. Each seed value produces a unique hash from the same data...
Definition: Hash.cpp:99
Id(const String &name)
Definition: Id.h:30
friend ostream & operator<<(ostream &os, const IdLiteral &val)
Definition: Id.h:110
istream & operator>>(istream &is, Bytes &val)
Definition: Bytes.cpp:16
friend ostream & operator<<(ostream &os, const NameId &val)
Definition: Id.h:157
constexpr szt hash() const
Definition: Id.h:105
Holds both a name string and its hashed value, and unlike Id the name is never compiled out...
Definition: Id.h:144
bool operator>(const String &lhs, const String &rhs)
Definition: String.h:148
constexpr IdLiteral()
Definition: Id.h:85
bool operator>(const Id &rhs) const
Definition: Id.h:44
szt hash() const
Get hashed integral value of name.
Definition: Id.h:60
friend ByteStream & operator>>(ByteStream &is, Id &val)
Id from bytes.
Definition: ByteStream.h:344
bool operator!=(const String &lhs, const String &rhs)
Definition: String.h:142
Id(const String &name, szt hash)
Construct with precalculated hash.
Definition: Id.h:32
Id & operator=(Id &&rhs)
Definition: Id.h:38
Id created from a string literal at compile-time.
Definition: Id.h:81
constexpr bool operator<=(const IdLiteral &rhs) const
Definition: Id.h:92
bool operator<=(const Id &rhs) const
Definition: Id.h:99
bool operator>=(const Id &rhs) const
Definition: Id.h:100
constexpr const char * name() const
Definition: Id.h:103
NameId(const char *name)
Definition: Id.h:149
Id(Id &&rhs)
Definition: Id.h:35
bool operator>=(const Id &rhs) const
Definition: Id.h:46
constexpr szt fast_(const char *str, szt len, szt seed=0)
Compile-time version of fast() for UTF-8 strings.
Definition: Hash.h:96
NameId(const String &name)
Definition: Id.h:148
Id & operator=(const Id &rhs)
Definition: Id.h:37
bool operator<(const String &lhs, const String &rhs)
Definition: String.h:145
bool operator!=(const Id &rhs) const
Definition: Id.h:42
const String & name() const
Get name string that this id represents.
Definition: Id.h:57
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
bool operator<=(const Id &rhs) const
Definition: Id.h:45
Unicode UTF-16 string class, wrapper around std::u16string.
Definition: String.h:23
An I/O stream into which objects may be serialized and subsequently deserialized. ...
Definition: ByteStream.h:63
bool operator<(const Id &rhs) const
Definition: Id.h:43
bool operator==(const Id &rhs) const
Definition: Id.h:95
constexpr bool operator!=(const IdLiteral &rhs) const
Definition: Id.h:89
size_t szt
Size type, shorthand for size_t.
Definition: Core.h:90
constexpr bool operator>(const IdLiteral &rhs) const
Definition: Id.h:91
NameId(const Id &id)
Create with id, leaving name empty.
Definition: Id.h:151
szt _hash
Definition: Id.h:77
constexpr bool operator>=(const IdLiteral &rhs) const
Definition: Id.h:93
Id(const Id &rhs)
Definition: Id.h:34
constexpr bool operator==(const IdLiteral &rhs) const
Definition: Id.h:88
#define debug_if(...)
Evaluate expression in debug mode only, does nothing in final mode.
Definition: Debug.h:30
constexpr IdLiteral(const char *str, szt len)
Definition: Id.h:86
bool operator<=(const String &lhs, const String &rhs)
Definition: String.h:151
NameId(const String &name, const Id &id)
Create with name and precalculated id.
Definition: Id.h:153
constexpr bool operator<(const IdLiteral &rhs) const
Definition: Id.h:90
bool operator==(const Id &rhs) const
Definition: Id.h:41
Holds a name string and its hashed value for fast comparison ops. See String Identifier.
Definition: Id.h:25
bool operator!=(const Id &rhs) const
Definition: Id.h:96
bool operator>=(const String &lhs, const String &rhs)
Definition: String.h:154
ostream & operator<<(ostream &os, const Bytes &val)
Definition: Bytes.cpp:9
const String & name() const
Definition: Id.h:155
String _name
Definition: Id.h:75
Global Honeycomb namespace.
friend ostream & operator<<(ostream &os, const Id &val)
Definition: Id.h:66