| The Gaudi Framework v32r1 (f65d50dc)

Public Member Functions | Private Attributes | List of all members
Gaudi::StringKey Class Reference

The helper class to represent the efficient "key" for access. More...

`#include <GaudiKernel/StringKey.h>`

Collaboration diagram for Gaudi::StringKey:
[legend]

## Public Member Functions
| StringKey (const char *key="")
| constructor from plain C-string, perform hashing More...
| StringKey (std::string key)
| constructor from std::string, perform hashing More...
const std::string & | str () const
| the actual string More...
| operator const std::string & () const
| implicit cast to std::string More...
bool | empty () const
| empty key? More...
bool | operator! () const
| empty key? More...
bool | operator== (const StringKey &o) const
| equality Key for efficiency reason compare the hash-values first More...
bool | operator== (const std::string &o) const
| equality, without hashing string rely on the native string equality More...
bool | operator!= (const StringKey &o) const
| non equality Key More...
bool | operator!= (const std::string &o) const
| non-equality string More...
bool | operator< (const StringKey &o) const
| less key It can be used as a key for std::map, e.g. More...
bool | operator> (const StringKey &o) const
| greater key More...
bool | operator<= (const StringKey &o) const
| less or equal key More...
bool | operator>= (const StringKey &o) const
| greater or equal key More...
std::size_t | __hash__ () const
| the actual access to the hash More...
std::string | __str__ () const
| the representation of the object More...
std::string | __repr__ () const
| the representation of the object More...
bool | __eq__ (const StringKey &right) const
| equality operator for python More...
bool | __eq__ (const std::string &right) const
| equality operators for python More...
bool | __neq__ (const StringKey &right) const
| non-equality operator for python More...
bool | __neq__ (const std::string &right) const
| non-equality operator for python More...
std::string | toString () const
| string representation (for properties) More...

## Private Attributes
std::string | m_str
| the actual string: More...
std::size_t | m_hash
| the hash: More...

## Detailed Description

The helper class to represent the efficient "key" for access.

Essentially it is a bit modified version ("boost-free") of the original class stringKey by Gerhard Raven, which is heavily used now in HLT

Attention
  NEVER use the actual hash value for anything stored in files, as it is not guaranteed that the hashing scheme will remain the same.

Author
  Vanya BELYAEV Ivan..nosp@m.Bely.nosp@m.aev@n.nosp@m.ikhe.nosp@m.f.nl

Date
  2009-04-08

Definition at line 34 of file StringKey.h.

## Constructor & Destructor Documentation

## ◆ StringKey() [1/2]

Gaudi::StringKey::StringKey | ( | const char * | key = `""` | ) |

constructor from plain C-string, perform hashing

Definition at line 26 of file StringKey.cpp.

27 : m_str( key )
28 , m_hash( std::hash<std::string>()( m_str ) ) // NB! hashing here!!!
29 {}
Gaudi::StringKey::m_hash
std::size_t m_hash
the hash:
Definition: StringKey.h:139
Gaudi::StringKey::m_str
std::string m_str
the actual string:
Definition: StringKey.h:137
std::hash

## ◆ StringKey() [2/2]

Gaudi::StringKey::StringKey | ( | std::string | key | ) |

constructor from std::string, perform hashing

Definition at line 19 of file StringKey.cpp.

20 : m_str( std::move( key ) )
21 , m_hash( std::hash<std::string>()( m_str ) ) // NB! hashing here!!!
22 {}
Gaudi::StringKey::m_hash
std::size_t m_hash
the hash:
Definition: StringKey.h:139
Gaudi::StringKey::m_str
std::string m_str
the actual string:
Definition: StringKey.h:137
std::hash
std::move
T move(T... args)

## Member Function Documentation

## ◆ __eq__() [1/2]

bool Gaudi::StringKey::__eq__ | ( | const StringKey & | right | ) | const

equality operator for python

Definition at line 44 of file StringKey.cpp.

44 { return this == &right || *this == right; }
std::right
T right(T... args)

## ◆ __eq__() [2/2]

bool Gaudi::StringKey::__eq__ | ( | const std::string & | right | ) | const

equality operators for python

Definition at line 48 of file StringKey.cpp.

48 { return *this == right; }
std::right
T right(T... args)

## ◆ __hash__()

std::size_t Gaudi::StringKey::__hash__ | ( |  | ) | const
| inline

the actual access to the hash

Attention
  NEVER use the actual hash value for anything stored in files, as it is not guaranteed that the hashing scheme will remain the same. The two reason for this function are:
  - transparent usage of this object for hashmap-like containers
  - Python @reutrn the actual hash value

Definition at line 114 of file StringKey.h.

114 { return m_hash; }
Gaudi::StringKey::m_hash
std::size_t m_hash
the hash:
Definition: StringKey.h:139

## ◆ __neq__() [1/2]

bool Gaudi::StringKey::__neq__ | ( | const StringKey & | right | ) | const

non-equality operator for python

Definition at line 52 of file StringKey.cpp.

52 { return this != &right && *this != right; }
std::right
T right(T... args)

## ◆ __neq__() [2/2]

bool Gaudi::StringKey::__neq__ | ( | const std::string & | right | ) | const

non-equality operator for python

Definition at line 56 of file StringKey.cpp.

56 { return *this != right; }
std::right
T right(T... args)

## ◆ __repr__()

std::string Gaudi::StringKey::__repr__ | ( |  | ) | const

