36 #ifndef RC_DYNAMICS_API_CSV_PRINTING_H_H 37 #define RC_DYNAMICS_API_CSV_PRINTING_H_H 47 #include "roboception/msgs/frame.pb.h" 48 #include "roboception/msgs/dynamics.pb.h" 49 #include "roboception/msgs/imu.pb.h" 67 static Header prefixed(
const std::string& p, const ::google::protobuf::Message& m)
76 fields_.insert(std::end(fields_), prefix_ + field);
83 fields_.insert(std::end(fields_), prefix_ + f);
89 using namespace ::google::protobuf;
91 auto descr = m.GetDescriptor();
92 auto refl = m.GetReflection();
93 for (
int i = 0; i < descr->field_count(); ++i)
95 auto field = descr->field(i);
97 if (field->is_repeated())
99 int size = refl->FieldSize(m, field);
100 if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE)
102 for (
int k = 0; k < size; k++)
104 *
this <<
prefixed(field->name() +
'_' + std::to_string(k), refl->GetMessage(m, field));
109 for (
int k = 0; k < size; k++)
111 *
this << field->name() +
"_" + std::to_string(k);
115 else if (!field->is_optional() || refl->HasField(m, field))
117 if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE)
119 *
this <<
prefixed(field->name() +
'_', refl->GetMessage(m, field));
123 *
this << field->name();
141 this->entries_.insert(std::end(this->entries_), t);
147 using namespace ::google::protobuf;
149 auto descr = m.GetDescriptor();
150 auto refl = m.GetReflection();
151 for (
int i = 0; i < descr->field_count(); ++i)
153 auto field = descr->field(i);
155 if (field->is_repeated())
157 int size = refl->FieldSize(m, field);
158 switch (field->cpp_type())
160 case FieldDescriptor::CPPTYPE_MESSAGE:
161 for (
int k = 0; k < size; ++k)
163 *
this << refl->GetRepeatedMessage(m, field, k);
166 case FieldDescriptor::CPPTYPE_BOOL:
167 for (
int k = 0; k < size; ++k)
169 *
this << std::to_string(refl->GetRepeatedBool(m, field, k));
172 case FieldDescriptor::CPPTYPE_ENUM:
173 for (
int k = 0; k < size; ++k)
175 *
this << refl->GetRepeatedEnum(m, field, k)->name();
178 case FieldDescriptor::CPPTYPE_FLOAT:
179 for (
int k = 0; k < size; ++k)
181 *
this << std::to_string(refl->GetRepeatedFloat(m, field, k));
184 case FieldDescriptor::CPPTYPE_DOUBLE:
185 for (
int k = 0; k < size; ++k)
187 *
this << std::to_string(refl->GetRepeatedDouble(m, field, k));
190 case FieldDescriptor::CPPTYPE_UINT32:
191 for (
int k = 0; k < size; ++k)
193 *
this << std::to_string(refl->GetRepeatedUInt32(m, field, k));
196 case FieldDescriptor::CPPTYPE_UINT64:
197 for (
int k = 0; k < size; ++k)
199 *
this << std::to_string(refl->GetRepeatedUInt64(m, field, k));
202 case FieldDescriptor::CPPTYPE_INT32:
203 for (
int k = 0; k < size; ++k)
205 *
this << std::to_string(refl->GetRepeatedInt32(m, field, k));
208 case FieldDescriptor::CPPTYPE_INT64:
209 for (
int k = 0; k < size; ++k)
211 *
this << std::to_string(refl->GetRepeatedInt64(m, field, k));
214 case FieldDescriptor::CPPTYPE_STRING:
215 for (
int k = 0; k < size; ++k)
217 *
this << refl->GetRepeatedString(m, field, k);
222 else if (!field->is_optional() || refl->HasField(m, field))
224 switch (field->cpp_type())
226 case FieldDescriptor::CPPTYPE_MESSAGE:
227 *
this << refl->GetMessage(m, field);
229 case FieldDescriptor::CPPTYPE_BOOL:
230 *
this << std::to_string(refl->GetBool(m, field));
232 case FieldDescriptor::CPPTYPE_ENUM:
233 *
this << refl->GetEnum(m, field)->name();
235 case FieldDescriptor::CPPTYPE_FLOAT:
236 *
this << std::to_string(refl->GetFloat(m, field));
238 case FieldDescriptor::CPPTYPE_DOUBLE:
239 *
this << std::to_string(refl->GetDouble(m, field));
241 case FieldDescriptor::CPPTYPE_UINT32:
242 *
this << std::to_string(refl->GetUInt32(m, field));
244 case FieldDescriptor::CPPTYPE_UINT64:
245 *
this << std::to_string(refl->GetUInt64(m, field));
247 case FieldDescriptor::CPPTYPE_INT32:
248 *
this << std::to_string(refl->GetInt32(m, field));
250 case FieldDescriptor::CPPTYPE_INT64:
251 *
this << std::to_string(refl->GetInt64(m, field));
253 case FieldDescriptor::CPPTYPE_STRING:
254 *
this << refl->GetString(m, field);
268 for (
auto&& hf : header.
fields_)
298 #endif // RC_DYNAMICS_API_CSV_PRINTING_H_H Line & operator<<(const ::google::protobuf::Message &m)
std::vector< std::string > entries_
Line & operator<<(const std::string &t)
struct and methods to "organice" printing of csv-Lines