- Aldebaran documentation |
- C++ Libraries |
- index

libqi-api 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
print.hpp
Go to the documentation of this file.
1 /*
2 ** Copyright (C) 2017 SoftBank Robotics
3 ** See COPYING for the license
4 */
5
6 #ifndef QI_PRINT_HPP
7 #define QI_PRINT_HPP
8
9 #include <qi/api.hpp>
10 #include <qi/iocolor.hpp>
11 #include <qi/flags.hpp>
12 #include <boost/variant.hpp>
13 #include <boost/utility/string_ref.hpp>
14 #include <ostream>
15 #include <memory>
16
19
20 namespace qi
21 {
22 class MetaObject;
23 class MetaMethod;
24 class MetaSignal;
25 class MetaProperty;
26 class StructTypeInterface;
27 class ListTypeInterface;
28 class MapTypeInterface;
29 class TypeInterface;
30 class Signature;
31
32 namespace detail
33 {
34
35 enum class DisplayHiddenMembers : bool
36 {
37 Hide = false,
38 Display = true,
39 };
40
63 class QI_API PrettyPrintStream
64 {
65 public:
66 enum class Option
67 {
68 Colorized = 1 << 0,
69 Documentation = 1 << 1,
70 RawSignatures = 1 << 2
71 };
72 using Options = qi::Flags<Option>;
73
74 enum class RecurseOption : bool
75 {
76 DoNotRecurse = false,
77 Recurse = true,
78 };
79
81 class QI_API IndentLevel
82 {
83 friend PrettyPrintStream;
84 IndentLevel(PrettyPrintStream& printer);
85
86 public:
87 ~IndentLevel();
88
89 // deleted copy and assignement
90 IndentLevel(const IndentLevel&) = delete;
91 IndentLevel& operator=(const IndentLevel&) = delete;
92
93 private:
94 PrettyPrintStream& _printer;
95 };
96 friend IndentLevel;
97 using IndentLevelPtr = std::unique_ptr<IndentLevel>;
98
100 struct QI_API Column
101 {
102 using ValueType = boost::variant<int, std::string>;
103 enum class Alignment
104 {
105 Left = 0,
106 Right = 1,
107 Internal = 2,
108 };
109 enum class Option
110 {
111 DelimitWithSpace = 1 << 0,
112 };
113 using Options = qi::Flags<Option>;
114
115 explicit Column(ValueType value,
116 StreamColor color = StreamColor_None,
117 Alignment alignment = Alignment::Left,
118 Options opts = Options{Option::DelimitWithSpace},
119 int width = 0,
120 char fillChar = ' ');
121
122 // Regular:
123 Column()
124 : color(StreamColor_None)
125 , alignment(Alignment::Left)
126 , width(0)
127 , fillChar(0)
128 {
129 }
130
131 KA_GENERATE_FRIEND_REGULAR_OPS_6(Column, value, color, alignment, opts, width, fillChar)
132
133 ValueType value;
134 StreamColor color;
135 Alignment alignment;
136 Options opts;
137 int width;
138 char fillChar;
139 };
140 using Columns = std::vector<Column>;
141
144 struct QI_API Line
145 {
146 enum class Option
147 {
148 NewLine = 1 << 0,
149 Indent = 1 << 1,
150 };
151 using Options = qi::Flags<Option>;
152
153 explicit Line(const std::initializer_list<Column>& columns);
154 explicit Line(const Columns& columns, Options opts = Options{Option::NewLine, Option::Indent});
155
156 // Regular:
157 Line() = default;
158
159 KA_GENERATE_FRIEND_REGULAR_OPS_2(Line, columns, opts)
160
161 Columns columns;
162 Options opts;
163 };
164
165 using string_ref = boost::string_ref;
166 static const string_ref infoLabel;
167 static const string_ref methodsLabel;
168 static const string_ref signalsLabel;
169 static const string_ref propertiesLabel;
170 static const string_ref membersLabel;
171 static const string_ref returnTypeLabel;
172 static const string_ref returnDescrLabel;
173 static const string_ref elementTypeLabel;
174 static const string_ref keyTypeLabel;
175 static const string_ref parametersLabel;
176 static const string_ref signalTypesLabel;
177
178 explicit PrettyPrintStream(std::ostream& stream,
179 DisplayHiddenMembers displayHidden = DisplayHiddenMembers::Hide,
180 Options flags = Options{ Option::Colorized },
181 int indentLevel = 0);
182
183 PrettyPrintStream(const PrettyPrintStream&) = delete;
184 PrettyPrintStream& operator=(const PrettyPrintStream&) = delete;
185
186 // TODO: Make this constructor = default when we get rid of VS2013
187 PrettyPrintStream(PrettyPrintStream&& o) BOOST_NOEXCEPT
188 : _stream(std::move(o._stream))
189 , _displayHidden(std::move(o._displayHidden))
190 , _options(std::move(o._options))
191 , _indentLevel(std::move(o._indentLevel))
192 {
193 o._stream = nullptr;
194 }
195
196 // TODO: Make this operator = default when we get rid of VS2013
197 PrettyPrintStream& operator=(PrettyPrintStream&& o) BOOST_NOEXCEPT
198 {
199 _stream = std::move(o._stream);
200 _displayHidden = std::move(o._displayHidden);
201 _options = std::move(o._options);
202 _indentLevel = std::move(o._indentLevel);
203 o._stream = nullptr;
204 return *this;
205 }
206
207 // Custom:
208 static Line makeSectionHeader(const Line& line);
209 static Line makeSubSectionHeader(const Line& line);
210
211 IndentLevelPtr makeIndentLevel();
212
213 void print(const Line& line);
214 void print(const MetaObject& mobj);
215 void print(const MetaMethod& method, int offsetLabel = 0, RecurseOption recurse = RecurseOption::Recurse);
216 void print(const MetaSignal& signal, int offsetLabel = 0, RecurseOption recurse = RecurseOption::Recurse);
217 void print(const MetaProperty& property, int offsetLabel = 0, RecurseOption recurse = RecurseOption::Recurse);
218 void print(TypeInterface* type);
219 void print(StructTypeInterface& structType);
220 void print(ListTypeInterface& listType);
221 void print(MapTypeInterface& mapType);
222
225 template <typename P>
226 PrettyPrintStream& operator<<(P&& printable)
227 {
228 print(std::forward<P>(printable));
229 return *this;
230 }
231
232 private:
233 inline int indentWidth() const
234 {
235 return _indentLevel * indentFactor;
236 }
237
238 void increaseIndent();
239 void decreaseIndent();
240
241 StreamColor colorIfEnabled(StreamColor color) const;
242
244 std::string stringify(const qi::Signature& signature) const;
245
246 void print(const Column& column) const;
247
248 void printParameters(const std::vector<qi::Signature>& paramsSignatures,
249 const std::string& label,
250 RecurseOption recurse);
251
253 template <typename Proc>
254 void printParameters(const std::vector<qi::Signature>& paramsSignatures,
255 const std::string& label,
256 RecurseOption recurse,
257 Proc makeExtraLine);
258
260 template <typename Proc>
261 void print(TypeInterface* type, Proc makeHeaderLine);
262
263 void printDetails(TypeInterface& type);
264
266 template <typename L>
267 void printMetaObjectMembers(const L& members, string_ref headerLabel);
268
269 static const int indentFactor;
270 static const int maxOffset;
271 static const int idColumnWidth;
272 std::ostream* _stream;
273 DisplayHiddenMembers _displayHidden;
274 Options _options;
275 int _indentLevel;
276 };
277
292 class QI_API ParseablePrintStream
293 {
294 public:
295 explicit ParseablePrintStream(std::ostream& stream,
296 DisplayHiddenMembers displayHidden = DisplayHiddenMembers::Hide);
297
298 ParseablePrintStream(const ParseablePrintStream&) = delete;
299 ParseablePrintStream& operator=(const ParseablePrintStream&) = delete;
300
301 // TODO: Make this constructor = default when we get rid of VS2013
302 ParseablePrintStream(ParseablePrintStream&& o) BOOST_NOEXCEPT
303 : _stream(std::move(o._stream))
304 , _displayHidden(std::move(o._displayHidden))
305 {
306 o._stream = nullptr;
307 }
308
309 // TODO: Make this operator = default when we get rid of VS2013
310 ParseablePrintStream& operator=(ParseablePrintStream&& o) BOOST_NOEXCEPT
311 {
312 _stream = std::move(o._stream);
313 _displayHidden = std::move(o._displayHidden);
314 o._stream = nullptr;
315 return *this;
316 }
317
318 // Custom:
320 template <typename S>
321 ParseablePrintStream& operator<<(S&& streamable)
322 {
323 *_stream << std::forward<S>(streamable);
324 return *this;
325 }
326
327 ParseablePrintStream& operator<<(const MetaObject& obj)
328 {
329 print(obj);
330 return *this;
331 }
332
333 void print(const MetaObject& mobj);
334
335 private:
337 template <typename L>
338 void printMetaObjectMembers(const L& members);
339
340 std::ostream* _stream;
341 DisplayHiddenMembers _displayHidden;
342 };
343
344 }
345 }
346
347 #endif // QI_PRINT_HPP
qi::detail::PrettyPrintStream::Column
Contains the data and options needed to fill and format one column of a line.
Definition: print.hpp:100
qi::detail::PrettyPrintStream
Definition: print.hpp:63
QI_API
#define QI_API
Definition: api.hpp:33
qi::MetaMethod
Representation of a method in an GenericObject.
Definition: metamethod.hpp:42
qi::detail::PrettyPrintStream::string_ref
boost::string_ref string_ref
Definition: print.hpp:165
qi::detail::ParseablePrintStream
Definition: print.hpp:292
qi::detail::PrettyPrintStream::Column::Option
Option
Definition: print.hpp:109
qi::detail::PrettyPrintStream::operator<<
PrettyPrintStream & operator<<(P &&printable)
Definition: print.hpp:226
qi::Signature
Definition: signature.hpp:66
qi::detail::PrettyPrintStream::RecurseOption
RecurseOption
Definition: print.hpp:74
qi::detail::ParseablePrintStream::operator=
ParseablePrintStream & operator=(ParseablePrintStream &&o) BOOST_NOEXCEPT
Definition: print.hpp:310
api.hpp
dll import/export and compiler message
qi::MetaSignal
Representation of a Signal in an GenericObject.
Definition: metasignal.hpp:20
qi::StreamColor
StreamColor
The Stream Color enum.
Definition: iocolor.hpp:19
qi::MapTypeInterface
Definition: typeinterface.hpp:213
qi::detail::PrettyPrintStream::Line::Option
Option
Definition: print.hpp:146
qi::TypeInterface
Definition: typeinterface.hpp:129
qi::detail::ParseablePrintStream::operator<<
ParseablePrintStream & operator<<(const MetaObject &obj)
Definition: print.hpp:327
qi::detail::PrettyPrintStream::Option
Option
Definition: print.hpp:66
qi::Flags< Option >
qi::detail::ParseablePrintStream::ParseablePrintStream
ParseablePrintStream(ParseablePrintStream &&o) BOOST_NOEXCEPT
Definition: print.hpp:302
qi::detail::PrettyPrintStream::IndentLevel
Encapsulates in a RAII style a shift or an indentation level of a PrettyPrintStream instance...
Definition: print.hpp:81
qi::detail::PrettyPrintStream::Column::ValueType
boost::variant< int, std::string > ValueType
Definition: print.hpp:102
qi::detail::PrettyPrintStream::Column::Column
Column()
Definition: print.hpp:123
qi::detail::DisplayHiddenMembers::Hide
qi::detail::DisplayHiddenMembers::Display
flags.hpp
qi::detail::PrettyPrintStream::Columns
std::vector< Column > Columns
Definition: print.hpp:140
qi::detail::PrettyPrintStream::operator=
PrettyPrintStream & operator=(PrettyPrintStream &&o) BOOST_NOEXCEPT
Definition: print.hpp:197
qi::detail::PrettyPrintStream::IndentLevelPtr
std::unique_ptr< IndentLevel > IndentLevelPtr
Definition: print.hpp:97
qi::detail::DisplayHiddenMembers
DisplayHiddenMembers
Definition: print.hpp:35
qi::detail::ParseablePrintStream::operator<<
ParseablePrintStream & operator<<(S &&streamable)
OutputStreamable S.
Definition: print.hpp:321
qi::log::color
LogColor color()
Get log color.
qi::ListTypeInterface
Definition: typeinterface.hpp:188
qi::detail::PrettyPrintStream::IndentLevel
friend IndentLevel
Definition: print.hpp:96
qi::MetaProperty
Definition: metaproperty.hpp:19
qi::detail::PrettyPrintStream::PrettyPrintStream
PrettyPrintStream(PrettyPrintStream &&o) BOOST_NOEXCEPT
Definition: print.hpp:187
iocolor.hpp
qi::detail::PrettyPrintStream::Column::Alignment
Alignment
Definition: print.hpp:103
qi::StructTypeInterface
Definition: typeinterface.hpp:241
qi::detail::PrettyPrintStream::Line
Definition: print.hpp:144
qi::MetaObject
Description of the signals and methods accessible on an ObjectTypeInterface.
Definition: metaobject.hpp:25
qi::StreamColor_None
No Color.
Definition: iocolor.hpp:21