MultiObject_imp.h
Go to the documentation of this file.
1 #ifndef _utl_MultiObject_imp_h_
2 #define _utl_MultiObject_imp_h_
3 
4 #include <utl/MultiObject.h>
5 #include <utl/AugerException.h>
6 #include <utl/ErrorLogger.h>
7 #include <utl/TypeId.h>
8 
9 using namespace std;
10 using namespace utl;
11 
12 
13 #define MULTIOBJECT_INST(Type, LabeledType) \
14  template class MultiObject<Type, LabeledType >
15 
16 
17 template<typename T, typename LabeledObjectType>
20 {
21  if (this == &obj)
22  return *this;
23 
24  Clear();
25 
26  for (const auto& lp : obj.fObjects)
27  fObjects.emplace(lp.first, new T(*lp.second));
28 
29  return *this;
30 }
31 
32 
33 template<typename T, typename LabeledObjectType>
34 T&
36 {
37  const InternalIterator it = fObjects.find(label);
38 
39  if (it != fObjects.end())
40  return *it->second;
41 
42  ostringstream err;
43  err << "No object '" << TypeId::Name<T>()
44  << "' with label " << label << " found";
45  ERROR(err);
46  throw NonExistentComponentException(err.str());
47 }
48 
49 
50 template<typename T, typename LabeledObjectType>
51 const T&
53  const
54 {
55  const InternalConstIterator it = fObjects.find(label);
56 
57  if (it != fObjects.end())
58  return *it->second;
59 
60  ostringstream err;
61  err << "No object '" << TypeId::Name<T>()
62  << "' with label " << label << " found";
63  ERROR(err);
64  throw NonExistentComponentException(err.str());
65 }
66 
67 
68 template<typename T, typename LabeledObjectType>
69 void
70 MultiObject<T, LabeledObjectType>::AddObject(T* const obj, const int label)
71 {
72  const InternalIterator it = fObjects.find(label);
73 
74  if (it != fObjects.end()) {
75  ostringstream info;
76  info << "Replacing object '" << TypeId::Name<T>() << '\'';
77  INFO(info);
78  delete it->second;
79  it->second = obj;
80  } else
81  fObjects.insert(make_pair(label, obj));
82 }
83 
84 
85 template<typename T, typename LabeledObjectType>
86 void
88 {
89  const InternalIterator it = fObjects.find(label);
90 
91  if (it == fObjects.end()) {
92  ostringstream err;
93  err << "Object '" << TypeId::Name<T>() << "' with label "
94  << label << " not found";
95  ERROR(err);
96  } else {
97  delete it->second;
98  fObjects.erase(it);
99  }
100 }
101 
102 
103 template<typename T, typename LabeledObjectType>
105 {
106  for (const auto& lp : fObjects)
107  delete lp.second;
108 }
109 
110 
111 template<typename T, typename LabeledObjectType>
112 bool
114  const
115 {
116  if (fObjects.size() != mobj.fObjects.size())
117  return false;
118 
119  for (InternalConstIterator it1 = fObjects.begin(), it2 = mobj.fObjects.begin();
120  it1 != fObjects.end() && it2 != mobj.fObjects.end(); ++it1, ++it2)
121  if (it1->first != it2->first || *it1->second != *it2->second)
122  return false;
123 
124  return true;
125 }
126 
127 
128 template<typename T, typename LabeledObjectType>
129 void
131 {
132  for (const auto& lp : fObjects)
133  delete lp.second;
134  fObjects.clear();
135 }
136 
137 
138 #endif
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
MultiObjectContainer::const_iterator InternalConstIterator
Definition: MultiObject.h:138
Base class for exceptions trying to access non-existing components.
MultiObjectContainer::iterator InternalIterator
Definition: MultiObject.h:137
bool operator==(const TimeStamp &ts, const TimeRange &tr)
Definition: TimeRange.h:97
container for object and associated labels
Definition: MultiObject.h:71
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
MultiObjectContainer fObjects
Definition: MultiObject.h:140

, generated on Tue Sep 26 2023.