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:
- Easy debugging: Reading "Texture/diffuse.png" is much nicer than "0x0a0100ef"
- 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)
- In practice we truncate to 32 bytes. If your fear this is too little for you and also fear about collisions, increase
- Author
- Matias N. Goldberg
- Version
- 1.0