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>
44 
45 namespace RosIntrospection{
46 
47 // Still faster in my benchmark than absl::InlinedVector
48 
49 template <typename T, size_t N>
51 public:
53  void push_back(T val) { _array[_size++] = val; }
54  const T& back() const { return _array[_size-1]; }
55  T& back() { return _array[_size-1]; }
56  size_t size() const { return _size; }
57  const T& operator[](size_t index) const { return _array[index]; }
58  T& operator[](size_t index) { return _array[index]; }
59 private:
60  std::array<T,N> _array;
61  size_t _size;
62 };
63 
83 
85 
87 
89 
91  bool toStr(std::string &destination) const;
92 
93  // return string length or -1 if failed
94  int toStr(char* buffer) const;
95 
96  std::string toStdString() const { std::string out; toStr(out); return out; }
97 
98  constexpr static const char SEPARATOR = '/';
99  constexpr static const char NUM_PLACEHOLDER = '#';
100 
102  constexpr static const absl::string_view nph("#");
103  return nph;
104  }
105 };
106 
107 //---------------------------------
108 
109 inline std::ostream& operator<<(std::ostream &os, const StringTreeLeaf& leaf )
110 {
111  std::string dest;
112  leaf.toStr(dest);
113  os << dest;
114  return os;
115 }
116 
117 inline StringTreeLeaf::StringTreeLeaf(): node_ptr(nullptr)
118 { }
119 
120 
121 inline bool StringTreeLeaf::toStr(std::string& destination) const
122 {
123  char buffer[256];
124  int offset = this->toStr(buffer);
125 
126  if( offset < 0 ) {
127  destination.clear();
128  return false;
129  }
130  destination.assign(buffer, offset);
131  return true;
132 }
133 
134 
135 }
136 
137 #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 "#".
NodeSet out
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)
static const absl::string_view & num_placeholder()
InlinedVector< uint16_t, 8 > index_array
const char * toStr(const BuiltinType &c)
const StringTreeNode * node_ptr
bool toStr(std::string &destination) const
Utility functions to print the entire branch.
const T & operator[](size_t index) const


ros_type_introspection
Author(s): Davide Faconti
autogenerated on Thu May 16 2019 02:39:09