|
Urbi SDK Remote for C++
2.7.5
|
00001 /* 00002 * Copyright (C) 2009-2011, Gostai S.A.S. 00003 * 00004 * This software is provided "as is" without warranty of any kind, 00005 * either expressed or implied, including but not limited to the 00006 * implied warranties of fitness for a particular purpose. 00007 * 00008 * See the LICENSE file for more information. 00009 */ 00010 00012 00013 #include <urbi/uvalue.hh> 00014 00015 namespace urbi 00016 { 00017 00018 template <typename T> 00019 inline 00020 int 00021 getValue(UMessage* m, T& val) 00022 { 00023 bool res = m && m->type == MESSAGE_DATA; 00024 if (res) 00025 val = *m->value; 00026 delete m; 00027 return res; 00028 } 00029 00030 template <> 00031 inline 00032 int 00033 getValue<ufloat>(UMessage* m, ufloat& val) 00034 { 00035 bool res = m && m->type == MESSAGE_DATA && m->value->type == DATA_DOUBLE; 00036 if (res) 00037 val = m->value->val; 00038 delete m; 00039 return res; 00040 } 00041 00042 template <> 00043 inline 00044 int 00045 getValue<std::string>(UMessage* m, std::string& val) 00046 { 00047 bool res = m && m->type == MESSAGE_DATA && m->value->type == DATA_STRING; 00048 if (res) 00049 val = *m->value->stringValue; 00050 delete m; 00051 return res; 00052 } 00053 00054 inline 00055 UMessage::operator urbi::UValue& () 00056 { 00057 return *value; 00058 } 00059 00060 inline 00061 std::ostream& 00062 operator<<(std::ostream& o, const UMessage& m) 00063 { 00064 return m.print(o); 00065 }; 00066 00067 } // namespace urbi