Skip to content

Commit

Permalink
clang-format: re-apply autoformat
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasDebrunner committed Sep 25, 2023
1 parent f4f49e1 commit f26265f
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 184 deletions.
16 changes: 8 additions & 8 deletions ulog_cpp/data_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ void DataContainer::headerComplete()

// try to resolve all fields for all message infos
for (auto& it : _message_info) {
auto& message_info = it.second;
message_info.field().resolveDefinition(_message_formats, 0);
auto& message_info = it.second;
message_info.field().resolveDefinition(_message_formats, 0);
}

// try to resolve all fields for params
for (auto &it : _default_parameters) {
auto &parameter = it.second;
for (auto& it : _default_parameters) {
auto& parameter = it.second;
parameter.field().resolveDefinition(_message_formats, 0);
}

for (auto &it : _initial_parameters) {
auto &parameter = it.second;
parameter.field().resolveDefinition(_message_formats, 0);
for (auto& it : _initial_parameters) {
auto& parameter = it.second;
parameter.field().resolveDefinition(_message_formats, 0);
}

for (auto &parameter : _changed_parameters) {
for (auto& parameter : _changed_parameters) {
parameter.field().resolveDefinition(_message_formats, 0);
}

Expand Down
75 changes: 42 additions & 33 deletions ulog_cpp/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#include <cstring>
#include <limits>
#include <utility>
#include <memory>
#include <utility>

#define CHECK_MSG_SIZE(size, min_required) \
if ((size) < (min_required)) throw ParsingException("message too short")
Expand Down Expand Up @@ -106,27 +106,28 @@ Field::Field(const char* str, int len)
}
}

void Field::resolveDefinition(const std::map<std::string, std::shared_ptr<MessageFormat>>& existing_formats, int offset)
void Field::resolveDefinition(
const std::map<std::string, std::shared_ptr<MessageFormat>>& existing_formats, int offset)
{
// if this is already resolved, do nothing
if (definitionResolved()) {
return;
}
// if this is already resolved, do nothing
if (definitionResolved()) {
return;
}

_offset_in_message_bytes = offset;
// if this is a basic type, we are done
if (_type.type != Field::BasicType::NESTED) {
return;
}
_offset_in_message_bytes = offset;
// if this is a basic type, we are done
if (_type.type != Field::BasicType::NESTED) {
return;
}

auto it = existing_formats.find(_type.name);
if (it == existing_formats.end()) {
throw ParsingException("Message format not found: " + _type.name);
}
_type.nested_message = it->second;
// recursively resolve nested type
_type.nested_message->resolveDefinition(existing_formats);
_type.size = _type.nested_message->sizeBytes();
auto it = existing_formats.find(_type.name);
if (it == existing_formats.end()) {
throw ParsingException("Message format not found: " + _type.name);
}
_type.nested_message = it->second;
// recursively resolve nested type
_type.nested_message->resolveDefinition(existing_formats);
_type.size = _type.nested_message->sizeBytes();
}

void Field::resolveDefinition(int offset)
Expand All @@ -142,19 +143,25 @@ void Field::resolveDefinition(int offset)
}

const std::map<std::string, Field::TypeAttributes> Field::kBasicTypes{
{"int8_t", {"int8_t", Field::BasicType::INT8, 1}}, {"uint8_t", {"uint8_t", Field::BasicType::UINT8, 1}},
{"int16_t", {"int16_t", Field::BasicType::INT16, 2}}, {"uint16_t", {"uint16_t", Field::BasicType::UINT16, 2}},
{"int32_t", {"int32_t", Field::BasicType::INT32, 4}}, {"uint32_t", {"uint32_t", Field::BasicType::UINT32, 4}},
{"int64_t", {"int64_t", Field::BasicType::INT64, 8}}, {"uint64_t", {"uint64_t", Field::BasicType::UINT64, 8}},
{"float", {"float", Field::BasicType::FLOAT, 4}}, {"double", {"double", Field::BasicType::DOUBLE, 8}},
{"bool", {"bool", Field::BasicType::BOOL, 1}}, {"char", {"char", Field::BasicType::CHAR, 1}}};


int Field::sizeBytes() const {
{"int8_t", {"int8_t", Field::BasicType::INT8, 1}},
{"uint8_t", {"uint8_t", Field::BasicType::UINT8, 1}},
{"int16_t", {"int16_t", Field::BasicType::INT16, 2}},
{"uint16_t", {"uint16_t", Field::BasicType::UINT16, 2}},
{"int32_t", {"int32_t", Field::BasicType::INT32, 4}},
{"uint32_t", {"uint32_t", Field::BasicType::UINT32, 4}},
{"int64_t", {"int64_t", Field::BasicType::INT64, 8}},
{"uint64_t", {"uint64_t", Field::BasicType::UINT64, 8}},
{"float", {"float", Field::BasicType::FLOAT, 4}},
{"double", {"double", Field::BasicType::DOUBLE, 8}},
{"bool", {"bool", Field::BasicType::BOOL, 1}},
{"char", {"char", Field::BasicType::CHAR, 1}}};

int Field::sizeBytes() const
{
if (!definitionResolved()) {
throw ParsingException("Unresolved type " + _type.name);
}
return _type.size * ((_array_length == -1) ? 1: _array_length);
return _type.size * ((_array_length == -1) ? 1 : _array_length);
}

std::string Field::encode() const
Expand Down Expand Up @@ -234,7 +241,8 @@ Value::NativeTypeVariant Value::asNativeTypeVariant() const
if (_backing_ref.size() < _field_ref.arrayLength()) {
throw ParsingException("Decoding fault, memory too short");
}
return std::string(reinterpret_cast<const char *>(_backing_ref.data()), _field_ref.arrayLength());
return std::string(reinterpret_cast<const char*>(_backing_ref.data()),
_field_ref.arrayLength());
case Field::BasicType::NESTED:
throw ParsingException("Can't get nested field as basic type. Field " + _field_ref.name());
}
Expand Down Expand Up @@ -319,7 +327,7 @@ MessageFormat::MessageFormat(const uint8_t* msg)
format_str = format_str.substr(semicolon + 1);
}
}
MessageFormat::MessageFormat(std::string name, const std::vector<Field> &fields)
MessageFormat::MessageFormat(std::string name, const std::vector<Field>& fields)
: _name(std::move(name))
{
for (const auto& field : fields) {
Expand All @@ -332,13 +340,14 @@ MessageFormat::MessageFormat(std::string name, const std::vector<Field> &fields)
int MessageFormat::sizeBytes() const
{
int size = 0;
for (const auto &it : _fields) {
for (const auto& it : _fields) {
size += it.second->sizeBytes();
}
return size;
}

void MessageFormat::resolveDefinition(const std::map<std::string, std::shared_ptr<MessageFormat>>& existing_formats) const
void MessageFormat::resolveDefinition(
const std::map<std::string, std::shared_ptr<MessageFormat>>& existing_formats) const
{
int offset = 0;
for (const auto& field : _fields_ordered) {
Expand Down
Loading

0 comments on commit f26265f

Please sign in to comment.