FE 0.5.0
A header-only C++ library for writing frontends
Loading...
Searching...
No Matches
fe::Sym Class Reference

A Symbol just wraps a pointer to Sym::String, so pass Sym itself around as value. More...

#include <fe/sym.h>

Classes

struct  String
 

Public Member Functions

 Sym () noexcept=default
 
Getters
bool empty () const
 
size_t size () const
 
Access
char operator[] (size_t i) const
 
char front () const
 
char back () const
 
Iterators
auto begin () const
 
auto end () const
 
auto cbegin () const
 
auto cend () const
 
auto rbegin () const
 
auto rend () const
 
auto crbegin () const
 
auto crend () const
 
Comparisons
auto operator<=> (Sym other) const
 
bool operator== (Sym other) const
 
bool operator!= (Sym other) const
 
auto operator<=> (char c) const
 
auto operator== (char c) const
 
auto operator!= (char c) const
 
Conversions
const char * c_str () const
 
 operator const char * () const
 
std::string_view view () const
 
 operator std::string_view () const
 
std::string_view operator* () const
 
std::string str () const
 This involves a copy.
 
 operator std::string () const
 explicit as this involves a copy.
 
 operator bool () const
 Is not empty?
 

Static Public Attributes

static constexpr size_t Short_String_Bytes = sizeof(uintptr_t)
 
static constexpr size_t Short_String_Mask = Short_String_Bytes - 1
 

Friends

struct ::std::hash< fe::Sym >
 
class SymPool
 
std::ostream & operator<< (std::ostream &o, Sym sym)
 

Detailed Description

A Symbol just wraps a pointer to Sym::String, so pass Sym itself around as value.

Sym is compatible with:

This means that retrieving a std::string_view or a null-terminated C-string is basically free. You can also obtain a std::string (via Sym::str), but this involves a copy. With the exception of the empty string, you should only create Symbols via SymPool::sym. This in turn will toss all Symbols into a big hash set. This makes Sym::operator== and Sym::operator!= an O(1) operation. The empty string is internally handled as nullptr. Thus, you can create a Symbol representing an empty string without having access to the SymPool.

Note
The empty std::string/std::string_view, nullptr, and "\0" are all identified as Sym::Sym().
Warning
Big endian version has not been tested.

Definition at line 39 of file sym.h.

Constructor & Destructor Documentation

◆ Sym()

fe::Sym::Sym ( )
defaultnoexcept

Member Function Documentation

◆ back()

char fe::Sym::back ( ) const
inline

Definition at line 99 of file sym.h.

References size().

◆ begin()

auto fe::Sym::begin ( ) const
inline

Definition at line 104 of file sym.h.

References c_str().

Referenced by cbegin(), and rend().

◆ c_str()

const char * fe::Sym::c_str ( ) const
inline

Definition at line 132 of file sym.h.

References view().

Referenced by begin(), end(), operator const char *(), and operator[]().

◆ cbegin()

auto fe::Sym::cbegin ( ) const
inline

Definition at line 106 of file sym.h.

References begin().

◆ cend()

auto fe::Sym::cend ( ) const
inline

Definition at line 107 of file sym.h.

References end().

◆ crbegin()

auto fe::Sym::crbegin ( ) const
inline

Definition at line 110 of file sym.h.

References rbegin().

◆ crend()

auto fe::Sym::crend ( ) const
inline

Definition at line 111 of file sym.h.

References rend().

◆ empty()

bool fe::Sym::empty ( ) const
inline

Definition at line 84 of file sym.h.

Referenced by size(), and view().

◆ end()

auto fe::Sym::end ( ) const
inline

Definition at line 105 of file sym.h.

References c_str(), and size().

Referenced by cend(), and rbegin().

◆ front()

char fe::Sym::front ( ) const
inline

Definition at line 98 of file sym.h.

◆ operator bool()

fe::Sym::operator bool ( ) const
inlineexplicit

Is not empty?

Definition at line 151 of file sym.h.

◆ operator const char *()

fe::Sym::operator const char * ( ) const
inline

Definition at line 133 of file sym.h.

References c_str().

◆ operator std::string()

fe::Sym::operator std::string ( ) const
inlineexplicit

explicit as this involves a copy.

Definition at line 149 of file sym.h.

References str().

◆ operator std::string_view()

fe::Sym::operator std::string_view ( ) const
inline

Definition at line 143 of file sym.h.

References view().

◆ operator!=() [1/2]

auto fe::Sym::operator!= ( char  c) const
inline

Definition at line 127 of file sym.h.

◆ operator!=() [2/2]

bool fe::Sym::operator!= ( Sym  other) const
inline

Definition at line 118 of file sym.h.

◆ operator*()

std::string_view fe::Sym::operator* ( ) const
inline

Definition at line 144 of file sym.h.

References view().

◆ operator<=>() [1/2]

auto fe::Sym::operator<=> ( char  c) const
inline

Definition at line 119 of file sym.h.

References size().

◆ operator<=>() [2/2]

auto fe::Sym::operator<=> ( Sym  other) const
inline

Definition at line 116 of file sym.h.

References view().

◆ operator==() [1/2]

auto fe::Sym::operator== ( char  c) const
inline

Definition at line 126 of file sym.h.

◆ operator==() [2/2]

bool fe::Sym::operator== ( Sym  other) const
inline

Definition at line 117 of file sym.h.

◆ operator[]()

char fe::Sym::operator[] ( size_t  i) const
inline

Definition at line 94 of file sym.h.

References c_str(), and size().

◆ rbegin()

auto fe::Sym::rbegin ( ) const
inline

Definition at line 108 of file sym.h.

References end().

Referenced by crbegin().

◆ rend()

auto fe::Sym::rend ( ) const
inline

Definition at line 109 of file sym.h.

References begin().

Referenced by crend().

◆ size()

size_t fe::Sym::size ( ) const
inline

Definition at line 85 of file sym.h.

References empty(), Short_String_Mask, and size().

Referenced by back(), end(), operator<=>(), operator[](), size(), and view().

◆ str()

std::string fe::Sym::str ( ) const
inline

This involves a copy.

Definition at line 148 of file sym.h.

References view().

Referenced by operator std::string().

◆ view()

std::string_view fe::Sym::view ( ) const
inline

Definition at line 135 of file sym.h.

References empty(), Short_String_Mask, and size().

Referenced by c_str(), operator std::string_view(), operator*(), operator<=>(), and str().

Friends And Related Symbol Documentation

◆ ::std::hash< fe::Sym >

friend struct ::std::hash< fe::Sym >
friend

Definition at line 151 of file sym.h.

◆ operator<<

std::ostream & operator<< ( std::ostream &  o,
Sym  sym 
)
friend

Definition at line 158 of file sym.h.

◆ SymPool

friend class SymPool
friend

Definition at line 165 of file sym.h.

Member Data Documentation

◆ Short_String_Bytes

constexpr size_t fe::Sym::Short_String_Bytes = sizeof(uintptr_t)
staticconstexpr

Definition at line 41 of file sym.h.

Referenced by fe::SymPool::sym().

◆ Short_String_Mask

constexpr size_t fe::Sym::Short_String_Mask = Short_String_Bytes - 1
staticconstexpr

Definition at line 42 of file sym.h.

Referenced by size(), and view().


The documentation for this class was generated from the following file: