Lumiera  0.pre.03
»edit your freedom«
symbol.hpp File Reference

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 concept level, while a string is just some sequence of characters and nothing can be said about mutability or lifetime, a Literal on the contrary is meant to be static. It is fixed and assumed to exist literally as is during the whole lifetime of the execution. The concept of a Symbol is related, yet slightly different: it is meant to be a distinguishable fixed, unique token. 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 started on occasion 11/2008, just with a typedef to mark assumption on 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 for Literal, 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>

Classes

class  Literal
 inline string literal This is a marker type to indicate that More...
 
class  Symbol
 Token or Atom with distinct identity. More...
 

Typedefs

using CStr = const char *
 

Functions

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

Namespaces

 lib
 Implementation namespace for support and library code.
 

Function Documentation

◆ cStr()

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

convenience shortcut: forced conversion to c-String via string.

usable for printf with objects providing to-string conversion.

Definition at line 68 of file symbol.hpp.

Referenced by AppState::abort(), Asset::Asset(), TreeDiffMutatorBinding::emu(), HandlingPattern::invoke(), lumiera::error::lumiera_unexpectedException(), AppState::maybeStart(), TreeDiffMutatorBinding::mut(), TestSource::nextResult(), DispatcherLoop::runSessionThread(), UiStyle::setTheme(), MockSys::start(), NotificationService::triggerGuiShutdown(), and MockSys::triggerShutdown().

+ Here is the caller graph for this function: