#include #include #include #include // $Id: MultiObject_imp.h 14717 2009-09-17 20:24:36Z lukas $ #define MULTIOBJECT_INST(Type, LabeledType) \ template class MultiObject using namespace std; using namespace utl; template MultiObject& MultiObject::operator=(const MultiObject& obj) { if (this == &obj) return *this; for (InternalConstIterator it = fObjects.begin(); it != fObjects.end(); ++it) delete it->second; fObjects.clear(); for (InternalConstIterator it = obj.fObjects.begin(); it != obj.fObjects.end(); ++it) fObjects.insert(make_pair(it->first, new T(*it->second))); return *this; } template T& MultiObject::GetObject(const int label) { const InternalIterator it = fObjects.find(label); if (it != fObjects.end()) return *it->second; ostringstream err; err << "No object '" << GetObjectName() << "' with label " << label << " found"; ERROR(err); throw NonExistentComponentException(err.str()); } template const T& MultiObject::GetObject(const int label) const { const InternalConstIterator it = fObjects.find(label); if (it != fObjects.end()) return *it->second; ostringstream err; err << "No object '" << GetObjectName() << "' with label " << label << " found"; ERROR(err); throw NonExistentComponentException(err.str()); } //static template string MultiObject::GetObjectName() { int status; return abi::__cxa_demangle(typeid(T).name(), 0, 0, &status); } template void MultiObject::AddObject(T* const obj, const int label) { const InternalIterator it = fObjects.find(label); if (it != fObjects.end()) { ostringstream info; info << "Replacing object '" << GetObjectName() << '\''; INFO(info); delete it->second; it->second = obj; } else fObjects.insert(make_pair(label, obj)); } template void MultiObject::RemoveObject(const int label) { const InternalIterator it = fObjects.find(label); if (it == fObjects.end()) { ostringstream err; err << "Object '" << GetObjectName() << "' with label " << label << " not found"; ERROR(err); } else { delete it->second; fObjects.erase(it); } } template MultiObject::~MultiObject() { for (InternalConstIterator it = fObjects.begin(); it != fObjects.end(); ++it) delete it->second; } template bool MultiObject::operator==(const MultiObject& mobj) const { if (fObjects.size() != mobj.fObjects.size()) return false; for (InternalConstIterator it1 = fObjects.begin(), it2 = mobj.fObjects.begin(); it1 != fObjects.end() && it2 != mobj.fObjects.end(); ++it1, ++it2) if (it1->first != it2->first || *it1->second != *it2->second) return false; return true; } template void MultiObject::Clear() { for (InternalConstIterator it = fObjects.begin(); it != fObjects.end(); ++it) delete it->second; fObjects.clear(); } // Configure (x)emacs for this file ... // Local Variables: // mode: c++ // End: