ATLAS Offline Software
Loading...
Searching...
No Matches
SGVersionedKey.h
Go to the documentation of this file.
1/* -*- C++ -*- */
2
3/*
4 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5*/
6
10#ifndef SGTOOLS_VERSIONEDKEY_H
11#define SGTOOLS_VERSIONEDKEY_H 1
12#include <iostream>
13#include <string>
14class StoreGateSvc; //our friend
15class SGImplSvc; //our friend
16namespace SG {
17 template <class T> class ObjectWithVersion;
18
32 friend class ::StoreGateSvc; //call copyVK
33 friend class ::SGImplSvc; //call copyVK
34 public:
36 static bool isVersionedKey(const char *);
38 static bool isVersionedKey(const std::string&);
39
42 static bool isAuto(const std::string&);
43
45 VersionedKey(const char* key, unsigned char version);
47 VersionedKey(const std::string& key, unsigned char version);
48
52 explicit VersionedKey(const char* vkey);
56 explicit VersionedKey(const std::string& vkey);
57
58 //Defaulted copy and move constructors and assignment operators
59 //since the class only holds strings.
60 VersionedKey(const VersionedKey& rhs) = default;
61 VersionedKey(VersionedKey&& rhs) = default;
62 VersionedKey& operator= (const VersionedKey& rhs) = default;
64
66
68 void decode(std::string& outKey, unsigned char& version) const;
69 // cppcheck-suppress returnByReference
70 operator std::string() const { return m_versionKey; }
72 unsigned char version() const;
74 const std::string& key() const;
76 const std::string& rawVersionKey() const {
77 return m_versionKey;
78 }
79
80 bool sameKey(const VersionedKey& vkey) const;
82 bool sameKey(const std::string& baseKey) const;
84 bool sameKey(const char* baseKey) const;
85 bool isAuto() const { return version() == VersionedKey::autoV(); }
86
87 private:
88 template <class U> friend class ObjectWithVersion;
91
92 void encode(const std::string& inKey, unsigned char version);
93 void copyVK(const std::string& inKey);
94
95 static char separator() {return ';';}
96 static const char* versionFormatString() {return ";%02u;";}
97 static const char* formatString() {return ";%02u;%s";}
98
99 static unsigned char autoV() { return 99;}
100 static unsigned char defaultV() { return 0;}
101 static const char* autoVS() { return "_99_"; }
102 static const char* defaultVS() { return "_00_"; }
103
106 std::string m_versionKey;
107 std::string m_baseKey;
108 };
109} // ns SG
110
112bool operator < (const SG::VersionedKey& lhs, const SG::VersionedKey& rhs);
113
114namespace SG {
115 inline
116 std::ostream& operator <<(std::ostream& ost, const SG::VersionedKey& k) {
117 return ost << k.rawVersionKey();
118 // return ost.write(k.rawVersionKey(), strlen(k.rawVersionKey()));
119 }
120}
121
122#endif
bool operator<(const SG::VersionedKey &lhs, const SG::VersionedKey &rhs)
sort according to highest key version
The Athena Transient Store API.
Definition SGImplSvc.h:110
associate a data object with its VersionedKey The object is held by a ReadHandle to delay its retriev...
a StoreGateSvc key with a version number.
VersionedKey(VersionedKey &&rhs)=default
static unsigned char autoV()
bool sameKey(const VersionedKey &vkey) const
compare base keys
VersionedKey(const char *key, unsigned char version)
version must be [0,98], 0 is the default version
VersionedKey(const VersionedKey &rhs)=default
static unsigned char defaultV()
unsigned char version() const
bool isAuto() const
static bool isVersionedKey(const char *)
quickly determine whether a string has the right format to be a VK
const std::string & rawVersionKey() const
friend class ObjectWithVersion
void copyVK(const std::string &inKey)
static const char * autoVS()
static char separator()
static const char * defaultVS()
VersionedKey()
default constructor (invalid state, do not use)
void encode(const std::string &inKey, unsigned char version)
static const char * formatString()
std::string m_baseKey
static const char * versionFormatString()
VersionedKey & operator=(const VersionedKey &rhs)=default
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)...
std::string m_versionKey
the encoded version/key.
const std::string & key() const
The Athena Transient Store API.
Forward declaration.
std::ostream & operator<<(std::ostream &os, const ArenaAllocatorBase::Stats::Stat &stat)
Format a statistic structure.