Flecs v4.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
flecs::string Struct Reference

Owned string wrapper. More...

#include <string.hpp>

Inheritance diagram for flecs::string:
[legend]

Public Member Functions

 string ()
 Default constructor.
 
 string (char *str)
 Construct from an owned char pointer.
 
 ~string ()
 Destructor.
 
 string (string &&str) noexcept
 Move constructor.
 
 operator const char * () const
 Implicit conversion to const char*.
 
stringoperator= (string &&str) noexcept
 Move assignment operator.
 
stringoperator= (const string &str)=delete
 Ban implicit copies/allocations.
 
 string (const string &str)=delete
 Ban implicit copies/allocations.
 
bool operator== (const flecs::string &str) const
 Equality operator.
 
bool operator!= (const flecs::string &str) const
 Inequality operator.
 
bool operator== (const char *str) const
 Equality operator for a C string.
 
bool operator!= (const char *str) const
 Inequality operator for a C string.
 
const char * c_str () const
 Return the C string.
 
std::size_t length () const
 Return the string length.
 
std::size_t size () const
 Return the string size (same as length).
 
void clear ()
 Clear the string, freeing the owned memory.
 
bool contains (const char *substr)
 Check if the string contains a substring.
 

Static Public Member Functions

template<size_t N>
static constexpr size_t length (char const (&)[N])
 Return the length of a string literal at compile time.
 

Protected Member Functions

 string (const char *str)
 Construct from a non-owned C string.
 

Protected Attributes

char * str_ = nullptr
 
const char * const_str_
 
ecs_size_t length_
 

Detailed Description

Owned string wrapper.

This removes dependencies on std::string (and therefore STL) and allows the API to return allocated strings without incurring additional allocations when wrapping in an std::string.

Definition at line 15 of file string.hpp.

Constructor & Destructor Documentation

◆ string() [1/4]

flecs::string::string ( )
inlineexplicit

Default constructor.

Definition at line 17 of file string.hpp.

◆ string() [2/4]

flecs::string::string ( char * str)
inlineexplicit

Construct from an owned char pointer.

Definition at line 23 of file string.hpp.

◆ ~string()

flecs::string::~string ( )
inline

Destructor.

Free the owned string if set.

Definition at line 29 of file string.hpp.

◆ string() [3/4]

flecs::string::string ( string && str)
inlinenoexcept

Move constructor.

Definition at line 40 of file string.hpp.

◆ string() [4/4]

flecs::string::string ( const char * str)
inlineprotected

Construct from a non-owned C string.

Must be constructed through string_view. This allows for using the string class for both owned and non-owned strings, which can reduce allocations when code conditionally should store a literal or an owned string. Making this constructor protected forces the code to explicitly create a string_view, which emphasizes that the string won't be freed by the class.

Definition at line 153 of file string.hpp.

Member Function Documentation

◆ c_str()

const char * flecs::string::c_str ( ) const
inline

Return the C string.

Definition at line 109 of file string.hpp.

◆ clear()

void flecs::string::clear ( )
inline

Clear the string, freeing the owned memory.

Definition at line 130 of file string.hpp.

◆ contains()

bool flecs::string::contains ( const char * substr)
inline

Check if the string contains a substring.

Definition at line 137 of file string.hpp.

◆ length() [1/2]

std::size_t flecs::string::length ( ) const
inline

Return the string length.

Definition at line 114 of file string.hpp.

◆ length() [2/2]

template<size_t N>
static constexpr size_t flecs::string::length ( char const(&)[N])
inlinestaticconstexpr

Return the length of a string literal at compile time.

Definition at line 120 of file string.hpp.

◆ operator const char *()

flecs::string::operator const char * ( ) const
inline

Implicit conversion to const char*.

Definition at line 49 of file string.hpp.

◆ operator!=() [1/2]

bool flecs::string::operator!= ( const char * str) const
inline

Inequality operator for a C string.

Definition at line 104 of file string.hpp.

◆ operator!=() [2/2]

bool flecs::string::operator!= ( const flecs::string & str) const
inline

Inequality operator.

Definition at line 86 of file string.hpp.

◆ operator=()

string & flecs::string::operator= ( string && str)
inlinenoexcept

Move assignment operator.

Definition at line 54 of file string.hpp.

◆ operator==() [1/2]

bool flecs::string::operator== ( const char * str) const
inline

Equality operator for a C string.

Definition at line 91 of file string.hpp.

◆ operator==() [2/2]

bool flecs::string::operator== ( const flecs::string & str) const
inline

Equality operator.

Definition at line 69 of file string.hpp.

◆ size()

std::size_t flecs::string::size ( ) const
inline

Return the string size (same as length).

Definition at line 125 of file string.hpp.

Member Data Documentation

◆ const_str_

const char* flecs::string::const_str_
protected

Definition at line 159 of file string.hpp.

◆ length_

ecs_size_t flecs::string::length_
protected

Definition at line 160 of file string.hpp.

◆ str_

char* flecs::string::str_ = nullptr
protected

Definition at line 158 of file string.hpp.


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