00001 #ifndef ERIS_ATLAS_UTILS_H
00002 #define ERIS_ATLAS_UTILS_H
00003
00004 #include <Atlas/Objects/Root.h>
00005
00006 #include <stdexcept>
00007 #include <cassert>
00008
00009 namespace Atlas {
00010
00011 template <class T>
00012 const T atlas_cast(const Message::Element &data)
00013 {
00014 T obj;
00015 if (!data.isMap()) {
00016 assert(false);
00017 throw std::invalid_argument("Input message object is not a map");
00018 }
00019
00020 const Message::Element::MapType & mp = data.asMap();
00021
00022 for (Message::Element::MapType::const_iterator A = mp.begin();
00023 A != mp.end(); ++A)
00024 {
00025 obj.setAttr(A->first, A->second);
00026 }
00027
00028 return obj;
00029 }
00030
00031 template <class T>
00032 const T atlas_cast(const Objects::Root &data)
00033 {
00034 T obj;
00035 Message::Element::MapType mp = data.asObject().asMap();
00036
00037 for (Message::Element::MapType::iterator A = mp.begin();
00038 A != mp.end(); ++A)
00039 {
00040 obj.setAttr(A->first, A->second);
00041 }
00042
00043 return obj;
00044 }
00045
00046 }
00047
00048 #endif