You.i Engine
CYIStringUnorderedContainerKey Class Reference

Detailed Description

A CYIString wrapper that can be used as key for an unordered container (such as std::unordered_map) while still allowing for lookup by CYIStringView.

This class stores a CYIString to allow for 'strong' references, while also storing a CYIStringView. When created from a CYIStringView, this class does not keep a strong reference to the string data. This allows lookups into unordered containers to be done without converting from CYIStringView to CYIString. This is necessary because unlike ordered containers, the unordered containers do not have a 'transparent comparator' equivalent.

Note
When doing a lookup in an unordered container that uses this class as key, lookup should always be done using a CYIStringView for performance reasons. If lookup is done using a CYIString, a copy of the string would be made internally, which would impact performance. It is therefore recommended to convert the CYIString to CYIStringView when doing lookups into such unordered containers.
Warning
While it is safe to do lookups into the unordered container using a CYIStringUnorderedContainerKey created from a CYIStringView, it is generally not safe to store values into the container using objects created from CYIStringView. The only exception is if the CYIStringView is created from a string whose lifetime exceeds that of the unordered container (such as when creating CYIStringView's from static const char arrays).

#include <utility/YiStringUnorderedContainerKey.h>

Public Member Functions

 CYIStringUnorderedContainerKey ()=default
 
 CYIStringUnorderedContainerKey (const CYIStringUnorderedContainerKey &other)
 
 CYIStringUnorderedContainerKey (CYIStringUnorderedContainerKey &&other) noexcept
 
 CYIStringUnorderedContainerKey (CYIString value)
 
 CYIStringUnorderedContainerKey (CYIStringView value)
 
CYIStringUnorderedContainerKeyoperator= (const CYIStringUnorderedContainerKey &other)
 
CYIStringUnorderedContainerKeyoperator= (CYIStringUnorderedContainerKey &&other)
 
bool operator== (const CYIStringUnorderedContainerKey &other) const
 
bool operator!= (const CYIStringUnorderedContainerKey &other) const
 
CYIStringView GetData () const
 
const CYIStringGetOwnedData () const
 
bool IsOwnerOfData () const
 

Constructor & Destructor Documentation

◆ CYIStringUnorderedContainerKey() [1/5]

CYIStringUnorderedContainerKey::CYIStringUnorderedContainerKey ( )
default

◆ CYIStringUnorderedContainerKey() [2/5]

CYIStringUnorderedContainerKey::CYIStringUnorderedContainerKey ( const CYIStringUnorderedContainerKey other)

◆ CYIStringUnorderedContainerKey() [3/5]

CYIStringUnorderedContainerKey::CYIStringUnorderedContainerKey ( CYIStringUnorderedContainerKey &&  other)
noexcept

◆ CYIStringUnorderedContainerKey() [4/5]

CYIStringUnorderedContainerKey::CYIStringUnorderedContainerKey ( CYIString  value)

Creates an instance of this object by making a copy of value.

◆ CYIStringUnorderedContainerKey() [5/5]

CYIStringUnorderedContainerKey::CYIStringUnorderedContainerKey ( CYIStringView  value)

Creates an instance of this object by making a reference to the data of value.

Warning
The lifetime of this object must not exceed that of the underlying data of value.

Member Function Documentation

◆ GetData()

CYIStringView CYIStringUnorderedContainerKey::GetData ( ) const

Returns the data referenced by this object.

◆ GetOwnedData()

const CYIString& CYIStringUnorderedContainerKey::GetOwnedData ( ) const

Returns the data owned by this object. The value returned by this function is valid only when IsOwnerOfData() returns true. This function exists mostly for testing purposes.

See also
GetData()
IsOwnerOfData()

◆ IsOwnerOfData()

bool CYIStringUnorderedContainerKey::IsOwnerOfData ( ) const

Returns true if this object owns the string data that it contains.

◆ operator!=()

bool CYIStringUnorderedContainerKey::operator!= ( const CYIStringUnorderedContainerKey other) const

◆ operator=() [1/2]

CYIStringUnorderedContainerKey& CYIStringUnorderedContainerKey::operator= ( const CYIStringUnorderedContainerKey other)

◆ operator=() [2/2]

CYIStringUnorderedContainerKey& CYIStringUnorderedContainerKey::operator= ( CYIStringUnorderedContainerKey &&  other)

◆ operator==()

bool CYIStringUnorderedContainerKey::operator== ( const CYIStringUnorderedContainerKey other) const

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