stringtree_leaf.hpp
Go to the documentation of this file.
1 /***** MIT License ****
2 *
3 * Copyright (c) 2016-2022 Davide Faconti
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23 
24 #ifndef ROS_INTROSPECTION_FieldTreeLeaf_H
25 #define ROS_INTROSPECTION_FieldTreeLeaf_H
26 
27 #include <vector>
28 #include <map>
29 #include <iostream>
30 
32 
33 // Brutally faster for numbers below 100
34 inline int print_number(char* buffer, uint16_t value)
35 {
36  const char DIGITS[] =
37  "00010203040506070809"
38  "10111213141516171819"
39  "20212223242526272829"
40  "30313233343536373839"
41  "40414243444546474849"
42  "50515253545556575859"
43  "60616263646566676869"
44  "70717273747576777879"
45  "80818283848586878889"
46  "90919293949596979899";
47  if (value < 10)
48  {
49  buffer[0] = static_cast<char>('0' + value);
50  return 1;
51  }
52  else if (value < 100) {
53  value *= 2;
54  buffer[0] = DIGITS[ value ];
55  buffer[1] = DIGITS[ value+1 ];
56  return 2;
57  }
58  else{
59  return sprintf( buffer,"%d", value );
60  }
61 }
62 
63 namespace RosMsgParser{
64 
83 struct FieldLeaf
84 {
87 };
88 
90 {
91  FieldsVector() = default;
92 
93  FieldsVector(const FieldLeaf& leaf);
94 
97 
99  void toStr(std::string &destination) const;
100 
101  std::string toStdString() const
102  {
103  std::string out;
104  toStr(out);
105  return out;
106  }
107 };
108 
109 //---------------------------------
110 
111 inline std::ostream& operator<<(std::ostream &os, const FieldsVector& leaf )
112 {
113  std::string dest;
114  leaf.toStr(dest);
115  os << dest;
116  return os;
117 }
118 
119 
120 }
121 
122 #endif // ROSTYPE_H
void toStr(std::string &destination) const
Utility functions to print the entire branch.
auto sprintf(const S &fmt, const T &... args) -> std::basic_string< Char >
Definition: printf.h:574
SmallVector< uint16_t, 4 > index_array
const FieldTreeNode * node
SmallVector< const ROSField *, 8 > fields
Definition: core.h:760
SmallVector< uint16_t, 4 > index_array
std::ostream & operator<<(std::ostream &os, const BuiltinType &c)
int print_number(char *buffer, uint16_t value)
std::string toStdString() const
Definition: core.h:1131
const char * toStr(const BuiltinType &c)
The FieldTreeLeaf 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 "#".
Element of the tree. it has a single parent and N >= 0 children.
Definition: tree.hpp:53
char * dest
Definition: lz4.h:697


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:12:53