ATLAS Offline Software
Loading...
Searching...
No Matches
SG::VersionedKey Class Reference

a StoreGateSvc key with a version number. More...

#include <SGVersionedKey.h>

Collaboration diagram for SG::VersionedKey:

Public Member Functions

 VersionedKey (const char *key, unsigned char version)
 version must be [0,98], 0 is the default version
 VersionedKey (const std::string &key, unsigned char version)
 version must be [0,98], 0 is the default version
 VersionedKey (const char *vkey)
 make a VersionedKey from vkey string.
 VersionedKey (const std::string &vkey)
 make a VersionedKey from vkey string.
 VersionedKey (const VersionedKey &rhs)=default
 VersionedKey (VersionedKey &&rhs)=default
VersionedKeyoperator= (const VersionedKey &rhs)=default
VersionedKeyoperator= (VersionedKey &&rhs)=default
 ~VersionedKey ()
void decode (std::string &outKey, unsigned char &version) const
 sets outKey to point to base key, and version to encoded version (0 is taken to mean default version).
 operator std::string () const
unsigned char version () const
const std::string & key () const
const std::string & rawVersionKey () const
bool sameKey (const VersionedKey &vkey) const
 compare base keys
bool sameKey (const std::string &baseKey) const
 compare base keys
bool sameKey (const char *baseKey) const
 compare base keys
bool isAuto () const

Static Public Member Functions

static bool isVersionedKey (const char *)
 quickly determine whether a string has the right format to be a VK
static bool isVersionedKey (const std::string &)
 quickly determine whether a string has the right format to be a VK
static bool isAuto (const std::string &)
 quickly determine whether a string has the right format to be a VK with auto-generated version #

Private Member Functions

 VersionedKey ()
 default constructor (invalid state, do not use)
void encode (const std::string &inKey, unsigned char version)
void copyVK (const std::string &inKey)

Static Private Member Functions

static char separator ()
static const char * versionFormatString ()
static const char * formatString ()
static unsigned char autoV ()
static unsigned char defaultV ()
static const char * autoVS ()
static const char * defaultVS ()

Private Attributes

std::string m_versionKey
 the encoded version/key.
std::string m_baseKey

Friends

class ::StoreGateSvc
class ::SGImplSvc
template<class U>
class ObjectWithVersion

Detailed Description

a StoreGateSvc key with a version number.

Notice that StoreGate does not order multiple instances of an object with a given key by version number. A generic retrieve will always return the first version recorded. For example, if object ("MyKey",1) is recorded _before__ ("MyKey", 2) a sg.retrieve(pObj,"MyKey") will return ("MyKey",1). StoreGateSvc provides retrieveAllVersions and retrieveHighestVersion, which offer a better-defined behaviour.

Author
pcala.nosp@m.fiur.nosp@m.a@lbl.nosp@m..gov - ATLAS Collaboration
Id
SGVersionedKey.h,v 1.4 2008-07-10 15:51:04 dquarrie Exp

Definition at line 31 of file SGVersionedKey.h.

Constructor & Destructor Documentation

◆ VersionedKey() [1/7]

VersionedKey::VersionedKey ( const char * key,
unsigned char version )

version must be [0,98], 0 is the default version

Definition at line 32 of file SGVersionedKey.cxx.

32 {
33 encode(std::string(key), version);
34}
unsigned char version() const
void encode(const std::string &inKey, unsigned char version)
const std::string & key() const

◆ VersionedKey() [2/7]

VersionedKey::VersionedKey ( const std::string & key,
unsigned char version )

version must be [0,98], 0 is the default version

Definition at line 35 of file SGVersionedKey.cxx.

35 {
37}

◆ VersionedKey() [3/7]

VersionedKey::VersionedKey ( const char * vkey)
explicit

make a VersionedKey from vkey string.

If vkey has the VersionedKey format (;NN;key), it is simply copied, otherwise it is taken to be the real key, and default version is assigned

Definition at line 41 of file SGVersionedKey.cxx.

41 {
42 copyVK(std::string(versionedKey));
43}
void copyVK(const std::string &inKey)

◆ VersionedKey() [4/7]

VersionedKey::VersionedKey ( const std::string & vkey)
explicit

make a VersionedKey from vkey string.

If vkey has the VersionedKey format (;NN;key), it is simply copied, otherwise it is taken to be the real key, and default version is assigned

Definition at line 38 of file SGVersionedKey.cxx.

38 {
39 copyVK(versionedKey);
40}

◆ VersionedKey() [5/7]

SG::VersionedKey::VersionedKey ( const VersionedKey & rhs)
default

◆ VersionedKey() [6/7]

SG::VersionedKey::VersionedKey ( VersionedKey && rhs)
default

◆ ~VersionedKey()

VersionedKey::~VersionedKey ( )

Definition at line 15 of file SGVersionedKey.cxx.

15{}

◆ VersionedKey() [7/7]

SG::VersionedKey::VersionedKey ( )
inlineprivate

default constructor (invalid state, do not use)

Definition at line 90 of file SGVersionedKey.h.

90: m_versionKey() {}
std::string m_versionKey
the encoded version/key.

Member Function Documentation

◆ autoV()

unsigned char SG::VersionedKey::autoV ( )
inlinestaticprivate

Definition at line 99 of file SGVersionedKey.h.

99{ return 99;}

◆ autoVS()

const char * SG::VersionedKey::autoVS ( )
inlinestaticprivate

Definition at line 101 of file SGVersionedKey.h.

101{ return "_99_"; }

◆ copyVK()

void VersionedKey::copyVK ( const std::string & inKey)
private

Definition at line 59 of file SGVersionedKey.cxx.

