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[] = "00010203040506070809"
37  "10111213141516171819"
38  "20212223242526272829"
39  "30313233343536373839"
40  "40414243444546474849"
41  "50515253545556575859"
42  "60616263646566676869"
43  "70717273747576777879"
44  "80818283848586878889"
45  "90919293949596979899";
46  if (value < 10)
47  {
48  buffer[0] = static_cast<char>('0' + value);
49  return 1;
50  }
51  else if (value < 100)
52  {
53  value *= 2;
54  buffer[0] = DIGITS[value];
55  buffer[1] = DIGITS[value + 1];
56  return 2;
57  }
58  else
59  {
60  return sprintf(buffer, "%d", value);
61  }
62 }
63 
64 namespace RosMsgParser
65 {
66 
85 struct FieldLeaf
86 {
89 };
90 
92 {
93  FieldsVector() = default;
94 
95  FieldsVector(const FieldLeaf& leaf);
96 
99 
101  void toStr(std::string& destination) const;
102 
103  std::string toStdString() const
104  {
105  std::string out;
106  toStr(out);
107  return out;
108  }
109 };
110 
111 //---------------------------------
112 
113 inline std::ostream& operator<<(std::ostream& os, const FieldsVector& leaf)
114 {
115  std::string dest;
116  leaf.toStr(dest);
117  os << dest;
118  return os;
119 }
120 
121 } // namespace RosMsgParser
122 
123 #endif // ROSTYPE_H
RosMsgParser::FieldsVector
Definition: stringtree_leaf.hpp:91
RosMsgParser::FieldLeaf::node
const FieldTreeNode * node
Definition: stringtree_leaf.hpp:87
RosMsgParser::FieldsVector::toStr
void toStr(std::string &destination) const
Utility functions to print the entire branch.
Definition: stringtree_leaf.cpp:41
ros_message.hpp
RosMsgParser::FieldsVector::index_array
SmallVector< uint16_t, 4 > index_array
Definition: stringtree_leaf.hpp:98
RosMsgParser
Definition: builtin_types.hpp:34
RosMsgParser::FieldsVector::fields
SmallVector< const ROSField *, 8 > fields
Definition: stringtree_leaf.hpp:97
RosMsgParser::FieldLeaf::index_array
SmallVector< uint16_t, 4 > index_array
Definition: stringtree_leaf.hpp:88
dest
char * dest
Definition: lz4.h:765
RosMsgParser::FieldsVector::toStdString
std::string toStdString() const
Definition: stringtree_leaf.hpp:103
llvm_vecsmall::SmallVector
Definition: SmallVector.h:1029
RosMsgParser::operator<<
std::ostream & operator<<(std::ostream &os, const BuiltinType &c)
Definition: builtin_types.hpp:138
print_number
int print_number(char *buffer, uint16_t value)
Definition: stringtree_leaf.hpp:34
RosMsgParser::FieldsVector::FieldsVector
FieldsVector()=default
sprintf
auto sprintf(const S &fmt, const T &... args) -> std::basic_string< Char >
Definition: printf.h:612
RosMsgParser::FieldLeaf
The FieldTreeLeaf is, as the name suggests, a leaf (terminal node) of a StringTree....
Definition: stringtree_leaf.hpp:85
RosMsgParser::details::TreeNode
Element of the tree. it has a single parent and N >= 0 children.
Definition: tree.hpp:119


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:47