File indexing completed on 2024-04-06 12:12:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <memory>
0015 #include <cstring>
0016
0017
0018 #include "FWCore/Framework/interface/DataKey.h"
0019
0020
0021
0022
0023
0024 namespace {
0025 constexpr char kBlank[] = {'\0'};
0026 }
0027
0028 namespace edm::eventsetup {
0029
0030 DataKey::DataKey() = default;
0031
0032 DataKey& DataKey::operator=(const DataKey& rhs) {
0033
0034 DataKey temp(rhs);
0035 swap(temp);
0036
0037 return *this;
0038 }
0039
0040 DataKey& DataKey::operator=(DataKey&& rhs) {
0041
0042 DataKey temp(std::move(rhs));
0043 swap(temp);
0044
0045 return *this;
0046 }
0047
0048
0049
0050
0051 void DataKey::swap(DataKey& iOther) {
0052 std::swap(ownMemory_, iOther.ownMemory_);
0053
0054
0055 using std::swap;
0056 swap(type_, iOther.type_);
0057 swap(name_, iOther.name_);
0058 }
0059
0060 namespace {
0061
0062 class ArrayHolder {
0063 public:
0064 ArrayHolder() = default;
0065
0066 void swap(ArrayHolder& iOther) {
0067 const char* t = iOther.ptr_;
0068 iOther.ptr_ = ptr_;
0069 ptr_ = t;
0070 }
0071 ArrayHolder(const char* iPtr) : ptr_(iPtr) {}
0072 ~ArrayHolder() { delete[] ptr_; }
0073 void release() { ptr_ = nullptr; }
0074
0075 private:
0076 const char* ptr_{nullptr};
0077 };
0078 }
0079
0080 void DataKey::makeCopyOfMemory() {
0081
0082
0083 char* pName = const_cast<char*>(kBlank);
0084
0085
0086
0087 ArrayHolder pNameHolder;
0088 if (kBlank[0] != name().value()[0]) {
0089 size_t const nBytes = std::strlen(name().value()) + 1;
0090 pName = new char[nBytes];
0091 ArrayHolder t(pName);
0092 pNameHolder.swap(t);
0093 std::strncpy(pName, name().value(), nBytes);
0094 }
0095 name_ = NameTag(pName);
0096 ownMemory_ = true;
0097 pNameHolder.release();
0098 }
0099
0100 void DataKey::deleteMemory() {
0101 if (kBlank[0] != name().value()[0]) {
0102 delete[] const_cast<char*>(name().value());
0103 }
0104 }
0105
0106
0107
0108
0109 bool DataKey::operator==(const DataKey& iRHS) const { return ((type_ == iRHS.type_) && (name_ == iRHS.name_)); }
0110
0111 bool DataKey::operator<(const DataKey& iRHS) const {
0112 return (type_ < iRHS.type_) || ((type_ == iRHS.type_) && (name_ < iRHS.name_));
0113 }
0114 }