CMS 3D CMS Logo

DataKey.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Framework
00004 // Class  :     DataKey
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Author:      Chris Jones
00010 // Created:     Thu Mar 31 14:31:13 EST 2005
00011 // $Id: DataKey.cc,v 1.8 2008/01/22 21:46:02 wmtan Exp $
00012 //
00013 
00014 // system include files
00015 #include <memory>
00016 
00017 // user include files
00018 #include "FWCore/Framework/interface/DataKey.h"
00019 
00020 
00021 //
00022 // constants, enums and typedefs
00023 //
00024 namespace edm {
00025    namespace eventsetup {
00026 //
00027 // static data member definitions
00028 //
00029 
00030 //
00031 // constructors and destructor
00032 //
00033 DataKey::DataKey(): type_(), name_(), ownMemory_(false)
00034 {
00035 }
00036 
00037 // DataKey::DataKey(const DataKey& rhs)
00038 // {
00039 //    // do actual copying here;
00040 // }
00041 
00042 //DataKey::~DataKey()
00043 //{
00044 //}
00045 
00046 //
00047 // assignment operators
00048 //
00049 const DataKey& DataKey::operator=(const DataKey& rhs)
00050 {
00051    //An exception safe implementation is
00052    DataKey temp(rhs);
00053    swap(temp);
00054 
00055    return *this;
00056 }
00057 
00058 //
00059 // member functions
00060 //
00061 void
00062 DataKey::swap(DataKey& iOther)
00063 {
00064    std::swap(ownMemory_, iOther.ownMemory_);
00065    // unqualified swap is used for user defined classes.
00066    // The using directive is needed so that std::swap will be used if there is no other matching swap.
00067    using std::swap;
00068    swap(type_, iOther.type_);
00069    swap(name_, iOther.name_);
00070 }
00071 
00072 void 
00073 DataKey::makeCopyOfMemory()
00074 {
00075    //empty string is the most common case, so handle it special
00076    static const char kBlank = '\0';
00077    
00078    char* pName = const_cast<char*>(&kBlank);
00079    //NOTE: if in the future additional tags are added then 
00080    // I should make sure that pName gets deleted in the case
00081    // where an exception is thrown
00082    std::auto_ptr<char> pNameHolder;
00083    if(kBlank != name().value()[0]) {
00084       pName = new char[ std::strlen(name().value()) + 1];
00085       pNameHolder = std::auto_ptr<char>(pName);
00086       std::strcpy(pName, name().value());
00087    }
00088    name_ = NameTag(pName);
00089    ownMemory_ = true;
00090    pNameHolder.release();
00091 }
00092 
00093 void
00094 DataKey::deleteMemory()
00095 {
00096    static const char kBlank = '\0';
00097    
00098    if(kBlank != name().value()[0]) {
00099       delete [] const_cast<char*>(name().value());
00100    }
00101 }
00102 
00103 //
00104 // const member functions
00105 //
00106 bool
00107 DataKey::operator==(const DataKey& iRHS) const 
00108 {
00109    return ((type_ == iRHS.type_) &&
00110             (name_ == iRHS.name_));
00111 }
00112 
00113 bool
00114 DataKey::operator<(const DataKey& iRHS) const 
00115 {
00116    return (type_ < iRHS.type_) ||
00117    ((type_ == iRHS.type_) && (name_ < iRHS.name_));
00118 /*
00119    if(type_ < iRHS.type_) {
00120       return true;
00121    } else if (type_ == iRHS.type_) {
00122       if(name_ < iRHS.name_) {
00123          return true;
00124    }
00125    return false;
00126       */
00127 }
00128 
00129 //
00130 // static member functions
00131 //
00132    }
00133 }
00134 
00135 #include "FWCore/Framework/interface/HCTypeTag.icc"
00136 template class edm::eventsetup::heterocontainer::HCTypeTag<edm::eventsetup::DataKey>;

Generated on Tue Jun 9 17:35:53 2009 for CMSSW by  doxygen 1.5.4