00001 #ifndef ATLAS_CAST_H
00002 #define ATLAS_CAST_H
00003
00004 #include <stdexcept>
00005
00006 #include <Atlas/Message/Object.h>
00007 #include <Atlas/Objects/Root.h>
00008
00009 namespace Atlas {
00010
00011 template <class T>
00012 const T atlas_cast(const Message::Object &data)
00013 {
00014 T obj = T::Instantiate();
00015 if (!data.IsMap()) {
00016 assert(false);
00017 throw std::invalid_argument("Input message object is not a map");
00018 }
00019
00020 const Message::Object::MapType & mp = data.AsMap();
00021
00022 for (Message::Object::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 = T::Instantiate();
00035 Message::Object::MapType mp = data.AsObject().AsMap();
00036
00037 for (Message::Object::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