Skip to content

Commit

Permalink
fix(server): replace reference data members with pointers
Browse files Browse the repository at this point in the history
Clang-tidy 16 implements a check for C++ Core Guidelines C.12. [1] That
requires data members to not be references.

[1] https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-constref
  • Loading branch information
romangg committed Sep 11, 2023
1 parent eb698bb commit 7af472b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
14 changes: 7 additions & 7 deletions server/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ output_transform transform_to_output(wl_output_transform transform)
}

output::Private::Private(output_metadata metadata, output_manager& manager, output* q_ptr)
: manager{manager}
: manager{&manager}
, q_ptr{q_ptr}
{
if (metadata.description.empty()) {
Expand All @@ -93,24 +93,24 @@ output::Private::Private(output_metadata metadata, output_manager& manager, outp
published.meta = pending.meta;

manager.outputs.push_back(q_ptr);
QObject::connect(&manager.display, &Display::destroyed, q_ptr, [this] {
QObject::connect(manager.display, &Display::destroyed, q_ptr, [this] {
xdg_output.reset();
wayland_output.reset();
});
}

output::Private::~Private()
{
remove_all(manager.outputs, q_ptr);
remove_all(manager->outputs, q_ptr);
}

void output::Private::done()
{
if (published.state.enabled != pending.state.enabled) {
if (pending.state.enabled) {
wayland_output.reset(new WlOutput(q_ptr, &manager.display));
if (manager.xdg_manager) {
xdg_output.reset(new XdgOutput(q_ptr, &manager.display));
wayland_output.reset(new WlOutput(q_ptr, manager->display));
if (manager->xdg_manager) {
xdg_output.reset(new XdgOutput(q_ptr, manager->display));
}
} else {
wayland_output.reset();
Expand All @@ -127,7 +127,7 @@ void output::Private::done()
}
}
}
if (auto& wlr_man = manager.wlr_manager_v1) {
if (auto& wlr_man = manager->wlr_manager_v1) {
if (wlr_head_v1) {
wlr_head_v1->broadcast();
} else {
Expand Down
6 changes: 3 additions & 3 deletions server/output_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Wrapland::Server
{

output_manager::output_manager(Display& display)
: display{display}
: display{&display}
{
}

Expand All @@ -36,14 +36,14 @@ void output_manager::commit_changes() const
XdgOutputManager& output_manager::create_xdg_manager()
{
assert(!xdg_manager);
xdg_manager = std::make_unique<XdgOutputManager>(&display);
xdg_manager = std::make_unique<XdgOutputManager>(display);
return *xdg_manager;
}

wlr_output_manager_v1& output_manager::create_wlr_manager_v1()
{
assert(!wlr_manager_v1);
wlr_manager_v1 = std::make_unique<wlr_output_manager_v1>(&display);
wlr_manager_v1 = std::make_unique<wlr_output_manager_v1>(display);
return *wlr_manager_v1;
}

Expand Down
2 changes: 1 addition & 1 deletion server/output_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class WRAPLANDSERVER_EXPORT output_manager
XdgOutputManager& create_xdg_manager();
wlr_output_manager_v1& create_wlr_manager_v1();

Display& display;
Display* display;
std::vector<output*> outputs;

std::unique_ptr<XdgOutputManager> xdg_manager;
Expand Down
2 changes: 1 addition & 1 deletion server/output_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class output::Private

static int32_t get_mode_flags(output_mode const& mode, output_state const& state);

output_manager& manager;
output_manager* manager;

int connector_id{0};
std::vector<output_mode> modes;
Expand Down
4 changes: 2 additions & 2 deletions server/wlr_output_configuration_head_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ wlr_output_configuration_head_v1::Private::Private(Client* client,
&zwlr_output_configuration_head_v1_interface,
&s_interface,
&q_ptr)
, state{head.d_ptr->head->output.d_ptr->published.state}
, state{head.d_ptr->head->output->d_ptr->published.state}
, scale{estimate_scale(state)}
, head{&head}
{
Expand Down Expand Up @@ -156,7 +156,7 @@ wlr_output_configuration_head_v1::~wlr_output_configuration_head_v1() = default;

output& wlr_output_configuration_head_v1::get_output() const
{
return d_ptr->head->d_ptr->head->output;
return *d_ptr->head->d_ptr->head->output;
}

output_state const& wlr_output_configuration_head_v1::get_state() const
Expand Down
30 changes: 15 additions & 15 deletions server/wlr_output_head_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ double estimate_scale(output_state const& data)
}

wlr_output_head_v1::wlr_output_head_v1(Server::output& output, wlr_output_manager_v1& manager)
: output{output}
, manager{manager}
: output{&output}
, manager{&manager}
{
manager.d_ptr->add_head(*this);
}
Expand All @@ -40,8 +40,8 @@ wlr_output_head_v1::~wlr_output_head_v1()
res->d_ptr->head = nullptr;
}

manager.d_ptr->changed = true;
remove_all(manager.d_ptr->heads, this);
manager->d_ptr->changed = true;
remove_all(manager->d_ptr->heads, this);
}

wlr_output_head_v1_res* wlr_output_head_v1::add_bind(wlr_output_manager_v1_bind& bind)
Expand All @@ -50,27 +50,27 @@ wlr_output_head_v1_res* wlr_output_head_v1::add_bind(wlr_output_manager_v1_bind&
bind.send<zwlr_output_manager_v1_send_head>(res->d_ptr->resource);
resources.push_back(res);

res->send_static_data(output.d_ptr->pending.meta);
res->send_static_data(output->d_ptr->pending.meta);

for (auto&& mode : output.d_ptr->modes) {
for (auto&& mode : output->d_ptr->modes) {
res->add_mode(*new wlr_output_mode_v1(bind.client->handle, bind.version, mode));
}

res->send_mutable_data(output.d_ptr->pending.state);
res->send_mutable_data(output->d_ptr->pending.state);

return res;
}

void wlr_output_head_v1::broadcast()
{
auto const published = output.d_ptr->published;
auto const pending = output.d_ptr->pending;
auto const published = output->d_ptr->published;
auto const pending = output->d_ptr->pending;

if (published.state.enabled != pending.state.enabled) {
for (auto res : resources) {
res->send_enabled(pending.state.enabled);
}
manager.d_ptr->changed = true;
manager->d_ptr->changed = true;
}

if (!pending.state.enabled) {
Expand All @@ -82,22 +82,22 @@ void wlr_output_head_v1::broadcast()
for (auto res : resources) {
res->send_current_mode(pending.state.mode);
}
manager.d_ptr->changed = true;
manager->d_ptr->changed = true;
}

if (published.state.geometry.topLeft() != pending.state.geometry.topLeft()
|| !published.state.enabled) {
for (auto res : resources) {
res->send_position(pending.state.geometry.topLeft().toPoint());
}
manager.d_ptr->changed = true;
manager->d_ptr->changed = true;
}

if (published.state.transform != pending.state.transform || !published.state.enabled) {
for (auto res : resources) {
res->send_transform(pending.state.transform);
}
manager.d_ptr->changed = true;
manager->d_ptr->changed = true;
}

if (auto scale = estimate_scale(pending.state);
Expand All @@ -106,14 +106,14 @@ void wlr_output_head_v1::broadcast()
res->send_scale(scale);
}
current_scale = scale;
manager.d_ptr->changed = true;
manager->d_ptr->changed = true;
}

if (published.state.adaptive_sync != pending.state.adaptive_sync || !published.state.enabled) {
for (auto res : resources) {
res->send_adaptive_sync(pending.state.adaptive_sync);
}
manager.d_ptr->changed = true;
manager->d_ptr->changed = true;
}
}

Expand Down
4 changes: 2 additions & 2 deletions server/wlr_output_head_v1_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class wlr_output_head_v1 : public QObject
wlr_output_head_v1_res* add_bind(wlr_output_manager_v1_bind& bind);
void broadcast();

Server::output& output;
Server::output* output;
std::vector<wlr_output_head_v1_res*> resources;
wlr_output_manager_v1& manager;
wlr_output_manager_v1* manager;

double current_scale{1.};
};
Expand Down

0 comments on commit 7af472b

Please sign in to comment.