15 template <u
int64_t Tag,
typename T>
19 constexpr
bool IsTagged(uint64_t query){
return query ==
Tag; }
24 inline constexpr uint64_t
Hash(
const char (&
string)[N]);
50 template <u
int64_t Tag>
64 template <uint64_t
Tag,
typename... Args>
69 template <uint64_t
Tag,
typename Default,
typename... Args>
72 template <
typename... Args>
77 template <uint64_t
Tag,
bool exists,
typename Default,
typename... Args>
82 template <uint64_t
Tag,
typename Default,
typename... Args>
91 template <uint64_t
Tag,
typename Default,
typename... Args>
92 inline typename TypeOfTagDefault<
Tag,Default,Args...>
::Result
101 return i == str.size() ? hash :
102 HashString(str, i + 1, ((hash << 5) ^ (hash >> 27)) ^ str[i]);
110 template <
typename... Args>
114 template<u
int64_t Tag>
121 template<u
int64_t Tag,
typename T>
124 return kw::Get(*
this, key, default_value);
127 template<
typename ReturnType>
128 ReturnType
GetAs(uint64_t tag, ReturnType default_value) {
129 return default_value;
132 template<
typename ReturnType>
133 ReturnType
GetAs(
const std::string& tag, ReturnType default_value) {
151 constexpr
Tag(
const char (&
string)[N])
156 constexpr
Tag(
const char*
string,
size_t len)
176 constexpr uint64_t
Hash(
int i, uint64_t hash) {
177 return i ==
size() ? hash :
178 Hash(i + 1, ((hash << 5) ^ (hash >> 27)) ^
m_ptr[i]);
193 inline constexpr uint64_t
Hash(
const char (&
string)[N]){
194 return Tag(
string).Hash();
205 #ifndef DOXYGEN_IGNORE
211 template <
typename T,
typename ReturnType>
219 template <
typename Head,
typename... Tail>
227 template <u
int64_t Tag>
232 template<u
int64_t Tag,
typename T>
235 return kw::Get<Tag>(*
this, key, default_value);
238 template<
typename ReturnType>
239 ReturnType
GetAs(uint64_t tag, ReturnType default_value) {
241 Head::IsTagged(tag) ?
245 template<
typename ReturnType>
246 ReturnType
GetAs(
const std::string&
string, ReturnType default_value) {
261 template <
typename Tail>
265 template <u
int64_t Tag>
270 template<u
int64_t Tag,
typename T>
273 return kw::Get<Tag>(*
this, key, default_value);
276 template<
typename ReturnType>
277 ReturnType
GetAs(uint64_t tag, ReturnType default_value) {
278 return Tail::IsTagged(tag) ? this->Tail::v : default_value;
281 template<
typename ReturnType>
282 ReturnType
GetAs(
const std::string&
string, ReturnType default_value) {
287 return Tail::IsTagged(tag) ?
true :
false;
300 template <uint64_t
Tag,
typename T,
typename... Rest>
306 template <uint64_t
Tag,
typename First,
typename... Rest>
312 template <uint64_t
Tag,
typename T,
typename... Rest>
314 static const bool result =
true;
318 template <u
int64_t Tag>
320 static const bool result =
false;
324 template <uint64_t
Tag,
typename Default,
typename Head,
typename... Tail>
330 template <uint64_t
Tag,
typename Default,
typename T,
typename... Tail>
336 template <u
int64_t Tag,
typename Default>
342 template <uint64_t
Tag,
typename Default,
typename... Args>
351 template <uint64_t
Tag,
typename Default,
typename... Args>
362 #define TAG(key) kw::Hash(#key)
363 #define KW(key) kw::Key<kw::Hash(#key)>()
365 #endif // DOXYGEN_IGNORE
constexpr bool ContainsTagFn(uint64_t tag)
Function version of ContainsTag.
provides static member Get() with implementations depending on whether or not Tag is in Args...
TypeOfTagDefault< Tag, Default, Tail...>::Result Result
constexpr uint32_t size()
return the number of characters in the string, including the terminal null
TypeOfTagDefault< Tag, T, Tail >::Result Get(const Key< Tag > &key, T default_value)
Arg< Tag, T > operator=(T v)
constexpr string, used to implement tagging with strings
ReturnType GetAs(const std::string &tag, ReturnType default_value)
constexpr bool Contains(const Key< Tag > &key) const
FT_Tag Tag
typedef for 32bit tags (as used in the SFNT format)
bool Contains(const std::string &tag)
bool Contains(const std::string &tag)
constexpr uint64_t Hash()
return a hash of the string
bool Contains(uint64_t tag)
ReturnType GetAs(uint64_t tag, ReturnType default_value)
TypeOfTagDefault< Tag, T, Args...>::Result Get(const Key< Tag > &key, T default_value)
return the value associated with Tag, if it exists in the kwargs, otherwise return the default ...
static Default Get(ParamPack< Args...> &pack, Default d)
RefWrap< T > Ref(T &v)
forces an argument to be passed by reference
assignment operator sentinal used as a key for key-values pairs in the kwargs parameter pack ...
ReturnType GetAs(uint64_t tag, ReturnType default_value)
Arg< Tag, const T & > operator=(ConstRefWrap< T > vw)
TypeOfTagDefault< Tag, Default, Args...>::Result Get(ParamPack< Args...> &pack, Default d)
given a parameter pack, retrieves and return sthe parameter tagged with tag, or else returns a defaul...
constexpr uint64_t Hash(const char(&string)[N])
returns a 64bit hash of string
signifies that the parameter should be passed by reference
signifies the parameter should be passed by const reference
static TypeOfTagDefault< Tag, Default, Args...>::Result Get(ParamPack< Args...> &pack, Default d)
Arg< Tag, T & > operator=(RefWrap< T > vw)
ReturnType SafeReturn(T query, ReturnType default_value)
SFINAE to safely iterate over params in a parampack since we cannot use the ?: operator on any old pa...
constexpr bool Contains(const Key< Tag > &key) const
ReturnType GetAs(uint64_t tag, ReturnType default_value)
constexpr bool IsTagged(uint64_t query)
bool Contains(const std::string &tag)
uint64_t HashString(const std::string &str, int i, uint64_t hash)
Return an unsigned 64bit hash of string.
template meta-function contains a static boolean variable 'result' which is true if Tag is in the lis...
const ConstRefWrap< T > ConstRef(const T &v)
forces an argument to be passed by const reference
bool Contains(uint64_t tag)
const Char8_t * str(const Char8_t *s1, const Char8_t *s2)
ReturnType GetAs(const std::string &string, ReturnType default_value)
constexpr Tag(const char(&string)[N])
Construct from a string literal.
constexpr Tag(const char *string, size_t len)
constexpr uint64_t Hash(int i, uint64_t hash)
Donald Knuth's hash function TODO: validate or replace this hash function.
parameter storage for type T within a parameter pack
bool Contains(uint64_t tag)
template meta function provides a member typedef Result which evaluates to T if Arg<Tag,T> is in Args... or Default if it is not
ReturnType GetAs(const std::string &string, ReturnType default_value)
TypeOfTagDefault< Tag, T, Head, Tail...>::Result Get(const Key< Tag > &key, T default_value)
constexpr bool Contains(const Key< Tag > &key)
returns true if the numeric tag is a member of the kwargs in Args...
storage for kwargs parameter pack
constexpr char operator[](uint32_t i)
return the character at index i
ParamPack(Head head, Tail...tail)