Skip to content

Commit

Permalink
clang tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
tanneberger committed Jan 21, 2025
1 parent 8410802 commit b214e17
Show file tree
Hide file tree
Showing 28 changed files with 80 additions and 100 deletions.
2 changes: 1 addition & 1 deletion examples/count/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using namespace reactor;
using namespace std::chrono_literals;

class Count : public Reactor {
class Count final : public Reactor {
private:
// actions
Timer timer{"timer", this};
Expand Down
2 changes: 1 addition & 1 deletion examples/hello/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using namespace reactor;
using namespace std::chrono_literals;

class Hello : public Reactor {
class Hello final : public Reactor {
private:
// actions
Timer timer{"timer", this, 1s, 2s};
Expand Down
6 changes: 3 additions & 3 deletions examples/multiport_mutation/consumer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Tassilo Tanneberger
*/

#ifndef CONSUMER_HH // NOLINT
#define CONSUMER_HH // NOLINT
#ifndef MULTIPORT_MUTATION_CONSUMER_HH
#define MULTIPORT_MUTATION_CONSUMER_HH

#include <reactor-cpp/reactor-cpp.hh>
#include <reactor-cpp/scopes.hh>
Expand Down Expand Up @@ -45,4 +45,4 @@ public:
void assemble() override { handle.declare_trigger(&in); }
};

#endif // CONSUMER_HH
#endif // MULTIPORT_MUTATION_CONSUMER_HH
4 changes: 2 additions & 2 deletions examples/multiport_mutation/load_balancer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Tassilo Tanneberger
*/

#ifndef MULTIPORT_MUTATION_LOAD_BALANCER_HH // NOLINT
#define MULTIPORT_MUTATION_LOAD_BALANCER_HH // NOLINT
#ifndef MULTIPORT_MUTATION_LOAD_BALANCER_HH
#define MULTIPORT_MUTATION_LOAD_BALANCER_HH

#include <reactor-cpp/mutations/multiport.hh>
#include <reactor-cpp/reactor-cpp.hh>
Expand Down
6 changes: 3 additions & 3 deletions examples/multiport_mutation/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Deployment final : public Reactor { // NOLINT
int state = 0;

public:
Inner(Reactor* reactor)
explicit Inner(Reactor* reactor)
: MutableScope(reactor) {}
void reaction_1(const Input<unsigned>& scale, std::vector<std::unique_ptr<Consumer>>& reactor_bank,
ModifableMultiport<Output<unsigned>>& load_balancer) {
Expand All @@ -41,8 +41,8 @@ class Deployment final : public Reactor { // NOLINT
};

std::function get_input_port = [](const std::unique_ptr<Consumer>& consumer) { return &consumer->in; };
auto rescale = std::make_shared<ResizeMultiportToBank<unsigned, Consumer>>(&load_balancer, &reactor_bank,
get_input_port, lambda, new_size);
const auto rescale = std::make_shared<ResizeMultiportToBank<unsigned, Consumer>>(
&load_balancer, &reactor_bank, get_input_port, lambda, new_size);

add_to_transaction(rescale);

Expand Down
4 changes: 2 additions & 2 deletions examples/multiport_mutation/producer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Tassilo Tanneberger
*/

#ifndef MULTIPORT_MUTATION_PRODUCER_HH // NOLINT
#define MULTIPORT_MUTATION_PRODUCER_HH // NOLINT
#ifndef MULTIPORT_MUTATION_PRODUCER_HH
#define MULTIPORT_MUTATION_PRODUCER_HH

#include <reactor-cpp/reactor-cpp.hh>

Expand Down
10 changes: 5 additions & 5 deletions examples/ports/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using namespace reactor;
using namespace std::chrono_literals;

class Trigger : public Reactor {
class Trigger final : public Reactor {
private:
Timer timer;
Reaction r_timer{"r_timer", 1, this, [this]() { on_timer(); }};
Expand All @@ -25,7 +25,7 @@ class Trigger : public Reactor {
void on_timer() { trigger.set(); }
};

class Counter : public Reactor {
class Counter final : public Reactor {
private:
int value_{0};
Reaction r_trigger{"r_trigger", 1, this, [this]() { on_trigger(); }};
Expand All @@ -49,7 +49,7 @@ class Counter : public Reactor {
}
};

class Printer : public Reactor {
class Printer final : public Reactor {
private:
Reaction r_value{"r_value", 1, this, [this]() { on_value(); }};

Expand All @@ -64,10 +64,10 @@ class Printer : public Reactor {
r_value.declare_trigger(&value);
}

void on_value() { std::cout << this->name() << ": " << *value.get() << '\n'; }
void on_value() const { std::cout << this->name() << ": " << *value.get() << '\n'; }
};

class Adder : public Reactor {
class Adder final : public Reactor {
private:
Reaction r_add{"r_add", 1, this, [this]() { add(); }};

Expand Down
12 changes: 6 additions & 6 deletions examples/power_train/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using namespace reactor;

class LeftPedal : public Reactor {
class LeftPedal final : public Reactor {
public:
// ports
Output<void> angle{"angle", this}; // NOLINT
Expand All @@ -30,7 +30,7 @@ class LeftPedal : public Reactor {
}
};

class RightPedal : public Reactor {
class RightPedal final : public Reactor {
public:
// ports
Output<void> angle{"angle", this}; // NOLINT
Expand Down Expand Up @@ -60,7 +60,7 @@ class RightPedal : public Reactor {
}
};

class BrakeControl : public Reactor {
class BrakeControl final : public Reactor {
public:
// ports
Input<void> angle{"angle", this}; // NOLINT
Expand All @@ -81,7 +81,7 @@ class BrakeControl : public Reactor {
}
};

class EngineControl : public Reactor {
class EngineControl final : public Reactor {
public:
// ports
Input<void> angle{"angle", this}; // NOLINT
Expand Down Expand Up @@ -118,7 +118,7 @@ class EngineControl : public Reactor {
}
};

class Brake : public Reactor {
class Brake final : public Reactor {
public:
// ports
Input<void> force{"force", this}; // NOLINT
Expand All @@ -136,7 +136,7 @@ class Brake : public Reactor {
void assemble() override { r1.declare_trigger(&force); }
};

class Engine : public Reactor {
class Engine final : public Reactor {
public:
// ports
Input<void> torque{"torque", this}; // NOLINT
Expand Down
7 changes: 3 additions & 4 deletions include/reactor-cpp/assert.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "reactor-cpp/fwd.hh"

#include <cassert>
#include <sstream>
#include <stdexcept>
#include <string>

Expand Down Expand Up @@ -71,7 +70,7 @@ public:
: std::runtime_error(build_message(msg)) {}
};

constexpr void validate([[maybe_unused]] bool condition, [[maybe_unused]] const std::string_view message) {
constexpr void validate([[maybe_unused]] const bool condition, [[maybe_unused]] const std::string_view message) {
if constexpr (runtime_validation) {
if (!condition) {
print_backtrace();
Expand All @@ -80,8 +79,8 @@ constexpr void validate([[maybe_unused]] bool condition, [[maybe_unused]] const
}
}

template <typename E> constexpr auto extract_value(E enum_value) -> typename std::underlying_type_t<E> {
return static_cast<typename std::underlying_type_t<E>>(enum_value);
template <typename E> constexpr auto extract_value(E enum_value) -> std::underlying_type_t<E> {
return static_cast<std::underlying_type_t<E>>(enum_value);
}

void assert_phase([[maybe_unused]] const ReactorElement* ptr, [[maybe_unused]] Phase phase);
Expand Down
7 changes: 3 additions & 4 deletions include/reactor-cpp/connection.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "logical_time.hh"
#include "port.hh"
#include "reaction.hh"
#include "reactor.hh"
#include "time.hh"
#include "time_barrier.hh"

Expand Down Expand Up @@ -69,7 +68,7 @@ protected:
return [this](const BasePort& port) {
// We know that port must be of type Port<T>
auto& typed_port = reinterpret_cast<const Port<T>&>(port); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
if constexpr (std::is_same<T, void>::value) {
if constexpr (std::is_same_v<T, void>) {
this->schedule();
} else {
this->schedule(std::move(typed_port.get()));
Expand All @@ -81,7 +80,7 @@ public:
void setup() noexcept override {
Action<T>::setup();

if constexpr (std::is_same<T, void>::value) {
if constexpr (std::is_same_v<T, void>) {
for (auto port : this->downstream_ports()) {
port->set();
}
Expand Down Expand Up @@ -134,7 +133,7 @@ public:
// without locking.
auto tag = Tag::from_logical_time(scheduler->logical_time());
[[maybe_unused]] bool result{false};
if constexpr (std::is_same<T, void>::value) {
if constexpr (std::is_same_v<T, void>) {
result = this->schedule_at(tag);
} else {
result = this->schedule_at(std::move(typed_port.get()), tag);
Expand Down
4 changes: 1 addition & 3 deletions include/reactor-cpp/logging.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
#define REACTOR_CPP_LOGGING_HH

#include "reactor-cpp/config.hh"
#include "reactor-cpp/time.hh"
#include <chrono>

#include <iostream>
#include <memory>
#include <mutex>
#include <string>
#include <utility>

namespace reactor::log {

Expand Down
8 changes: 4 additions & 4 deletions include/reactor-cpp/multiport.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace reactor {

class BaseMultiport { // NOLINT cppcoreguidelines-special-member-functions,-warnings-as-errors
protected:
std::atomic<std::size_t> size_{0};
std::vector<std::size_t> present_ports_{};
std::atomic<std::size_t> size_{0}; // NOLINT cppcoreguidelines-non-private-member-variables-in-classes
std::vector<std::size_t> present_ports_{}; // NOLINT cppcoreguidelines-non-private-member-variables-in-classes

private:
std::string name_{};
Expand Down Expand Up @@ -53,11 +53,11 @@ protected:
public:
BaseMultiport(std::string name, Reactor* container)
: name_(std::move(name))
, container_(container) {};
, container_(container) {}
~BaseMultiport() = default;

[[nodiscard]] auto name() const noexcept -> const std::string& { return name_; }
auto container() const noexcept -> Reactor* { return container_; }
[[nodiscard]] auto container() const noexcept -> Reactor* { return container_; }
};

template <class T, class A = std::allocator<T>>
Expand Down
2 changes: 0 additions & 2 deletions include/reactor-cpp/mutations/multiport.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#ifndef REACTOR_CPP_MUTATIONS_MULTIPORT_HH
#define REACTOR_CPP_MUTATIONS_MULTIPORT_HH

#include <vector>

#include "../multiport.hh"
#include "../mutations.hh"
#include "../port.hh"
Expand Down
2 changes: 1 addition & 1 deletion include/reactor-cpp/reaction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public:

void startup() final {}
void shutdown() final {}
void trigger();
void trigger() const;
void set_index(unsigned index);

template <class Dur> void set_deadline(Dur deadline, const std::function<void(void)>& handler) {
Expand Down
1 change: 0 additions & 1 deletion include/reactor-cpp/reactor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define REACTOR_CPP_REACTOR_HH

#include <set>
#include <sstream>
#include <string>

#include "action.hh"
Expand Down
2 changes: 0 additions & 2 deletions include/reactor-cpp/reactor_element.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#define REACTOR_CPP_REACTOR_ELEMENT_HH

#include <cstdint>
#include <memory>
#include <set>
#include <sstream>
#include <string>

Expand Down
1 change: 0 additions & 1 deletion include/reactor-cpp/semaphore.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#ifndef REACTOR_CPP_SEMAPHORE_HH
#define REACTOR_CPP_SEMAPHORE_HH

#include <atomic>
#include <condition_variable>
#include <mutex>

Expand Down
5 changes: 2 additions & 3 deletions include/reactor-cpp/statistics.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include <atomic>

#include "reactor-cpp/config.hh"
#include "reactor-cpp/logging.hh"

namespace reactor {
Expand All @@ -23,7 +22,7 @@ private:
#else
constexpr static bool enabled_{false};
#endif
// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
// NOLINT BEGIN(cppcoreguidelines-avoid-non-const-global-variables)
inline static std::atomic_size_t reactor_instances_{0};
inline static std::atomic_size_t connections_{0};
inline static std::atomic_size_t reactions_{0};
Expand All @@ -34,7 +33,7 @@ private:
inline static std::atomic_size_t triggered_actions_{0};
inline static std::atomic_size_t set_ports_{0};
inline static std::atomic_size_t scheduled_actions_{0};
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
// NOLINT END(cppcoreguidelines-avoid-non-const-global-variables)

static void increment(std::atomic_size_t& counter) {
if constexpr (enabled_) {
Expand Down
1 change: 0 additions & 1 deletion include/reactor-cpp/time_barrier.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#ifndef REACTOR_CPP_TIME_BARRIER_HH
#define REACTOR_CPP_TIME_BARRIER_HH

#include "fwd.hh"
#include "logical_time.hh"
#include "scheduler.hh"
#include "time.hh"
Expand Down
7 changes: 2 additions & 5 deletions include/reactor-cpp/value_ptr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include <memory>
#include <type_traits>

#include "reactor-cpp/logging.hh"

namespace reactor {

namespace detail {
Expand Down Expand Up @@ -459,16 +457,15 @@ public:
// get_mutable_copy()
friend class ImmutableValuePtr<T, true>;

// Give the factory function make_mutable_value() access to the private
// constructor
// Give the factory function make_mutable_value() access to the private constructor
template <class U, class... Args>
friend auto reactor::make_mutable_value(Args&&... args) -> reactor::MutableValuePtr<U>;
};

template <class T> class ImmutableValuePtr<T, true> {
public:
/// A type alias that adds ``const`` to ``T``
using const_T = typename std::add_const_t<T>;
using const_T = std::add_const_t<T>;

private:
T value_{};
Expand Down
Loading

0 comments on commit b214e17

Please sign in to comment.