YamlHelper.hpp
Go to the documentation of this file.
00001 /*
00002  * YamlHelper.hpp
00003  *
00004  *  Created on: Nov 13, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #ifndef YAMLHELPER_HPP_
00009 #define YAMLHELPER_HPP_
00010 
00011 #include <telekyb_defines/telekyb_defines.hpp>
00012 
00013 #include <ros/console.h>
00014 
00015 #include <yaml-cpp/yaml.h>
00016 // Conversion
00017 #include <telekyb_base/Tools/YamlConversion.hpp>
00018 
00019 namespace TELEKYB_NAMESPACE
00020 {
00021 
00022 
00023 class YamlHelper {
00024 public:
00025         // Parse Node to String
00026         static bool parseNodeToString(const YAML::Node& node, std::string& output);
00027         static bool parseStringToNode(const std::string& string, YAML::Node& node);
00028 
00029         // Parse Node to Value
00030         template < class _T >
00031         static bool parseNodeToValue(const YAML::Node& input, _T& value) {
00032                 bool success = true;
00033                 try {
00034                         value = input.as<_T>();
00035                         //input >> value;
00036                 } catch (YAML::Exception &e) {
00037                         ROS_ERROR_STREAM("Error converting from YAML! " << e.what());
00038                         success = false;
00039                 } catch (std::runtime_error &e) {
00040                         ROS_ERROR_STREAM("Error converting from YAML! " << e.what());
00041                         success = false;
00042                 }
00043 
00044                 return success;
00045         }
00046 
00047         // Template Helpers
00048         template < class _T >
00049         static bool parseStringToValue(const std::string& input, _T& value) {
00050                 //ROS_INFO_STREAM("Parsing: " << input);
00051                 YAML::Node node = YAML::Load(input);
00052                 return parseNodeToValue(node, value);
00053         }
00054 
00055         template < class _T >
00056         static bool parseValueToString(const _T& value , std::string& output) {
00057                 YAML::Node node( value );// = value;
00058                 return parseNodeToString(node, output);
00059         }
00060 
00061         // direct accessor
00062         template < class _T >
00063         static std::string parseValueToString(const _T& value) {
00064                 std::string str("yaml-conversion failed");
00065                 parseValueToString(value, str);
00066                 return str;
00067         }
00068 
00069 
00070 
00071 };
00072 
00073 }
00074 
00075 
00076 #endif /* YAMLHELPER_HPP_ */
 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