HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ustringhash Class Reference

#include <ustring.h>

Public Types

using rep_t = ustring::hash_t
 The underlying representation type. More...
 
using hash_t = ustring::hash_t
 The hash type. More...
 

Public Member Functions

OIIO_HOSTDEVICE constexpr ustringhash () noexcept
 
 ~ustringhash () noexcept=default
 ustringhash destructor. More...
 
OIIO_HOSTDEVICE constexpr ustringhash (const ustringhash &str) noexcept
 Copy construct a ustringhash from another ustringhash. More...
 
 ustringhash (const ustring &str) noexcept
 Construct from a ustring. More...
 
OIIO_DEVICE_CONSTEXPR ustringhash (const char *str)
 Construct a ustringhash from a null-terminated C string (char *). More...
 
OIIO_DEVICE_CONSTEXPR ustringhash (const char *str, size_t len)
 
OIIO_DEVICE_CONSTEXPR ustringhash (string_view str)
 
OIIO_HOSTDEVICE constexpr ustringhash (hash_t hash) noexcept
 
 operator string_view () const noexcept
 Conversion to an OIIO::string_view. More...
 
 operator std::string () const noexcept
 Conversion to std::string (explicit only!). More...
 
OIIO_HOSTDEVICE constexpr
const ustringhash
operator= (const ustringhash &str)
 Assign from a ustringhash. More...
 
const ustringhashoperator= (const ustring &str)
 Assign from a ustring. More...
 
OIIO_HOSTDEVICE void clear () noexcept
 Reset to an empty string. More...
 
const char * c_str () const noexcept
 Return a pointer to the characters. More...
 
const char * data () const noexcept
 Return a C string representation of a ustring. More...
 
const std::string & string () const noexcept
 Return a C++ std::string representation of a ustring. More...
 
size_t length () const noexcept
 Return the number of characters in the string. More...
 
OIIO_HOSTDEVICE constexpr hash_t hash () const noexcept
 Return a hashed version of the string. More...
 
size_t size () const noexcept
 Return the number of characters in the string. More...
 
OIIO_HOSTDEVICE constexpr bool empty () const noexcept
 
OIIO_HOSTDEVICE constexpr bool operator== (const ustringhash &str) const noexcept
 Test for equality with another ustringhash. More...
 
OIIO_HOSTDEVICE constexpr bool operator!= (const ustringhash &str) const noexcept
 Test for inequality with another ustringhash. More...
 
OIIO_CONSTEXPR17 bool operator== (const char *str) const noexcept
 Test for equality with a char*. More...
 
OIIO_CONSTEXPR17 bool operator!= (const char *str) const noexcept
 Test for inequality with a char*. More...
 
bool operator== (const ustring &str) const noexcept
 Test for equality with a ustring. More...
 
bool operator!= (const ustring &str) const noexcept
 Test for inequality with a ustring. More...
 
OIIO_HOSTDEVICE constexpr bool operator< (const ustringhash &x) const noexcept
 

Static Public Member Functions

static OIIO_NODISCARD
constexpr ustringhash 
from_hash (hash_t hash)
 

Friends

class ustring
 
bool operator== (const ustring &a, const ustringhash &b) noexcept
 
bool operator!= (const ustring &a, const ustringhash &b) noexcept
 
std::ostream & operator<< (std::ostream &out, const ustringhash &str)
 

Detailed Description

A ustringhash holds the hash of a ustring in a type-safe way.

It has a nearly identical interface to a ustring, and still refers to a string in the internal ustring table. But whereas the representation of a ustring is the pointer to the characters, the representation of a ustringhash is the hash of the string.

For some uses where you don't need access to the characters in any performance-critical paths, this may be a more convenient representation. In particular, it's well suited to a GPU that doesn't have access to the character memory. Another interesting difference is that from run to run, a ustring may have a different literal value, since there's no reason to expect that the pointer to a string like "foo" will refer to the same memory location every time the program executes, but in contrast, the hash is guaranteed to be identical from run to run.

Definition at line 791 of file ustring.h.

Member Typedef Documentation

The hash type.

Definition at line 794 of file ustring.h.

The underlying representation type.

Definition at line 793 of file ustring.h.

Constructor & Destructor Documentation

OIIO_HOSTDEVICE constexpr ustringhash::ustringhash ( )
inlinenoexcept

Definition at line 797 of file ustring.h.

ustringhash::~ustringhash ( )
defaultnoexcept

ustringhash destructor.

OIIO_HOSTDEVICE constexpr ustringhash::ustringhash ( const ustringhash str)
inlinenoexcept

Copy construct a ustringhash from another ustringhash.

Definition at line 806 of file ustring.h.

ustringhash::ustringhash ( const ustring str)
inlinenoexcept

Construct from a ustring.

Definition at line 812 of file ustring.h.

OIIO_DEVICE_CONSTEXPR ustringhash::ustringhash ( const char *  str)
inlineexplicit

