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>
14#include <format>
15class StoreGateSvc; //our friend
16class SGImplSvc; //our friend
17namespace SG {
18 template <class T> class ObjectWithVersion;
19
33 friend class ::StoreGateSvc; //call copyVK
34 friend class ::SGImplSvc; //call copyVK
35 public:
37 static bool isVersionedKey(const char *);
39 static bool isVersionedKey(const std::string&);
40
43 static bool isAuto(const std::string&);
44
46 VersionedKey(const char* key, unsigned char version);
48 VersionedKey(const std::string& key, unsigned char version);
49
53 explicit VersionedKey(const char* vkey);
57 explicit VersionedKey(const std::string& vkey);
58
59 //Defaulted copy and move constructors and assignment operators
60 //since the class only holds strings.
61 VersionedKey(const VersionedKey& rhs) = default;
62 VersionedKey(VersionedKey&& rhs) = default;
63 VersionedKey& operator= (const VersionedKey& rhs) = default;
65
67
69 void decode(std::string& outKey, unsigned char& version) const;
70 // cppcheck-suppress returnByReference
71 operator std::string() const { return m_versionKey; }
73 unsigned char version() const;
75 const std::string& key() const;
77 const std::string& rawVersionKey() const {
78 return m_versionKey;
79 }
80
81 bool sameKey(const VersionedKey& vkey) const;
83 bool sameKey(const std::string& baseKey) const;
85 bool sameKey(const char* baseKey) const;
86 bool isAuto() const { return version() == VersionedKey::autoV(); }
87
88 private:
89 template <class U> friend class ObjectWithVersion;
92
93 void encode(const std::string& inKey, unsigned char version);
94 void copyVK(const std::string& inKey);
95
96 static char separator() {return ';';}
97 static const char* versionFormatString() {return ";%02u;";}
98 static const char* formatString() {return ";%02u;%s";}
99
100 static unsigned char autoV() { return 99;}
101 static unsigned char defaultV() { return 0;}
102 static const char* autoVS() { return "_99_"; }
103 static const char* defaultVS() { return "_00_"; }
104
107 std::string m_versionKey;
108 std::string m_baseKey;
109 };
110} // ns SG
111
113bool operator < (const SG::VersionedKey& lhs, const SG::VersionedKey& rhs);
114
115namespace SG {
116 inline
117 std::ostream& operator <<(std::ostream& ost, const SG::VersionedKey& k) {
118 return ost << k.rawVersionKey();
119 }
120}
121
123namespace std {
124template <>
125struct formatter<SG::VersionedKey>
126 : public formatter<string_view>
127{
128 template <class FmtContext>
129 FmtContext::iterator format(const SG::VersionedKey& k, FmtContext& ctx) const
130 {
131 return formatter<string_view>::format (k.rawVersionKey(), ctx);
132 }
133};
134}
135
136#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:109
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.
STL namespace.
FmtContext::iterator format(const SG::VersionedKey &k, FmtContext &ctx) const