libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gbl::Quark Class Reference

#include <gimbal_quark.hpp>

Public Member Functions

 Quark (GblQuark cQuark)
 
 Quark (const char *pString, std::size_t length=0)
 
 Quark (const std::string &stdStr)
 
 Quark (std::string_view strv)
 
bool isValid (void) const
 
const char * toString (void) const
 
std::size_t length (void) const
 
 operator GblQuark (void) const
 
char operator[] (std::size_t index) const
 
Quarkoperator= (const Quark &rhs)=default
 
Quarkoperator= (GblQuark cQuark)
 
Quarkoperator= (const char *pString)
 
Quarkoperator= (const std::string &stdStr)
 
Quarkoperator= (std::string_view strv)
 

Static Public Member Functions

static Quark fromString (const char *pString, std::size_t length=0)
 
static Quark fromString (const std::string &stdStr)
 
static Quark fromString (std::string_view strv)
 
static Quark fromStatic (const char *pString)
 
static const char * internString (const char *pString, std::size_t length=0)
 
static const char * internStatic (const char *pString)
 

Static Public Attributes

static GblQuark Invalid
 

Friends

std::ostream & operator<< (std::ostream &os, Quark quark)
 

Detailed Description

OO C++ wrapper object around GblQuark.

gbl::Quark is the high-level C++ wrapper around GblQuark, which represents an interned string.

See also
GblQuark

Definition at line 33 of file gimbal_quark.hpp.

Constructor & Destructor Documentation

◆ Quark() [1/4]

gbl::Quark::Quark ( GblQuark  cQuark)
inline

Definition at line 41 of file gimbal_quark.hpp.

41 :
42 value_(cQuark) {}

◆ Quark() [2/4]

gbl::Quark::Quark ( const char *  pString,
std::size_t  length = 0 
)
inline

Definition at line 44 of file gimbal_quark.hpp.

44 :
45 Quark(GblQuark_tryString(pString, length)) {}
GblQuark GblQuark_tryString(const char *pStr, size_t len)
Returns the GblQuark associated with the given string, returning GBL_QUARK_INVALID if it was not prev...

◆ Quark() [3/4]

gbl::Quark::Quark ( const std::string &  stdStr)
inline

Definition at line 47 of file gimbal_quark.hpp.

47 :
48 Quark(stdStr.c_str()) {}

◆ Quark() [4/4]

gbl::Quark::Quark ( std::string_view  strv)
inline

Definition at line 50 of file gimbal_quark.hpp.

50 :
51 Quark(strv.data(), strv.length()) {}

Member Function Documentation

◆ isValid()

bool gbl::Quark::isValid ( void  ) const
inline

Definition at line 53 of file gimbal_quark.hpp.

53 {
54 return value_ != GBL_QUARK_INVALID;
55 }
#define GBL_QUARK_INVALID
Value of an invalid or NULL GblQuark.

◆ toString()

const char * gbl::Quark::toString ( void  ) const
inline

Definition at line 57 of file gimbal_quark.hpp.

57 {
58 return GblQuark_toString(value_);
59 }
const char * GblQuark_toString(GblQuark quark)
Returns the NULL-terminated interned C string associated with a given GblQuark.

◆ length()

std::size_t gbl::Quark::length ( void  ) const
inline

Definition at line 61 of file gimbal_quark.hpp.

61 {
62 return isValid()?
63 strlen(GblQuark_toString(value_)) :
64 0;
65 }

◆ operator GblQuark()

gbl::Quark::operator GblQuark ( void  ) const
inline

Definition at line 67 of file gimbal_quark.hpp.

67 {
68 return value_;
69 }

◆ operator[]()

char gbl::Quark::operator[] ( std::size_t  index) const
inline

Definition at line 71 of file gimbal_quark.hpp.

71 {
72 if(index >= length())
73 throw std::out_of_range("Out-of-range GblQuark access!");
74
75 return toString()[index];
76 }

◆ operator=() [1/4]

Quark & gbl::Quark::operator= ( GblQuark  cQuark)
inline

Definition at line 80 of file gimbal_quark.hpp.

80 {
81 value_ = cQuark;
82 return *this;
83 }

◆ operator=() [2/4]

Quark & gbl::Quark::operator= ( const char *  pString)
inline

Definition at line 85 of file gimbal_quark.hpp.

85 {
86 value_ = GblQuark_tryString(pString);
87 return *this;
88 }

◆ operator=() [3/4]

Quark & gbl::Quark::operator= ( const std::string &  stdStr)
inline

Definition at line 90 of file gimbal_quark.hpp.

90 {
91 return *this = stdStr.c_str();
92 }

◆ operator=() [4/4]

Quark & gbl::Quark::operator= ( std::string_view  strv)
inline

Definition at line 94 of file gimbal_quark.hpp.

94 {
95 value_ = GblQuark_tryString(strv.data(), strv.length());
96 return *this;
97 }

◆ fromString() [1/3]

static Quark gbl::Quark::fromString ( const char *  pString,
std::size_t  length = 0 
)
inlinestatic

Definition at line 101 of file gimbal_quark.hpp.

101 {
102 return GblQuark_fromString(pString, length);
103 }
GblQuark GblQuark_fromString(const char *pStr, size_t len)
Returns the GblQuark associated with the given string, adding a new entry to the registry if necessar...

◆ fromString() [2/3]

static Quark gbl::Quark::fromString ( const std::string &  stdStr)
inlinestatic

Definition at line 105 of file gimbal_quark.hpp.

105 {
106 return fromString(stdStr.c_str());
107 }

◆ fromString() [3/3]

static Quark gbl::Quark::fromString ( std::string_view  strv)
inlinestatic

Definition at line 109 of file gimbal_quark.hpp.

109 {
110 return fromString(strv.data(), strv.length());
111 }

◆ fromStatic()

static Quark gbl::Quark::fromStatic ( const char *  pString)
inlinestatic

Definition at line 113 of file gimbal_quark.hpp.

113 {
114 return GblQuark_fromStatic(pString);
115 }
GblQuark GblQuark_fromStatic(const char *pSstring)
Returns the GblQuark associated with the given STATIC string, which can save an allocation when initi...

◆ internString()

static const char * gbl::Quark::internString ( const char *  pString,
std::size_t  length = 0 
)
inlinestatic

Definition at line 117 of file gimbal_quark.hpp.

117 {
118 return GblQuark_internString(pString, length);
119 }
const char * GblQuark_internString(const char *pStr, size_t len)
Creates a GblQuark from the given string (if necessary), also returning its interned string.

◆ internStatic()

static const char * gbl::Quark::internStatic ( const char pString)
inlinestatic

Definition at line 121 of file gimbal_quark.hpp.

121 {
122 return GblQuark_internStatic(pString);
123 }
const char * GblQuark_internStatic(const char *pString)
Creates a GblQuark from the given STATIC string (if necessary, saving on allocating),...

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
Quark  quark 
)
friend

Definition at line 125 of file gimbal_quark.hpp.

125 {
126 os << quark.toString();
127 return os;
128 }

Field Documentation

◆ Invalid

GblQuark gbl::Quark::Invalid
inlinestatic

Definition at line 99 of file gimbal_quark.hpp.


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