the representation of the object

Definition at line 41 of file StringKey.cpp.

41 { return toString(); }
Gaudi::StringKey::toString
std::string toString() const
string representation (for properties)
Definition: StringKey.cpp:33

## ◆ __str__()

std::string Gaudi::StringKey::__str__ | ( |  | ) | const

the representation of the object

Definition at line 37 of file StringKey.cpp.

37 { return toString(); }
Gaudi::StringKey::toString
std::string toString() const
string representation (for properties)
Definition: StringKey.cpp:33

## ◆ empty()

bool Gaudi::StringKey::empty | ( |  | ) | const
| inline

empty key?

Definition at line 49 of file StringKey.h.

49 { return m_str.empty(); }
std::string::empty
T empty(T... args)
Gaudi::StringKey::m_str
std::string m_str
the actual string:
Definition: StringKey.h:137

## ◆ operator const std::string &()

Gaudi::StringKey::operator const std::string & | ( |  | ) | const
| inline

implicit cast to std::string

Definition at line 47 of file StringKey.h.

47 { return str(); }
Gaudi::StringKey::str
const std::string & str() const
the actual string
Definition: StringKey.h:45

## ◆ operator!()

bool Gaudi::StringKey::operator! | ( |  | ) | const
| inline

empty key?

Definition at line 51 of file StringKey.h.

51 { return empty(); }
Gaudi::StringKey::empty
bool empty() const
empty key?
Definition: StringKey.h:49

## ◆ operator!=() [1/2]

bool Gaudi::StringKey::operator!= | ( | const StringKey & | o | ) | const
| inline

non equality Key

Definition at line 67 of file StringKey.h.

67 { return !( *this == o ); }

## ◆ operator!=() [2/2]

bool Gaudi::StringKey::operator!= | ( | const std::string & | o | ) | const
| inline

non-equality string

Definition at line 69 of file StringKey.h.

69 { return !( *this == o ); }

## ◆ operator<()

bool Gaudi::StringKey::operator< | ( | const StringKey & | o | ) | const
| inline

less key It can be used as a key for std::map, e.g.

`std::map<StringKey,double>` Note that with such maps one can gain if using prehashed key:

typedef std::map<StringKey,double> MAP ;
const StringKey& key = ... ;
const MAP& m = ... ;
// EFFICIENT:
MAP::const_iterator i1 = m.find ( key ) ;
// CAN BE VERY INEFICIENT:
MAP::const_iterator i2 = m_find( "SomeLongKey,_e.g._TES_Locaiton" );

Definition at line 94 of file StringKey.h.

94 { return m_hash == o.m_hash ? m_str < o.m_str : m_hash < o.m_hash; }
Gaudi::StringKey::m_hash
std::size_t m_hash
the hash:
Definition: StringKey.h:139
Gaudi::StringKey::m_str
std::string m_str
the actual string:
Definition: StringKey.h:137

## ◆ operator<=()

bool Gaudi::StringKey::operator<= | ( | const StringKey & | o | ) | const
| inline

less or equal key

Definition at line 98 of file StringKey.h.

98 { return !( *this > o ); }

## ◆ operator==() [1/2]

bool Gaudi::StringKey::operator== | ( | const StringKey & | o | ) | const
| inline

equality Key for efficiency reason compare the hash-values first

Definition at line 58 of file StringKey.h.

58 { return m_hash == o.m_hash && m_str == o.m_str; }
Gaudi::StringKey::m_hash
std::size_t m_hash
the hash:
Definition: StringKey.h:139
Gaudi::StringKey::m_str
std::string m_str
the actual string:
Definition: StringKey.h:137

## ◆ operator==() [2/2]

bool Gaudi::StringKey::operator== | ( | const std::string & | o | ) | const
| inline

equality, without hashing string rely on the native string equality

Definition at line 62 of file StringKey.h.

62 { return m_str == o; }
Gaudi::StringKey::m_str
std::string m_str
the actual string:
Definition: StringKey.h:137

## ◆ operator>()

bool Gaudi::StringKey::operator> | ( | const StringKey & | o | ) | const
| inline

greater key

Definition at line 96 of file StringKey.h.

96 { return o < *this; }

## ◆ operator>=()

bool Gaudi::StringKey::operator>= | ( | const StringKey & | o | ) | const
| inline

greater or equal key

Definition at line 100 of file StringKey.h.

100 { return !( *this < o ); }

## ◆ str()

const std::string& Gaudi::StringKey::str | ( |  | ) | const
| inline

the actual string

Definition at line 45 of file StringKey.h.

45 { return m_str; }
Gaudi::StringKey::m_str
std::string m_str
the actual string:
Definition: StringKey.h:137

## ◆ toString()

std::string Gaudi::StringKey::toString | ( |  | ) | const

string representation (for properties)

Definition at line 33 of file StringKey.cpp.

33 { return Gaudi::Utils::toString( m_str ); }
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:334
Gaudi::StringKey::m_str
std::string m_str
the actual string:
Definition: StringKey.h:137

## Member Data Documentation

## ◆ m_hash

std::size_t Gaudi::StringKey::m_hash
| private

the hash:

Definition at line 139 of file StringKey.h.

## ◆ m_str

std::string Gaudi::StringKey::m_str
| private

the actual string:

Definition at line 137 of file StringKey.h.

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

- GaudiKernel/GaudiKernel/StringKey.h
- GaudiKernel/src/Lib/StringKey.cpp