Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
symbol.hpp File Reference

Marker types to indicate a literal string and a Symbol. More...

Go to the source code of this file.

Description

Marker types to indicate a literal string and a Symbol.

Instead of working just with pointers, which could represent pretty much anything, it is prudent to express the meaning at interfaces and for variables and members explicitly.

On conceptual level, while a string is just some sequence of characters and nothing can be said about its mutability or lifetime, a Literal is explicitly meant to be static. It is a fixed sequence of characters placed in a stable memory location and assumed to exist during the whole lifetime of the execution. The concept of a Symbol is slightly different: it is meant to be a distinguishable, fixed, unique token. An Identical sequence of characters means we have exactly the same Symbol.

These concepts can be fused by treating Symbol as a specialisation of Literal, additionally maintaining an automatically populated, static symbol table, and we close the circle by allowing Symbol instances to be created from strings at runtime.

Remarks
this abstraction was first used occasionally 11/2008, at that time just as a typedef to mark assumption on the new interfaces for rules based configuration in the Steam-Layer. Over time, conversions, comparison and hashcode implementation were added. It turned out that the most smooth integration in coding practice is achieved when allowing transparent conversion between Literal ⟷ CStr, but not for Symbol or std::string.
Todo:
9/2017 consider this mostly as settled, but might require some finishing touches
  • maybe improve interoperation of Symbol and std::string
  • investigate performance of the automatic symbol table
  • improve Lifecycle in startup and shutdown phase
  • maybe some metaprogramming magic to build distinct types based on symbols.
See also
symbol-impl.cpp
configrules.hpp
query.hpp

Definition in file symbol.hpp.

#include "lib/hash-standard.hpp"
#include <string>
#include <cstring>

Namespaces

namespace  lib
 Implementation namespace for support and library code.
 
namespace  lib::anonymous_namespace{symbol.hpp}
 

Typedefs

using CStr = const char *
 

Classes

class  Literal
 Inline string literal. More...
 
class  Symbol
 Token or Atom with distinct identity. More...
 

Functions

CStr cStr (std::string const &rendered)
 convenience shortcut: forced conversion to c-String via string.
 
constexpr int strNcmp (CStr a, CStr b, size_t len)
 
HashVal hash_value (Literal literal)
 generate hash value based on the Literal's contents.
 
HashVal hash_value (Symbol sym)
 hash value for Symbols is directly based on the symbol table entry
 
constexpr bool operator== (Literal const &s1, Literal const &s2)
 
constexpr bool operator== (Symbol const &s1, Symbol const &s2)
 
constexpr bool operator== (CStr s1, Literal s2)
 
constexpr bool operator== (Symbol s1, CStr s2)
 
constexpr bool operator== (Literal s1, Symbol s2)
 
constexpr bool operator== (Literal s1, std::string const &s2)
 
constexpr bool operator== (Symbol s1, std::string const &s2)
 
std::string operator+ (std::string str, Literal const &sym)
 string concatenation
 
std::string operator+ (Literal const &sym, std::string str)
 

Typedef Documentation

◆ CStr

using CStr = const char*

Definition at line 55 of file symbol.hpp.

Function Documentation

◆ cStr()

CStr cStr ( std::string const &  rendered)
inline