Adobe Source Libraries 2.0.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
name_t Class Reference

A character string class for immutable strings. More...

#include <adobe/name.hpp>

Inheritance diagram for name_t:

Classes

struct  fast_compare

Public Types

using const_iterator
using iterator

Public Member Functions

 name_t (const char *s="")
 operator std::string_view () const
 name_t (const static_name_t &static_name)
 operator bool () const
const char * c_str () const
const char * begin () const
const char * end () const

Static Public Member Functions

static bool fast_sort (const name_t &x, const name_t &y)

Friends

struct std::hash< name_t >
std::ostream & operator<< (std::ostream &s, const name_t &name)
bool operator== (const name_t &x, const name_t &y)
bool operator< (const name_t &x, const name_t &y)

Detailed Description

A name is an immutable string literal used for indexing associative containers (e.g., dictionary_t.) It has several performance guarantees that make it a preferred alternative to other string-based key types.

A name_t is a string class for immutable strings. The storage for name_t is globally pooled and strings are reused. Although an adobe::name_t can be somewhat expensive to construct, copying assignment, and equality comparisons are very fast.

Model Of:
Rationale:
Note
The name_t class is thread safe when compiled with BOOST_HAS_THREADS defined.
Todo
The complexity of construction of a name_t is currently O(log(n)). An efficient hash implementation may improve efficiency.
Todo
Serialization support for name_t is not complete, but can be enabled by defining ADOBE_SERIALIZATION.

Definition at line 220 of file name.hpp.

Member Typedef Documentation

◆ const_iterator

Definition at line 221 of file name.hpp.

◆ iterator

using iterator

Definition at line 222 of file name.hpp.

Constructor & Destructor Documentation

◆ name_t() [1/2]

name_t ( const char * string_name = "")
explicit

Constructs a name_t associated with string_name. If this is the first instance of this string, then the string will be copied to a pool with static storage duration.

Precondition
string_name is a '\0' terminated character sequence.

Definition at line 224 of file name.hpp.

◆ name_t() [2/2]

name_t ( const static_name_t & static_name)

Implicit conversion constructor from a static_name_t.

Definition at line 230 of file name.hpp.

Member Function Documentation

◆ operator std::string_view()

operator std::string_view ( ) const

Definition at line 225 of file name.hpp.

◆ operator bool()

operator bool ( ) const
explicit
Returns
false iff the instance is equal to the empty string.
Complexity Guarantee(s)
O(1)

◆ c_str()

const char * c_str ( ) const
Returns
the associated '\0' terminated string.

Definition at line 261 of file name.hpp.

◆ begin()

const char * begin ( ) const

Definition at line 263 of file name.hpp.

◆ end()

const char * end ( ) const

Definition at line 264 of file name.hpp.

◆ fast_sort()

bool fast_sort ( const name_t & x,
const name_t & y )
static

Deprecated. Use fast_compare{} instead.

Definition at line 287 of file name.hpp.

◆ std::hash< name_t >

friend struct std::hash< name_t >
friend

Definition at line 287 of file name.hpp.

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const name_t & name )
friend

◆ operator==

bool operator== ( const name_t & x,
const name_t & y )
friend
Complexity Guarantee(s)
O(1)

Definition at line 248 of file name.hpp.

◆ operator<

bool operator< ( const name_t & x,
const name_t & y )
friend

Lexicographical comparison of two names. For a faster comparison use name_t::fast_compare.

Complexity Guarantee(s)
O(N)

Definition at line 257 of file name.hpp.