CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
19 
20 
21 //
22 // constants, enums and typedefs
23 //
24 namespace edm {
25  namespace eventsetup {
26 //
27 // static data member definitions
28 //
29 
30 //
31 // constructors and destructor
32 //
33 DataKey::DataKey(): type_(), name_(), ownMemory_(false)
34 {
35 }
36 
37 // DataKey::DataKey(const DataKey& rhs)
38 // {
39 // // do actual copying here;
40 // }
41 
42 //DataKey::~DataKey()
43 //{
44 //}
45 
46 //
47 // assignment operators
48 //
50 {
51  //An exception safe implementation is
52  DataKey temp(rhs);
53  swap(temp);
54 
55  return *this;
56 }
57 
58 //
59 // member functions
60 //
61 void
63 {
65  // unqualified swap is used for user defined classes.
66  // The using directive is needed so that std::swap will be used if there is no other matching swap.
67  using std::swap;
68  swap(type_, iOther.type_);
69  swap(name_, iOther.name_);
70 }
71 
72 void
74 {
75  //empty string is the most common case, so handle it special
76  static const char kBlank = '\0';
77 
78  char* pName = const_cast<char*>(&kBlank);
79  //NOTE: if in the future additional tags are added then
80  // I should make sure that pName gets deleted in the case
81  // where an exception is thrown
82  std::auto_ptr<char> pNameHolder;
83  if(kBlank != name().value()[0]) {
84  pName = new char[ std::strlen(name().value()) + 1];
85  pNameHolder = std::auto_ptr<char>(pName);
86  std::strcpy(pName, name().value());
87  }
88  name_ = NameTag(pName);
89  ownMemory_ = true;
90  pNameHolder.release();
91 }
92 
93 void
95 {
96  static const char kBlank = '\0';
97 
98  if(kBlank != name().value()[0]) {
99  delete [] const_cast<char*>(name().value());
100  }
101 }
102 
103 //
104 // const member functions
105 //
106 bool
107 DataKey::operator==(const DataKey& iRHS) const
108 {
109  return ((type_ == iRHS.type_) &&
110  (name_ == iRHS.name_));
111 }
112 
113 bool
114 DataKey::operator<(const DataKey& iRHS) const
115 {
116  return (type_ < iRHS.type_) ||
117  ((type_ == iRHS.type_) && (name_ < iRHS.name_));
118 /*
119  if(type_ < iRHS.type_) {
120  return true;
121  } else if (type_ == iRHS.type_) {
122  if(name_ < iRHS.name_) {
123  return true;
124  }
125  return false;
126  */
127 }
128 
129 //
130 // static member functions
131 //
132  }
133 }
bool operator<(const DataKey &iRHS) const
Definition: DataKey.cc:114
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
const DataKey & operator=(const DataKey &)
Definition: DataKey.cc:49
bool operator==(const DataKey &iRHS) const
Definition: DataKey.cc:107
friend void swap(DataKey &, DataKey &)
Definition: DataKey.h:100
const NameTag & name() const
Definition: DataKey.h:67
const char * value() const
Definition: DataKeyTags.h:40