Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-05-23 02:04:59

0001 // -*- C++ -*-
0002 //
0003 // Package:     Framework
0004 // Class  :     DataKey
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Author:      Chris Jones
0010 // Created:     Thu Mar 31 14:31:13 EST 2005
0011 //
0012 
0013 // system include files
0014 #include <memory>
0015 #include <cstring>
0016 
0017 // user include files
0018 #include "FWCore/Framework/interface/DataKey.h"
0019 
0020 //
0021 // constants, enums and typedefs
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     //An exception safe implementation is
0034     DataKey temp(rhs);
0035     swap(temp);
0036 
0037     return *this;
0038   }
0039 
0040   DataKey& DataKey::operator=(DataKey&& rhs) {
0041     //An exception safe implementation is
0042     DataKey temp(std::move(rhs));
0043     swap(temp);
0044 
0045     return *this;
0046   }
0047 
0048   //
0049   // member functions
0050   //
0051   void DataKey::swap(DataKey& iOther) {
0052     std::swap(ownMemory_, iOther.ownMemory_);
0053     // unqualified swap is used for user defined classes.
0054     // The using directive is needed so that std::swap will be used if there is no other matching swap.
0055     using std::swap;
0056     swap(type_, iOther.type_);
0057     swap(name_, iOther.name_);
0058   }
0059 
0060   void DataKey::makeCopyOfMemory() {
0061     //empty string is the most common case, so handle it special
0062 
0063     char const* pName = kBlank;
0064     std::unique_ptr<char[]> pNameHolder;
0065     if (kBlank[0] != name().value()[0]) {
0066       size_t const nBytes = std::strlen(name().value()) + 1;
0067       pNameHolder.reset(new char[nBytes]);
0068       pName = pNameHolder.get();
0069       std::strncpy(pNameHolder.get(), name().value(), nBytes);
0070     }
0071     name_ = NameTag(pName);
0072     ownMemory_ = true;
0073     pNameHolder.release();
0074   }
0075 
0076   void DataKey::deleteMemory() {
0077     if (kBlank[0] != name().value()[0]) {
0078       delete[] (name().value());
0079     }
0080   }
0081 
0082   //
0083   // const member functions
0084   //
0085   bool DataKey::operator==(const DataKey& iRHS) const { return ((type_ == iRHS.type_) && (name_ == iRHS.name_)); }
0086 
0087   bool DataKey::operator<(const DataKey& iRHS) const {
0088     return (type_ < iRHS.type_) || ((type_ == iRHS.type_) && (name_ < iRHS.name_));
0089   }
0090 }  // namespace edm::eventsetup