XmlRpcHelper.cpp
Go to the documentation of this file.
00001 /*
00002  * XmlRpcHelper.cpp
00003  *
00004  *  Created on: Oct 12, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include <telekyb_base/Tools/XmlRpcHelper.hpp>
00009 
00010 #include <iostream>
00011 
00012 #include <boost/lexical_cast.hpp>
00013 using boost::lexical_cast;
00014 
00015 namespace TELEKYB_NAMESPACE
00016 {
00017 
00018 
00019 // Multiple Level Arrays are not supported!
00020 bool XmlRpcHelper::xmlRpcValuetoString(XmlRpc::XmlRpcValue xmlValue, std::string& value) {
00021 
00022         bool ret = false;
00023 
00024         switch (xmlValue.getType()) {
00025                 case XmlRpc::XmlRpcValue::TypeArray: {
00026                         // no multiple level support // only Number support (and boolean)
00027                         std::stringstream ss;
00028                         std::string temp;
00029                         std::string seperator("");
00030                         ret = true;
00031                         for (int i = 0; i < xmlValue.size(); i++) {
00032                                 if (xmlValue[i].getType() == XmlRpc::XmlRpcValue::TypeBoolean
00033                                                 || xmlValue[i].getType() == XmlRpc::XmlRpcValue::TypeDouble
00034                                                 || xmlValue[i].getType() == XmlRpc::XmlRpcValue::TypeInt) {
00035                                         xmlRpcValuetoString(xmlValue[i], temp);
00036                                         ss << seperator << temp;
00037                                         seperator = " ";
00038                                 }
00039                                 else {
00040                                         ret = false;
00041                                         break;
00042                                 }
00043                         }
00044                         // ok
00045                         if (ret) {
00046                                 value = ss.str();
00047                         }
00048                         break;
00049                 }
00050                 case XmlRpc::XmlRpcValue::TypeBase64:
00051                         // NOT IMPLEMENTED
00052                         break;
00053                 case XmlRpc::XmlRpcValue::TypeBoolean:
00054                         if ((bool)xmlValue) {
00055                                 value = "true";
00056                         } else {
00057                                 value = "false";
00058                         }
00059                         //std::cout << "BoolValue: " << value << std::endl;
00060                         //value = lexical_cast<std::string>((bool)xmlValue);
00061                         //std::cout << "BoolValue: " << value << std::endl;
00062                         ret = true;
00063                         break;
00064                 case XmlRpc::XmlRpcValue::TypeDateTime:
00065                         // NOT IMPLEMENTED
00066                         break;
00067                 case XmlRpc::XmlRpcValue::TypeDouble:
00068                         value = lexical_cast<std::string>((double)xmlValue);
00069                         ret = true;
00070                         break;
00071                 case XmlRpc::XmlRpcValue::TypeInt:
00072                         value = lexical_cast<std::string>((int)xmlValue);
00073                         ret = true;
00074                         break;
00075                 case XmlRpc::XmlRpcValue::TypeString:
00076                         value = (std::string)xmlValue;
00077                         ret = true;
00078                         break;
00079                 case XmlRpc::XmlRpcValue::TypeStruct:
00080                         // NOT IMPLEMENTED
00081                         break;
00082                 default:
00083                         break;
00084         }
00085 
00086 
00087         return ret;
00088 }
00089 
00090 } // namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


telekyb_base
Author(s): Dr. Antonio Franchi and Martin Riedel
autogenerated on Mon Nov 11 2013 11:12:34