xmlrpc_casts.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018, Hamburg University
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Hamburg University nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Michael Görner, Robert Haschke */
36 
38 #include <ros/console.h>
39 #include <boost/algorithm/string/join.hpp>
40 
41 namespace moveit
42 {
43 namespace core
44 {
45 double parseDouble(const XmlRpc::XmlRpcValue& v)
46 {
48  return static_cast<double>(v);
49  else if (v.getType() == XmlRpc::XmlRpcValue::TypeInt)
50  return static_cast<int>(v);
51  else
52  return 0.0;
53 }
54 
55 bool isArray(const XmlRpc::XmlRpcValue& v, size_t size, const std::string& name, const std::string& description)
56 {
57  if (v.getType() != XmlRpc::XmlRpcValue::TypeArray || (size != 0 && static_cast<size_t>(v.size()) != size))
58  {
59  if (!name.empty())
60  ROS_WARN_STREAM(name << " is not an array[" << size << "] of "
61  << (description.empty() ? "elements" : description.c_str()));
62  return false;
63  }
64  return true;
65 }
66 
67 bool isStruct(const XmlRpc::XmlRpcValue& v, const std::vector<std::string>& keys, const std::string& name)
68 {
70  {
71  if (!name.empty())
72  ROS_WARN_STREAM(name << " is not a struct with keys " << boost::join(keys, ","));
73  return false;
74  }
75 
76  std::vector<std::string> missing;
77  for (const std::string& key : keys)
78  if (!v.hasMember(key))
79  missing.push_back(key);
80 
81  if (!name.empty() && !missing.empty())
82  {
83  ROS_WARN_STREAM(name << " is not a struct with keys " << boost::join(keys, ",") << " (misses "
84  << boost::join(missing, ",") << ")");
85  return false;
86  }
87 
88  return missing.empty();
89 }
90 } // namespace core
91 } // namespace moveit
XmlRpc::XmlRpcValue::size
int size() const
xmlrpc_casts.h
moveit::core::isStruct
bool isStruct(const XmlRpc::XmlRpcValue &v, const std::vector< std::string > &keys={}, const std::string &name="")
Definition: xmlrpc_casts.cpp:131
XmlRpc::XmlRpcValue::TypeInt
TypeInt
XmlRpc::XmlRpcValue::TypeStruct
TypeStruct
console.h
ROS_WARN_STREAM
#define ROS_WARN_STREAM(args)
XmlRpc::XmlRpcValue::TypeDouble
TypeDouble
name
std::string name
moveit::core::parseDouble
double parseDouble(const XmlRpc::XmlRpcValue &v)
parse a double value from a scalar XmlRpc
Definition: xmlrpc_casts.cpp:109
XmlRpc::XmlRpcValue::getType
const Type & getType() const
XmlRpc::XmlRpcValue::TypeArray
TypeArray
XmlRpc::XmlRpcValue::hasMember
bool hasMember(const std::string &name) const
moveit
Main namespace for MoveIt.
Definition: background_processing.h:46
moveit::core::isArray
bool isArray(const XmlRpc::XmlRpcValue &v, size_t size=0, const std::string &name="", const std::string &description="")
Definition: xmlrpc_casts.cpp:119
XmlRpc::XmlRpcValue


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Sun Mar 3 2024 03:23:36