FWCore
Framework
src
DataKey.cc
Go to the documentation of this file.
1
// -*- C++ -*-
2
//
3
// Package: Framework
4
// Class : DataKey
5
//
6
// Implementation:
7
// <Notes on implementation>
8
//
9
// Author: Chris Jones
10
// Created: Thu Mar 31 14:31:13 EST 2005
11
//
12
13
// system include files
14
#include <memory>
15
#include <cstring>
16
17
// user include files
18
#include "
FWCore/Framework/interface/DataKey.h
"
19
20
//
21
// constants, enums and typedefs
22
//
23
24
namespace
{
25
constexpr
char
kBlank[] = {
'\0'
};
26
}
27
28
namespace
edm::eventsetup
{
29
30
DataKey::DataKey
() =
default
;
31
32
DataKey
&
DataKey::operator=
(
const
DataKey
& rhs) {
33
//An exception safe implementation is
34
DataKey
temp
(rhs);
35
swap
(
temp
);
36
37
return
*
this
;
38
}
39
40
DataKey
&
DataKey::operator=
(
DataKey
&& rhs) {
41
//An exception safe implementation is
42
DataKey
temp
(
std::move
(rhs));
43
swap
(
temp
);
44
45
return
*
this
;
46
}
47
48
//
49
// member functions
50
//
51
void
DataKey::swap
(
DataKey
& iOther) {
52
std::swap
(
ownMemory_
, iOther.
ownMemory_
);
53
// unqualified swap is used for user defined classes.
54
// The using directive is needed so that std::swap will be used if there is no other matching swap.
55
using
std::swap
;
56
swap
(
type_
, iOther.
type_
);
57
swap
(
name_
, iOther.
name_
);
58
}
59
60
namespace
{
61
//used for exception safety
62
class
ArrayHolder {
63
public
:
64
ArrayHolder() =
default
;
65
66
void
swap
(ArrayHolder& iOther) {
67
const
char
*
t
= iOther.ptr_;
68
iOther.ptr_ =
ptr_
;
69
ptr_
=
t
;
70
}
71
ArrayHolder(
const
char
* iPtr) :
ptr_
(iPtr) {}
72
~ArrayHolder() {
delete
[]
ptr_
; }
73
void
release
() {
ptr_
=
nullptr
; }
74
75
private
:
76
const
char
*
ptr_
{
nullptr
};
77
};
78
}
// namespace
79
80
void
DataKey::makeCopyOfMemory
() {
81
//empty string is the most common case, so handle it special
82
83
char
* pName = const_cast<char*>(kBlank);
84
//NOTE: if in the future additional tags are added then
85
// I should make sure that pName gets deleted in the case
86
// where an exception is thrown
87
ArrayHolder pNameHolder;
88
if
(kBlank[0] !=
name
().
value
()[0]) {
89
size_t
const
nBytes = std::strlen(
name
().
value
()) + 1;
90
pName =
new
char
[nBytes];
91
ArrayHolder
t
(pName);
92
pNameHolder.swap(
t
);
93
std::strncpy(pName,
name
().
value
(), nBytes);
94
}
95
name_
=
NameTag
(pName);
96
ownMemory_
=
true
;
97
pNameHolder.release();
98
}
99
100
void
DataKey::deleteMemory
() {
101
if
(kBlank[0] !=
name
().
value
()[0]) {
102
delete
[] const_cast<char*>(
name
().
value
());
103
}
104
}
105
106
//
107
// const member functions
108
//
109
bool
DataKey::operator==
(
const
DataKey
& iRHS)
const
{
return
((
type_
== iRHS.
type_
) && (
name_
== iRHS.
name_
)); }
110
111
bool
DataKey::operator<
(
const
DataKey
& iRHS)
const
{
112
return
(
type_
< iRHS.
type_
) || ((
type_
== iRHS.
type_
) && (
name_
< iRHS.
name_
));
113
}
114
}
// namespace edm::eventsetup
edm::eventsetup::DataKey::makeCopyOfMemory
void makeCopyOfMemory()
Definition:
DataKey.cc:80
edm::eventsetup::DataKey::name_
NameTag name_
Definition:
DataKey.h:80
edm::eventsetup::DataKey::type_
TypeTag type_
Definition:
DataKey.h:79
edm::eventsetup::DataKey
Definition:
DataKey.h:29
edm::eventsetup::DataKey::operator==
bool operator==(const DataKey &iRHS) const
Definition:
DataKey.cc:109
edm::eventsetup::DataKey::DataKey
DataKey()
edm::eventsetup::DataKey::swap
friend void swap(DataKey &, DataKey &)
Definition:
DataKey.h:85
edm::eventsetup::DataKey::deleteMemory
void deleteMemory()
Definition:
DataKey.cc:100
groupFilesInBlocks.temp
list temp
Definition:
groupFilesInBlocks.py:142
ptr_
const char * ptr_
Definition:
DataKey.cc:76
edm::eventsetup::DataKey::operator=
DataKey & operator=(const DataKey &)
Definition:
DataKey.cc:32
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition:
DataFrameContainer.h:209
edm::eventsetup::DataKey::name
const NameTag & name() const
Definition:
DataKey.h:53
edm::eventsetup::DataKey::operator<
bool operator<(const DataKey &iRHS) const
Definition:
DataKey.cc:111
edm::eventsetup::DataKey::ownMemory_
bool ownMemory_
Definition:
DataKey.h:81
OrderedSet.t
t
Definition:
OrderedSet.py:90
fetchall_from_DQM_v2.release
release
Definition:
fetchall_from_DQM_v2.py:92
DataKey.h
eostools.move
def move(src, dest)
Definition:
eostools.py:511
relativeConstraints.value
value
Definition:
relativeConstraints.py:53
edm::eventsetup::swap
void swap(DataKey &a, DataKey &b)
Definition:
DataKey.h:85
edm::eventsetup::NameTag
Definition:
DataKeyTags.h:45
edm::eventsetup
Definition:
ES_DDDetector.cc:16
Generated for CMSSW Reference Manual by
1.8.16