Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address coverage and issues #622

Merged
merged 10 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/examples/rpp/doxygen/group_by.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ int main()
//! [group_by]
//
//! [group_by selector]
struct Person
struct person
{
std::string name;
int age;
};
rpp::source::just(Person{"Kate", 18},
Person{"Alex", 25},
Person{"Nick", 18},
Person{"Jack", 25},
Person{"Tom", 30},
Person{"Vanda", 18})
| rpp::operators::group_by([](const Person& v) { return v.age; }, [](const Person& v) { return v.name; })
rpp::source::just(person{"Kate", 18},
person{"Alex", 25},
person{"Nick", 18},
person{"Jack", 25},
person{"Tom", 30},
person{"Vanda", 18})
| rpp::operators::group_by([](const person& v) { return v.age; }, [](const person& v) { return v.name; })
| rpp::operators::subscribe([](auto grouped_observable) {
grouped_observable.subscribe([age = grouped_observable.get_key()](const std::string& name) {
std::cout << "Age [" << age << "] Name: " << name << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/examples/rpp/sfml/snake/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
static constexpr float s_gap_size = 1.0f;
static constexpr float s_cell_size = 10.0f;

sf::RectangleShape get_rectangle_at(Coordinates location, sf::Color color)
sf::RectangleShape get_rectangle_at(coordinates location, sf::Color color)
{
sf::RectangleShape box;
box.setSize(sf::Vector2f{s_cell_size, s_cell_size});
Expand Down
2 changes: 1 addition & 1 deletion src/examples/rpp/sfml/snake/canvas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

#include "snake.hpp"

sf::RectangleShape get_rectangle_at(Coordinates location, sf::Color color);
sf::RectangleShape get_rectangle_at(coordinates location, sf::Color color);
sf::Vector2u get_window_size(size_t rows_count, size_t cols_count);
6 changes: 3 additions & 3 deletions src/examples/rpp/sfml/snake/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static auto get_events_observable(sf::RenderWindow& window)
return res;

// indicate new frame
obs.on_next(PresentEvent{frame_number++});
obs.on_next(present_event{frame_number++});

while (window.pollEvent(ev))
obs.on_next(ev);
Expand All @@ -43,12 +43,12 @@ int main()

auto start = rpp::schedulers::clock_type::now();
size_t frames_delta = 0;
presents.subscribe([&window](const PresentEvent&) {
presents.subscribe([&window](const present_event&) {
window.display();
window.clear(sf::Color{0, 128, 0});
});

presents | rpp::ops::observe_on(rpp::schedulers::new_thread{}) | rpp::ops::subscribe([&start, &frames_delta](const PresentEvent& p) {
presents | rpp::ops::observe_on(rpp::schedulers::new_thread{}) | rpp::ops::subscribe([&start, &frames_delta](const present_event& p) {
const auto diff = p.frame_number - frames_delta;
if (diff > 50)
{
Expand Down
28 changes: 14 additions & 14 deletions src/examples/rpp/sfml/snake/snake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
static SnakeBody generate_initial_snake_body()
{
// tail to head
return SnakeBody{Coordinates{1, 1}, Coordinates{2, 1}, Coordinates{3, 1}, Coordinates{4, 1}};
return SnakeBody{coordinates{1, 1}, coordinates{2, 1}, coordinates{3, 1}, coordinates{4, 1}};
}

static Coordinates generate_initial_apple()
static coordinates generate_initial_apple()
{
return Coordinates{3, 5};
return coordinates{3, 5};
}

static int wrap_coordinate(int value, int max_value)
Expand Down Expand Up @@ -55,17 +55,17 @@ static bool is_snake_eat_self(const SnakeBody& body)
return std::find(body.cbegin(), body.cend() - 1, head) == body.cend() - 1;
}

static Coordinates update_apple_position_if_eat(Coordinates&& apple_position, const SnakeBody& snake)
static coordinates update_apple_position_if_eat(coordinates&& apple_position, const SnakeBody& snake)
{
if (std::find(snake.cbegin(), snake.cend(), apple_position) == snake.cend())
return apple_position;

static std::random_device rd;
static std::mt19937 rng(rd());
static std::uniform_int_distribution<int> x_uni(0, s_columns_count - 1);
static std::uniform_int_distribution<int> y_uni(0, s_rows_count - 1);
static std::random_device s_rd;
static std::mt19937 s_rng(s_rd());
static std::uniform_int_distribution<int> s_x_uni(0, s_columns_count - 1);
static std::uniform_int_distribution<int> s_y_uni(0, s_rows_count - 1);

return Coordinates{x_uni(rng), y_uni(rng)};
return coordinates{s_x_uni(s_rng), s_y_uni(s_rng)};
}

static Direction select_next_not_opposite_direction(Direction&& current_direction, const Direction& new_direction)
Expand Down Expand Up @@ -126,16 +126,16 @@ rpp::dynamic_observable<sf::RectangleShape> get_shapes_to_draw(const rpp::dynami
| rpp::ops::publish()
| rpp::ops::ref_count();

static constexpr size_t points_per_apple = 1;
static constexpr size_t s_points_per_apple = 1;
apple_position | rpp::ops::distinct_until_changed()
| rpp::ops::skip(1) // skip first apple position to avoid snake growing immediately
| rpp::ops::map([](const auto&) { return points_per_apple; })
| rpp::ops::map([](const auto&) { return s_points_per_apple; })
| rpp::ops::subscribe(snake_earn_points.get_observer());

auto drawable_objects = snake_body | rpp::ops::with_latest_from([](const SnakeBody& body, const Coordinates& apple_coords) {
auto drawable_objects = snake_body | rpp::ops::with_latest_from([](const SnakeBody& body, const coordinates& apple_coords) {
return rpp::source::from_iterable(body)
| rpp::ops::map([](const Coordinates& coords) { return get_rectangle_at(coords, sf::Color::White); })
| rpp::ops::merge_with(rpp::source::just(apple_coords) | rpp::ops::map([](const Coordinates& coords) {
| rpp::ops::map([](const coordinates& coords) { return get_rectangle_at(coords, sf::Color::White); })
| rpp::ops::merge_with(rpp::source::just(apple_coords) | rpp::ops::map([](const coordinates& coords) {
return get_rectangle_at(coords, sf::Color::Red);
}));
},
Expand Down
18 changes: 9 additions & 9 deletions src/examples/rpp/sfml/snake/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@
static constexpr size_t s_rows_count = 20;
static constexpr size_t s_columns_count = 30;

struct Coordinates
struct coordinates
{
int x{};
int y{};

bool operator==(const Coordinates& other) const = default;
bool operator!=(const Coordinates& other) const = default;
bool operator==(const coordinates& other) const = default;
bool operator!=(const coordinates& other) const = default;
};

using Direction = Coordinates;
using SnakeBody = std::vector<Coordinates>;
using Direction = coordinates;
using SnakeBody = std::vector<coordinates>;

inline rpp::schedulers::run_loop g_run_loop{};

struct PresentEvent
struct present_event
{
size_t frame_number{};
};

using CustomEvent = std::variant<PresentEvent, sf::Event>;
using CustomEvent = std::variant<present_event, sf::Event>;

auto get_presents_stream(const auto& events)
{
return events | rpp::ops::filter([](const CustomEvent& ev) { return std::holds_alternative<PresentEvent>(ev); })
| rpp::ops::map([](const CustomEvent& ev) { return std::get<PresentEvent>(ev); });
return events | rpp::ops::filter([](const CustomEvent& ev) { return std::holds_alternative<present_event>(ev); })
| rpp::ops::map([](const CustomEvent& ev) { return std::get<present_event>(ev); });
}
2 changes: 1 addition & 1 deletion src/examples/rppgrpc/doxygen/server_reactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* \example server_reactor.cpp
**/

class Server : public TestService::CallbackService
class server : public TestService::CallbackService
{

//! [read_reactor]
Expand Down
38 changes: 19 additions & 19 deletions src/extensions/rppgrpc/rppgrpc/details/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ namespace rppgrpc::details

void handle_write_done()
{
std::lock_guard lock{write_mutex};
write.pop_front();
std::lock_guard lock{m_write_mutex};
m_write.pop_front();

if (!write.empty())
if (!m_write.empty())
{
start_write(write.front());
start_write(m_write.front());
}
else if (finished)
else if (m_finished)
{
finish_writes(grpc::Status::OK);
}
Expand All @@ -70,26 +70,26 @@ namespace rppgrpc::details
template<rpp::constraint::decayed_same_as<TData> T>
void on_next(T&& message) const
{
std::lock_guard lock{owner.get().write_mutex};
owner.get().write.push_back(std::forward<T>(message));
if (owner.get().write.size() == 1)
owner.get().start_write(owner.get().write.front());
std::lock_guard lock{owner.get().m_write_mutex};
owner.get().m_write.push_back(std::forward<T>(message));
if (owner.get().m_write.size() == 1)
owner.get().start_write(owner.get().m_write.front());
}

void on_error(const std::exception_ptr&) const
{
std::lock_guard lock{owner.get().write_mutex};
owner.get().finished = true;
std::lock_guard lock{owner.get().m_write_mutex};
owner.get().m_finished = true;

if (owner.get().write.size() == 0)
if (owner.get().m_write.size() == 0)
owner.get().finish_writes(grpc::Status{grpc::StatusCode::INTERNAL, "Internal error happens"});
}
void on_completed() const
{
std::lock_guard lock{owner.get().write_mutex};
owner.get().finished = true;
std::lock_guard lock{owner.get().m_write_mutex};
owner.get().m_finished = true;

if (owner.get().write.size() == 0)
if (owner.get().m_write.size() == 0)
owner.get().finish_writes(grpc::Status::OK);
}

Expand All @@ -100,9 +100,9 @@ namespace rppgrpc::details
private:
rpp::subjects::serialized_publish_subject<TData> m_subject{};

std::mutex write_mutex{};
std::deque<TData> write{};
bool finished{};
std::mutex m_write_mutex{};
std::deque<TData> m_write{};
bool m_finished{};
};

template<rpp::constraint::decayed_type TData>
Expand Down Expand Up @@ -137,7 +137,7 @@ namespace rppgrpc::details

private:
rpp::subjects::publish_subject<TData> m_observer;
TData m_data{};
RPP_NO_UNIQUE_ADDRESS TData m_data{};
};

} // namespace rppgrpc::details
2 changes: 1 addition & 1 deletion src/extensions/rppqt/rppqt/schedulers/main_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace rppqt::schedulers
return;
}

QTimer::singleShot(std::chrono::duration_cast<std::chrono::milliseconds>(duration), application, [fn = std::forward<Fn>(fn), handler = std::forward<Handler>(handler), ... args = std::forward<Args>(args)]() mutable {
QTimer::singleShot(std::chrono::duration_cast<std::chrono::milliseconds>(std::max(rpp::schedulers::duration{}, duration)), application, [fn = std::forward<Fn>(fn), handler = std::forward<Handler>(handler), ... args = std::forward<Args>(args)]() mutable {
if (!handler.is_disposed())
invoke(std::move(fn), std::move(handler), std::move(args)...);
});
Expand Down
5 changes: 1 addition & 4 deletions src/rpp/rpp/defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
#define RPP_EMPTY_BASES
#endif

// MSVC has bad support for the no_unique_address from the box NOW, but provides specificator to enable full support. GCC/Clang works as expected
#if defined(_MSC_VER) && _MSC_FULL_VER >= 192829913
#define RPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
#elif defined(__APPLE__) && defined(__clang__) // apple works unexpectedly bad on clang 15 =C
#if defined(__APPLE__) && defined(__clang__) // apple works unexpectedly bad on clang 15 =C
#define RPP_NO_UNIQUE_ADDRESS
#else
#define RPP_NO_UNIQUE_ADDRESS [[no_unique_address]]
Expand Down
2 changes: 1 addition & 1 deletion src/rpp/rpp/disposables/callback_disposable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace rpp
void base_dispose_impl(interface_disposable::Mode) noexcept override { std::move(m_fn)(); } // NOLINT(bugprone-exception-escape)

private:
Fn m_fn;
RPP_NO_UNIQUE_ADDRESS Fn m_fn;
};

template<rpp::constraint::is_nothrow_invocable Fn>
Expand Down
2 changes: 1 addition & 1 deletion src/rpp/rpp/disposables/details/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace rpp::details::disposables

void dispose() const
{
for (auto& d : m_data)
for (const auto& d : m_data)
{
d.dispose();
}
Expand Down
4 changes: 2 additions & 2 deletions src/rpp/rpp/observables/connectable_observable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ namespace rpp
}

private:
OriginalObservable m_original_observable;
Subject m_subject;
RPP_NO_UNIQUE_ADDRESS OriginalObservable m_original_observable;
Subject m_subject;

struct state_t
{
Expand Down
2 changes: 1 addition & 1 deletion src/rpp/rpp/observers/dynamic_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace rpp::details::observers
}

private:
TObs m_observer;
RPP_NO_UNIQUE_ADDRESS TObs m_observer;
};

template<rpp::constraint::decayed_type Type>
Expand Down
8 changes: 4 additions & 4 deletions src/rpp/rpp/observers/mock_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class mock_observer_strategy final
{
public:
explicit mock_observer_strategy(bool copy_values = true)
: m_state{std::make_shared<State>(copy_values)}
: m_state{std::make_shared<state>(copy_values)}
{
}

Expand Down Expand Up @@ -57,9 +57,9 @@ class mock_observer_strategy final
auto get_observer(rpp::composite_disposable_wrapper d) const { return rpp::observer_with_disposable<Type, mock_observer_strategy<Type>>{std::move(d), *this}; }

private:
struct State
struct state
{
explicit State(bool copy_values)
explicit state(bool copy_values)
: m_copy_values{copy_values}
{
}
Expand All @@ -73,5 +73,5 @@ class mock_observer_strategy final
std::vector<Type> vals{};
};

std::shared_ptr<State> m_state{};
std::shared_ptr<state> m_state{};
};
2 changes: 1 addition & 1 deletion src/rpp/rpp/operators/concat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace rpp::operators::details
template<rpp::constraint::observable TObservable, rpp::constraint::observer TObserver>
struct concat_inner_observer_strategy;

enum ConcatStage : uint8_t
enum class ConcatStage : uint8_t
{
None = 0,
Draining = 1,
Expand Down
6 changes: 3 additions & 3 deletions src/rpp/rpp/operators/delay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ namespace rpp::operators::details
}
}

Observer observer;
RPP_NO_UNIQUE_ADDRESS Worker worker;
rpp::schedulers::duration delay;
RPP_NO_UNIQUE_ADDRESS Observer observer;
RPP_NO_UNIQUE_ADDRESS Worker worker;
rpp::schedulers::duration delay;

std::mutex mutex{};
std::queue<emission<T>> queue;
Expand Down
Loading
Loading