OGRE  1.12.8
Object-Oriented Graphics Rendering Engine
Ogre::IdString Struct Reference

Hashed string. More...

#include <OgreIdString.h>

Public Member Functions

 IdString ()
 
 IdString (const char *string)
 
 IdString (const std::string &string)
 
 IdString (uint32 value)
 
std::string getFriendlyText () const
 Returns "[Hash 0x0a0100ef]" strings in Release mode, readable string in debug. More...
 
std::string getReleaseText () const
 Always returns "[Hash 0x0a0100ef]" strings in any mode. More...
 
bool operator!= (IdString idString) const
 
IdString operator+ (IdString idString) const
 
void operator+= (IdString idString)
 
bool operator< (IdString idString) const
 
bool operator== (IdString idString) const
 

Public Attributes

uint32 mHash
 

Static Public Attributes

static const uint32_t Seed = 0x3A8EFA67
 

Detailed Description

Hashed string.

An IdString is meant to be passed by value rather than by reference since in Release mode it's just an encapsulated integer. The default implementation uses a 32-bit uint. A hash = 0 is the default initialization, and assumed by Ogre to mean an IdString is empty or unspecified.

Note that IdString("") != IdString(0) != IdString() The latter indicates mHash == 0 (the default initialization). While the first one will hash the empty string "", and the second will attempt to hash the number 0, producing up to three possible outputs.
IdStrings convert regular String to hashes AND ARE DESTRUCTIVE. This means that you may no longer recover the real string it was constructed from. When the original data is not available getFriendlyText returns [Hash 0x0a0100ef] (in the example that mHash = 0x0a0100ef)* In debug mode (OGRE_DEBUG_MODE is defined), IdStrings try to maintain a copy of the original string for two purposes:
  1. Easy debugging: Reading "Texture/diffuse.png" is much nicer than "0x0a0100ef"
  2. Hash collision: If Ogre finds two IdStrings are identical but their original strings are not, an assertion will trigger indicating a collision has been found. Note that this isn't foolproof. Note: When IdString( uint32 ) was used to hash an integer, getFriendlyText will return "[Value 0x1234567]"
IdStrings can be concatenated: IdString( "Hello." ) + IdString( " How are you?" ) produc a new IdString, but please note that it may not be the same as doing IdString( "Hello. How are you?" ) depending on the hashing function used (by default, we use MurmurHash3,
See also
OGRE_HASH_FUNC)
Remarks
Hash collision detection isn't foolproof because we keep a fixed string copy of the original string. If the original string is too long, it will be truncated and there is an extremely low possibility that their truncation becomes the same string, and their hashes also become equal, when the original strings were not. i.e. VeryLooooooong/String and UltraaaaaLoong/String could both become "/String" and happen to also hash to the same number.
In practice we truncate to 32 bytes. If your fear this is too little for you and also fear about collisions, increase
See also
OGRE_DEBUG_STR_SIZE
Author
Matias N. Goldberg
Version
1.0

Constructor & Destructor Documentation

◆ IdString() [1/4]

Ogre::IdString::IdString ( )
inline

◆ IdString() [2/4]

Ogre::IdString::IdString ( const char *  string)
inline

◆ IdString() [3/4]

Ogre::IdString::IdString ( const std::string &  string)
inline

◆ IdString() [4/4]

Ogre::IdString::IdString ( uint32  value)
inline

Member Function Documentation

◆ operator+=()

void Ogre::IdString::operator+= ( IdString  idString)
inline

◆ operator+()

IdString Ogre::IdString::operator+ ( IdString  idString) const
inline

◆ operator<()

bool Ogre::IdString::operator< ( IdString  idString) const
inline

References mHash.

◆ operator==()

bool Ogre::IdString::operator== ( IdString  idString) const
inline

References mHash.

◆ operator!=()

bool Ogre::IdString::operator!= ( IdString  idString) const
inline

References mHash.

◆ getFriendlyText()

std::string Ogre::IdString::getFriendlyText ( ) const
inline

Returns "[Hash 0x0a0100ef]" strings in Release mode, readable string in debug.

References getReleaseText().

◆ getReleaseText()

std::string Ogre::IdString::getReleaseText ( ) const
inline

Always returns "[Hash 0x0a0100ef]" strings in any mode.

References mHash, and OGRE_HASH_BITS.

Referenced by getFriendlyText().

Member Data Documentation

◆ Seed

const uint32_t Ogre::IdString::Seed = 0x3A8EFA67
static

◆ mHash

uint32 Ogre::IdString::mHash

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