Construct a ustringhash from a null-terminated C string (char *).

Definition at line 818 of file ustring.h.

OIIO_DEVICE_CONSTEXPR ustringhash::ustringhash ( const char *  str,
size_t  len 
)
inlineexplicit

Definition at line 830 of file ustring.h.

OIIO_DEVICE_CONSTEXPR ustringhash::ustringhash ( string_view  str)
inlineexplicit

Construct a ustringhash from a string_view, which can be auto-converted from either a std::string.

Definition at line 844 of file ustring.h.

OIIO_HOSTDEVICE constexpr ustringhash::ustringhash ( hash_t  hash)
inlineexplicitnoexcept

Construct from a raw hash value. Beware: results are undefined if it's not the valid hash of a ustring.

Definition at line 858 of file ustring.h.

Member Function Documentation

const char* ustringhash::c_str ( void  ) const
inlinenoexcept

Return a pointer to the characters.

Definition at line 892 of file ustring.h.

OIIO_HOSTDEVICE void ustringhash::clear ( )
inlinenoexcept

Reset to an empty string.

Definition at line 888 of file ustring.h.

const char* ustringhash::data ( ) const
inlinenoexcept

Return a C string representation of a ustring.

Definition at line 898 of file ustring.h.

OIIO_HOSTDEVICE constexpr bool ustringhash::empty ( void  ) const
inlinenoexcept

Is the string empty – i.e., is it nullptr or does it point to an empty string? (Empty strings always have a hash of 0.)

Definition at line 923 of file ustring.h.

static OIIO_NODISCARD constexpr ustringhash ustringhash::from_hash ( hash_t  hash)
inlinestatic

Return the ustringhash corresponding to the given hash. Caveat emptor: results are undefined if it's not the valid hash of a ustring.

Definition at line 992 of file ustring.h.

OIIO_HOSTDEVICE constexpr hash_t ustringhash::hash ( ) const
inlinenoexcept

Return a hashed version of the string.

Definition at line 914 of file ustring.h.

size_t ustringhash::length ( void  ) const
inlinenoexcept

Return the number of characters in the string.

Definition at line 907 of file ustring.h.

ustringhash::operator std::string ( ) const
inlineexplicitnoexcept

Conversion to std::string (explicit only!).

Definition at line 867 of file ustring.h.

ustringhash::operator string_view ( ) const
inlinenoexcept

Conversion to an OIIO::string_view.

Definition at line 864 of file ustring.h.

OIIO_HOSTDEVICE constexpr bool ustringhash::operator!= ( const ustringhash str) const
inlinenoexcept

Test for inequality with another ustringhash.

Definition at line 937 of file ustring.h.

OIIO_CONSTEXPR17 bool ustringhash::operator!= ( const char *  str) const
inlinenoexcept

Test for inequality with a char*.

Definition at line 949 of file ustring.h.

bool ustringhash::operator!= ( const ustring str) const
inlinenoexcept

Test for inequality with a ustring.

Definition at line 967 of file ustring.h.

OIIO_HOSTDEVICE constexpr bool ustringhash::operator< ( const ustringhash x) const
inlinenoexcept

Definition at line 977 of file ustring.h.

OIIO_HOSTDEVICE constexpr const ustringhash& ustringhash::operator= ( const ustringhash str)
inline

Assign from a ustringhash.

Definition at line 874 of file ustring.h.

const ustringhash& ustringhash::operator= ( const ustring str)
inline

Assign from a ustring.

Definition at line 881 of file ustring.h.

OIIO_HOSTDEVICE constexpr bool ustringhash::operator== ( const ustringhash str) const
inlinenoexcept

Test for equality with another ustringhash.

Definition at line 930 of file ustring.h.

OIIO_CONSTEXPR17 bool ustringhash::operator== ( const char *  str) const
inlinenoexcept

Test for equality with a char*.

Definition at line 943 of file ustring.h.

bool ustringhash::operator== ( const ustring str) const
inlinenoexcept

Test for equality with a ustring.

Definition at line 956 of file ustring.h.

size_t ustringhash::size ( void  ) const
inlinenoexcept

Return the number of characters in the string.

Definition at line 918 of file ustring.h.

const std::string& ustringhash::string ( void  ) const
inlinenoexcept

Return a C++ std::string representation of a ustring.

Definition at line 901 of file ustring.h.

Friends And Related Function Documentation

bool operator!= ( const ustring a,
const ustringhash b 
)
friend

Definition at line 972 of file ustring.h.

std::ostream& operator<< ( std::ostream &  out,
const ustringhash str 
)
friend

Generic stream output of a ustringhash outputs the string it refers to.

Definition at line 984 of file ustring.h.

bool operator== ( const ustring a,
const ustringhash b 
)
friend

Definition at line 961 of file ustring.h.

friend class ustring
friend

Definition at line 1003 of file ustring.h.


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