59 {
60 if (isVersionedKey(inKey)) {
61 m_versionKey = inKey;
62 m_baseKey = m_versionKey.substr(4);
63 } else {
64 encode(inKey, 0); //FIXME should autoincrement
65 }
66}
static bool isVersionedKey(const char *)
quickly determine whether a string has the right format to be a VK
std::string m_baseKey

◆ decode()

void VersionedKey::decode ( std::string & outKey,
unsigned char & version ) const

sets outKey to point to base key, and version to encoded version (0 is taken to mean default version).

Definition at line 45 of file SGVersionedKey.cxx.

45 {
46 outKey = this->key();
47 version = (unsigned char)atoi(m_versionKey.substr(1,2).c_str());
48 assert(version <= 99);
49}
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...

◆ defaultV()

unsigned char SG::VersionedKey::defaultV ( )
inlinestaticprivate

Definition at line 100 of file SGVersionedKey.h.

100{ return 0;}

◆ defaultVS()

const char * SG::VersionedKey::defaultVS ( )
inlinestaticprivate

Definition at line 102 of file SGVersionedKey.h.

102{ return "_00_"; }

◆ encode()

void VersionedKey::encode ( const std::string & inKey,
unsigned char version )
private

Definition at line 51 of file SGVersionedKey.cxx.

51 {
52 assert(version <= 99);
53 char vers[6];
54 snprintf(vers, 6, versionFormatString(), version);
55 m_versionKey = vers + inKey;
56 m_baseKey = inKey;
57}
static const char * versionFormatString()

◆ formatString()

const char * SG::VersionedKey::formatString ( )
inlinestaticprivate

Definition at line 97 of file SGVersionedKey.h.

97{return ";%02u;%s";}

◆ isAuto() [1/2]

bool SG::VersionedKey::isAuto ( ) const
inline

Definition at line 85 of file SGVersionedKey.h.

85{ return version() == VersionedKey::autoV(); }
static unsigned char autoV()

◆ isAuto() [2/2]

bool VersionedKey::isAuto ( const std::string & vkey)
static

quickly determine whether a string has the right format to be a VK with auto-generated version #

Definition at line 28 of file SGVersionedKey.cxx.

28 {
29 return (vkey.compare(0,4, VersionedKey::autoVS())==0);
30}
static const char * autoVS()

◆ isVersionedKey() [1/2]

bool VersionedKey::isVersionedKey ( const char * vkey)
static

quickly determine whether a string has the right format to be a VK

Definition at line 18 of file SGVersionedKey.cxx.

18 {
19 return (vkey[0]==separator() && vkey[3]==separator());
20}
static char separator()

◆ isVersionedKey() [2/2]

bool VersionedKey::isVersionedKey ( const std::string & vkey)
static

quickly determine whether a string has the right format to be a VK

Definition at line 23 of file SGVersionedKey.cxx.

23 {
24 return isVersionedKey(vkey.c_str());
25}

◆ key()

const std::string & VersionedKey::key ( ) const
Returns
base key

Definition at line 71 of file SGVersionedKey.cxx.

71 {
72 return m_baseKey;
73}

◆ operator std::string()

SG::VersionedKey::operator std::string ( ) const
inline

Definition at line 70 of file SGVersionedKey.h.

70{ return m_versionKey; }

◆ operator=() [1/2]

VersionedKey & SG::VersionedKey::operator= ( const VersionedKey & rhs)
default

◆ operator=() [2/2]

VersionedKey & SG::VersionedKey::operator= ( VersionedKey && rhs)
default

◆ rawVersionKey()

const std::string & SG::VersionedKey::rawVersionKey ( ) const
inline
Returns
access underlying encoded m_versionKey C string

Definition at line 76 of file SGVersionedKey.h.

76 {
77 return m_versionKey;
78 }

◆ sameKey() [1/3]

bool VersionedKey::sameKey ( const char * baseKey) const

compare base keys

Definition at line 86 of file SGVersionedKey.cxx.

86 {
87 return (this->key() == std::string(baseKey));
88}

◆ sameKey() [2/3]

bool VersionedKey::sameKey ( const std::string & baseKey) const

compare base keys

Definition at line 81 of file SGVersionedKey.cxx.

81 {
82 return (this->key() == baseKey);
83}

◆ sameKey() [3/3]

bool VersionedKey::sameKey ( const VersionedKey & vkey) const

compare base keys

Definition at line 76 of file SGVersionedKey.cxx.

76 {
77 return (this->key() == vkey.key());
78}

◆ separator()

char SG::VersionedKey::separator ( )
inlinestaticprivate

Definition at line 95 of file SGVersionedKey.h.

95{return ';';}

◆ version()

unsigned char VersionedKey::version ( ) const
Returns
version number

Definition at line 67 of file SGVersionedKey.cxx.

67 {
68 return (unsigned char) std::stoul(m_versionKey.substr(1,2), nullptr, 0);
69}

◆ versionFormatString()

const char * SG::VersionedKey::versionFormatString ( )
inlinestaticprivate

Definition at line 96 of file SGVersionedKey.h.

96{return ";%02u;";}

◆ ::SGImplSvc

friend class ::SGImplSvc
friend

Definition at line 33 of file SGVersionedKey.h.

◆ ::StoreGateSvc

friend class ::StoreGateSvc
friend

Definition at line 32 of file SGVersionedKey.h.

◆ ObjectWithVersion

template<class U>
friend class ObjectWithVersion
friend

Definition at line 88 of file SGVersionedKey.h.

Member Data Documentation

◆ m_baseKey

std::string SG::VersionedKey::m_baseKey
private

Definition at line 107 of file SGVersionedKey.h.

◆ m_versionKey

std::string SG::VersionedKey::m_versionKey
private

the encoded version/key.

Mutable so that ownership can be transferred in the copy constructor

Definition at line 106 of file SGVersionedKey.h.


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