Skip to content

Commit

Permalink
read-api: Attempt to make clang-tidy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasDebrunner committed Sep 26, 2023
1 parent d63af38 commit 589512f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
15 changes: 7 additions & 8 deletions examples/ulog_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <string>
#include <ulog_cpp/data_container.hpp>
#include <ulog_cpp/reader.hpp>
#include <variant>

int main(int argc, char** argv)
{
Expand Down Expand Up @@ -47,19 +46,19 @@ int main(int argc, char** argv)

// List all subscription names
for (const auto& sub : data_container->subscriptionNames()) {
std::cout << sub << std::endl;
std::cout << sub << "\n";
}

// Get a particular subscription
const auto& subscription = data_container->subscription("vehicle_status");

// Get message format of subscription
auto message_format = subscription->format();
std::cout << "Message format: " << message_format->name() << std::endl;
std::cout << "Message format: " << message_format->name() << "\n";

// List all field names
for (const std::string& field : subscription->fieldNames()) {
std::cout << field << std::endl;
std::cout << field << "\n";
}

// Get particular field
Expand All @@ -71,7 +70,7 @@ int main(int argc, char** argv)
// gets cast to the value you put in int.
// This also works for arrays and strings.
auto nav_state = sample[nav_state_field].as<int>();
std::cout << nav_state << std::endl;
std::cout << nav_state << "\n";
}

// get a specific sample
Expand All @@ -80,18 +79,18 @@ int main(int argc, char** argv)
// access values by name
auto timestamp = sample_12["timestamp"].as<uint64_t>();

std::cout << timestamp << std::endl;
std::cout << timestamp << "\n";

// get from nested data type
auto esc_format =
data_container->messageFormats().at("esc_status")->field("esc")->type().nested_message;
for (const auto& field_name : esc_format->fieldNames()) {
std::cout << field_name << std::endl;
std::cout << field_name << "\n";
}

auto esc_status = data_container->subscription("esc_status");
for (const auto& sample : *esc_status) {
std::cout << "timestamp: " << sample["esc"][7]["esc_power"].as<int>() << std::endl;
std::cout << "timestamp: " << sample["esc"][7]["esc_power"].as<int>() << "\n";
}
return 0;
}
1 change: 0 additions & 1 deletion examples/ulog_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
****************************************************************************/

#include <chrono>
#include <cstdint>
#include <string>
#include <thread>
#include <ulog_cpp/simple_writer.hpp>
Expand Down
2 changes: 1 addition & 1 deletion ulog_cpp/data_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DataContainer : public DataHandlerInterface {

NameAndMultiIdKey() = default;

NameAndMultiIdKey(const std::string& name, int multi_id) : name(name), multi_id(multi_id) {}
NameAndMultiIdKey(std::string name, int multi_id) : name(std::move(name)), multi_id(multi_id) {}

bool operator==(const NameAndMultiIdKey& other) const
{
Expand Down
10 changes: 5 additions & 5 deletions ulog_cpp/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class Field {

TypeAttributes() = default;

TypeAttributes(std::string name, BasicType type_, int size_)
: name(std::move(name)), type(type_), size(size_), nested_message(nullptr)
TypeAttributes(std::string name, BasicType type, int size)
: name(std::move(name)), type(type), size(size), nested_message(nullptr)
{
}
};
Expand Down Expand Up @@ -146,14 +146,14 @@ class Value {
std::vector<float>, std::vector<double>, std::vector<bool>, std::string>;

template <typename T>
struct is_vector : std::false_type {
struct is_vector : std::false_type { // NOLINT(*-identifier-naming)
};
template <typename T>
struct is_vector<std::vector<T>> : std::true_type {
};

template <typename T>
struct is_string : std::is_same<std::decay_t<T>, std::string> {
struct is_string : std::is_same<std::decay_t<T>, std::string> { // NOLINT(*-identifier-naming)
};

Value(const Field& field_ref, const std::vector<uint8_t>::const_iterator& backing_ref_begin,
Expand Down Expand Up @@ -247,7 +247,7 @@ class Value {
backing_end - backing_start - total_offset < static_cast<int64_t>(sizeof(v))) {
throw ParsingException("Unexpected data type size");
}
std::copy(backing_start + total_offset, backing_start + total_offset + sizeof(v), (uint8_t*)&v);
std::copy(backing_start + total_offset, backing_start + total_offset + sizeof(v), reinterpret_cast<uint8_t*>(&v));
return v;
}

Expand Down
18 changes: 9 additions & 9 deletions ulog_cpp/subscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ template <typename base_iterator_type>
class SubscriptionIterator {
public:
SubscriptionIterator(const base_iterator_type& it,
const std::shared_ptr<MessageFormat>& message_format)
: _it(it), _message_format(message_format)
std::shared_ptr<MessageFormat> message_format)
: _it(it), _message_format(std::move(message_format))
{
}

using iterator_category = std::random_access_iterator_tag;
using value_type = TypedDataView;
using difference_type = std::ptrdiff_t;
using pointer = TypedDataView*;
using reference = TypedDataView&;
using iterator_category = std::random_access_iterator_tag; // NOLINT(*-identifier-naming)
using value_type = TypedDataView; // NOLINT(*-identifier-naming)
using difference_type = std::ptrdiff_t; // NOLINT(*-identifier-naming)
using Pointer = TypedDataView*; // NOLINT(*-identifier-naming)
using reference = TypedDataView&; // NOLINT(*-identifier-naming)

TypedDataView operator*() { return TypedDataView(*_it, *_message_format); }

const TypedDataView operator*() const { return TypedDataView(*_it, *_message_format); }
TypedDataView operator*() const { return TypedDataView(*_it, *_message_format); }

SubscriptionIterator& operator++()
{
Expand Down Expand Up @@ -146,7 +146,7 @@ class Subscription {
Subscription(AddLoggedMessage add_logged_message, std::vector<Data> samples,
std::shared_ptr<MessageFormat> message_format)
: _add_logged_message(std::move(add_logged_message)),
_message_format(message_format),
_message_format(std::move(message_format)),
_samples(std::move(samples))
{
}
Expand Down

0 comments on commit 589512f

Please sign in to comment.