Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
symbol-impl.cpp
Go to the documentation of this file.
1/*
2 Symbol(impl) - helpers for working with literal string IDs
3
4 Copyright (C)
5 2009,2017 Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
23#include "lib/symbol.hpp"
24#include "lib/symbol-table.hpp"
25
26#include <boost/functional/hash.hpp>
27#include <cstddef>
28#include <cstring>
29#include <string>
30
31using std::size_t;
32using std::string;
33using std::forward;
34using boost::hash_combine;
35
36
37
38
39namespace lib {
40
42
43 namespace { // global symbol table
44
47 {
48 static SymbolTable theSymbolTable;
49 return theSymbolTable; // Meyer's Singleton
50 }
51 }
52
53
61 Symbol::Symbol (string&& definition)
62 : Literal{symbolTable().internedString (forward<string> (definition))}
63 { }
64
65
66 /* == predefined marker Symbols == */
67 Symbol Symbol::ANY = "*";
69 Symbol Symbol::BOTTOM = "⟂";
70 Symbol Symbol::FAILURE = "↯";
71
72 // see also: lib/format-obj.cpp
73 // We can not share these definitions due to undefined static init order
74
75
76
77
78
85 {
86 size_t hash=0;
87 if (literal)
88 {
89 size_t cnt = 1;
90 CStr pos = literal;
91 for ( ; cnt <= STRING_MAX_RELEVANT and *pos ; ++cnt, ++pos )
92 hash_combine (hash, *pos);
93 }
94
95 return hash;
96 }
97
101 {
102 return sym? boost::hash_value (sym.c())
103 : 0;
104 }
105
106
107
108} // namespace lib
Inline string literal.
Definition symbol.hpp:78
constexpr const char * c() const
Definition symbol.hpp:93
Table for automatically interned strings.
Token or Atom with distinct identity.
Definition symbol.hpp:120
static Symbol BOTTOM
Definition symbol.hpp:124
static Symbol ANY
Definition symbol.hpp:122
static Symbol FAILURE
Definition symbol.hpp:125
static Symbol EMPTY
Definition symbol.hpp:123
Symbol(CStr lit=NULL)
Definition symbol.hpp:127
const char * CStr
Definition error.hpp:42
#define hash
#define LUMIERA_IDSTRING_MAX_RELEVANT
Definition limits.hpp:33
Implementation namespace for support and library code.
const size_t STRING_MAX_RELEVANT
safety guard: maximum number of chars to process.
size_t HashVal
a STL compatible hash value
Definition hash-value.h:52
HashVal hash_value(QueryText const &entry)
support using queries in hashtables.
Registry table for automatically interned strings.
Marker types to indicate a literal string and a Symbol.