The Gaudi Framework  master (37c0b60a)
Gaudi::Details::SharedString Class Referencefinal

std::string wrapper for static strings where identical values actually share the memory. More...

#include </builds/gaudi/Gaudi/GaudiCoreSvc/src/JobOptionsSvc/PropertyId.h>

Collaboration diagram for Gaudi::Details::SharedString:

Public Member Functions

 SharedString (std::string_view s={})
 Create a new SharedString checking if the value is already in the shared storage otherwise adding it. More...
 
 operator std::string () const
 
 operator std::string_view () const
 
bool operator== (std::string_view other) const
 
bool operator== (const SharedString &other) const
 
template<typename T >
bool operator== (const T &other) const
 

Static Private Member Functions

static const std::stringget (std::string_view s)
 

Private Attributes

const std::stringm_s
 

Static Private Attributes

static std::unordered_set< std::stringstorage
 

Detailed Description

std::string wrapper for static strings where identical values actually share the memory.

This class is useful when dealing with several duplicated strings so that the actual value is kept in memory only once and all the SharedString instances point to it.

SharedString is automatically comparable and convertible to std::string.

Definition at line 36 of file PropertyId.h.

Constructor & Destructor Documentation

◆ SharedString()

Gaudi::Details::SharedString::SharedString ( std::string_view  s = {})
inline

Create a new SharedString checking if the value is already in the shared storage otherwise adding it.

Definition at line 40 of file PropertyId.h.

40 {} ) : m_s{ SharedString::get( s ) } {}

Member Function Documentation

◆ get()

static const std::string* Gaudi::Details::SharedString::get ( std::string_view  s)
inlinestaticprivate

Definition at line 56 of file PropertyId.h.

56  {
57  if ( s.empty() ) { return {}; }
58  return &*( storage.emplace( s ).first );
59  }

◆ operator std::string()

Gaudi::Details::SharedString::operator std::string ( ) const
inline

Definition at line 42 of file PropertyId.h.

42 { return *m_s; }

◆ operator std::string_view()

Gaudi::Details::SharedString::operator std::string_view ( ) const
inline

Definition at line 43 of file PropertyId.h.

43 { return *m_s; }

◆ operator==() [1/3]

bool Gaudi::Details::SharedString::operator== ( const SharedString other) const
inline

Definition at line 46 of file PropertyId.h.

46 { return m_s == other.m_s; }

◆ operator==() [2/3]

template<typename T >
bool Gaudi::Details::SharedString::operator== ( const T &  other) const
inline

Definition at line 49 of file PropertyId.h.

49  {
50  return *m_s == other;
51  }

◆ operator==() [3/3]

bool Gaudi::Details::SharedString::operator== ( std::string_view  other) const
inline

Definition at line 45 of file PropertyId.h.

45 { return *m_s == other; }

Member Data Documentation

◆ m_s

const std::string* Gaudi::Details::SharedString::m_s
private

Definition at line 54 of file PropertyId.h.

◆ storage

std::unordered_set< std::string > Gaudi::Details::SharedString::storage
staticprivate

Definition at line 61 of file PropertyId.h.


The documentation for this class was generated from the following files:
Gaudi::Details::SharedString::storage
static std::unordered_set< std::string > storage
Definition: PropertyId.h:61
gaudirun.s
string s
Definition: gaudirun.py:346
std::unordered_set::emplace
T emplace(T... args)
Gaudi::Details::SharedString::get
static const std::string * get(std::string_view s)
Definition: PropertyId.h:56
Gaudi::Details::SharedString::m_s
const std::string * m_s
Definition: PropertyId.h:54