stringtree_leaf.hpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright 2016-2017 Davide Faconti
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 Willow Garage, Inc. 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 #ifndef ROS_INTROSPECTION_STRINGTREELEAF_H
36 #define ROS_INTROSPECTION_STRINGTREELEAF_H
37 
38 #include <vector>
39 #include <map>
40 #include <iostream>
41 #include <boost/container/small_vector.hpp>
42 #include <boost/container/static_vector.hpp>
44 
45 namespace RosIntrospection{
46 
66 
68 
70 
71  boost::container::static_vector<uint16_t,8> index_array;
72 
74  bool toStr(std::string &destination) const;
75 
76  // return string length or -1 if failed
77  int toStr(char* buffer) const;
78 
79  std::string toStdString() const { std::string out; toStr(out); return out; }
80 
81  constexpr static const char SEPARATOR = '/';
82  constexpr static const char NUM_PLACEHOLDER = '#';
83 
84  static const boost::string_ref& num_placeholder() {
85  static const boost::string_ref nph("#");
86  return nph;
87  }
88 };
89 
90 void CreateStringFromTreeLeaf(const StringTreeLeaf& leaf, bool skip_root, std::string &out);
91 
92 //---------------------------------
93 
94 inline std::ostream& operator<<(std::ostream &os, const StringTreeLeaf& leaf )
95 {
96  std::string dest;
97  leaf.toStr(dest);
98  os << dest;
99  return os;
100 }
101 
103 { }
104 
105 
106 inline bool StringTreeLeaf::toStr(std::string& destination) const
107 {
108  char buffer[256];
109  int offset = this->toStr(buffer);
110 
111  if( offset < 0 ) {
112  destination.clear();
113  return false;
114  }
115  destination.assign(buffer, offset);
116  return true;
117 }
118 
119 
120 }
121 
122 #endif // ROSTYPE_H
The StringTreeLeaf is, as the name suggests, a leaf (terminal node) of a StringTree. It provides the pointer to the node and a list of numbers that represent the index that corresponds to the placeholder "#".
static constexpr const char NUM_PLACEHOLDER
Element of the tree. it has a single parent and N >= 0 children.
Definition: tree.hpp:54
std::ostream & operator<<(std::ostream &os, const BuiltinType &c)
void CreateStringFromTreeLeaf(const StringTreeLeaf &leaf, bool skip_root, std::string &out)
boost::container::static_vector< uint16_t, 8 > index_array
const StringTreeNode * node_ptr
bool toStr(std::string &destination) const
Utility functions to print the entire branch.
static constexpr const char SEPARATOR
static const boost::string_ref & num_placeholder()


ros_type_introspection
Author(s): Davide Faconti
autogenerated on Sun Sep 6 2020 03:19:54