OpenDDS  Snapshot(2023/04/28-20:55)
PrinterValueWriter.h
Go to the documentation of this file.
1 /*
2  * Distributed under the OpenDDS License.
3  * See: http://www.opendds.org/license.html
4  */
5 
6 #ifndef OPENDDS_DCPS_PRINTER_VALUE_WRITER_H
7 #define OPENDDS_DCPS_PRINTER_VALUE_WRITER_H
8 
9 #include "ValueWriter.h"
10 #include "ValueHelper.h"
11 #include "dcps_export.h"
12 #include "Definitions.h"
13 
14 #include <dds/DdsDcpsCoreTypeSupportImpl.h>
15 #include <dds/DdsDcpsTopicC.h>
16 
17 #include <iosfwd>
18 #include <sstream>
19 #include <vector>
20 
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 #pragma once
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 
26 
27 namespace OpenDDS {
28 namespace DCPS {
29 
30 /// Convert values to a readable format.
32 public:
33  explicit PrinterValueWriter(unsigned int a_indent = TheServiceParticipant->printer_value_writer_indent())
34  : indent_(a_indent)
35  , current_indent_(0)
36  , at_newline_(true)
37  {}
38 
39  void begin_struct();
40  void end_struct();
41  void begin_struct_member(const DDS::MemberDescriptor& /*descriptor*/);
42  void end_struct_member();
43 
44  void begin_union();
45  void end_union();
46  void begin_discriminator();
47  void end_discriminator();
48  void begin_union_member(const char* name);
49  void end_union_member();
50 
51  void begin_array();
52  void end_array();
53  void begin_sequence();
54  void end_sequence();
55  void begin_element(size_t idx);
56  void end_element();
57 
59  void write_byte(ACE_CDR::Octet value);
60 #if OPENDDS_HAS_EXPLICIT_INTS
61  void write_int8(ACE_CDR::Int8 value);
62  void write_uint8(ACE_CDR::UInt8 value);
63 #endif
64  void write_int16(ACE_CDR::Short value);
65  void write_uint16(ACE_CDR::UShort value);
66  void write_int32(ACE_CDR::Long value);
67  void write_uint32(ACE_CDR::ULong value);
68  void write_int64(ACE_CDR::LongLong value);
69  void write_uint64(ACE_CDR::ULongLong value);
70  void write_float32(ACE_CDR::Float value);
71  void write_float64(ACE_CDR::Double value);
73  void write_fixed(const OpenDDS::FaceTypes::Fixed& value);
74  void write_char8(ACE_CDR::Char value);
75  void write_char16(ACE_CDR::WChar value);
76  void write_string(const ACE_CDR::Char* value, size_t length);
77  void write_wstring(const ACE_CDR::WChar* value, size_t length);
78  void write_enum(const char* /*name*/, ACE_CDR::Long value);
79 
80  std::string str() const
81  {
82  return stream_.str();
83  }
84 
85 private:
86  std::string newline()
87  {
88  if (at_newline_) {
89  return "";
90  } else {
91  at_newline_ = false;
92  return "\n";
93  }
94  }
95 
96  const unsigned int indent_;
97  std::stringstream stream_;
98  unsigned int current_indent_;
100 };
101 
103 {
105 }
106 
108 {
110 }
111 
113 {
114  stream_ << newline() << std::string(current_indent_, ' ') << descriptor.name() << ": ";
115  at_newline_ = false;
116 }
117 
119 {}
120 
122 {
124 }
125 
127 {
129 }
130 
132 {
133  stream_ << newline() << std::string(current_indent_, ' ') << "$discriminator: ";
134  at_newline_ = false;
135 }
136 
138 {}
139 
141 {
142  stream_ << newline() << std::string(current_indent_, ' ') << name << ": ";
143  at_newline_ = false;
144 }
145 
147 {}
148 
150 {
152 }
153 
155 {
157 }
158 
160 {
162 }
163 
165 {
167 }
168 
170 {
171  stream_ << newline() << std::string(current_indent_, ' ') << '[' << idx << "]: ";
172  at_newline_ = false;
173 }
174 
176 {}
177 
179 {
180  stream_ << (value ? "true" : "false");
181 }
182 
184 {
185  stream_ << std::hex << "0x" << static_cast<unsigned int>(value) << std::dec;
186 }
187 
188 #if OPENDDS_HAS_EXPLICIT_INTS
189 
190 void PrinterValueWriter::write_int8(ACE_CDR::Int8 value)
191 {
192  stream_ << static_cast<int>(value);
193 }
194 
195 void PrinterValueWriter::write_uint8(ACE_CDR::UInt8 value)
196 {
197  stream_ << static_cast<unsigned int>(value);
198 }
199 #endif
200 
202 {
203  stream_ << value;
204 }
205 
207 {
208  stream_ << value;
209 }
210 
212 {
213  stream_ << value;
214 }
215 
217 {
218  stream_ << value;
219 }
220 
222 {
223  stream_ << value;
224 }
225 
227 {
228  stream_ << value;
229 }
230 
232 {
233  stream_ << value;
234 }
235 
237 {
238  stream_ << value;
239 }
240 
242 {
243  stream_ << value;
244 }
245 
246 void PrinterValueWriter::write_fixed(const OpenDDS::FaceTypes::Fixed& /*value*/)
247 {
248  // FUTURE
249  stream_ << "fixed";
250 }
251 
253 {
254  char_helper(stream_, value);
255 }
256 
258 {
259  char_helper(stream_, value);
260 }
261 
262 void PrinterValueWriter::write_string(const ACE_CDR::Char* value, size_t length)
263 {
264  string_helper(stream_, value, length);
265 }
266 
267 void PrinterValueWriter::write_wstring(const ACE_CDR::WChar* value, size_t length)
268 {
269  string_helper(stream_, value, length);
270 }
271 
273  ACE_CDR::Long value)
274 {
275  stream_ << name << " (" << value << ")";
276 }
277 
278 } // namespace DCPS
279 } // namespace OpenDDS
280 
282 
283 #endif /* OPENDDS_DCPS_PRINTER_VALUE_WRITER_H */
ACE_Byte Octet
ACE_INT64 LongLong
const LogLevel::Value value
Definition: debug.cpp:61
ACE_UINT64 ULongLong
void write_int16(ACE_CDR::Short value)
Convert values to a readable format.
void write_fixed(const OpenDDS::FaceTypes::Fixed &value)
void write_uint64(ACE_CDR::ULongLong value)
ACE_INT16 Short
void write_float32(ACE_CDR::Float value)
char Char
void write_float128(ACE_CDR::LongDouble value)
ACE_UINT16 UShort
void write_int64(ACE_CDR::LongLong value)
void write_char16(ACE_CDR::WChar value)
ACE_UINT32 ULong
const char *const name
Definition: debug.cpp:60
void write_float64(ACE_CDR::Double value)
void write_uint16(ACE_CDR::UShort value)
PrinterValueWriter(unsigned int a_indent=TheServiceParticipant->printer_value_writer_indent())
ACE_INT32 Long
void write_string(const ACE_CDR::Char *value, size_t length)
void write_wstring(const ACE_CDR::WChar *value, size_t length)
void begin_union_member(const char *name)
void begin_struct_member(const DDS::MemberDescriptor &)
std::ostream & string_helper(std::ostream &o, const CharType *value)
Definition: ValueHelper.h:108
ACE_INT8 Int8
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
void write_uint32(ACE_CDR::ULong value)
ACE_WCHAR_T WChar
public ObjectName name
void write_int32(ACE_CDR::Long value)
#define TheServiceParticipant
bool Boolean
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
void write_byte(ACE_CDR::Octet value)
ACE_UINT8 UInt8
void write_enum(const char *, ACE_CDR::Long value)
void write_char8(ACE_CDR::Char value)
std::ostream & char_helper(std::ostream &o, CharType value)
Definition: ValueHelper.h:77
void write_boolean(ACE_CDR::Boolean value)