Skip to content
Snippets Groups Projects
Verified Commit 205a4dd0 authored by Benny Baumann's avatar Benny Baumann
Browse files

fix: Code style, const correctness

parent 35614671
No related branches found
No related tags found
No related merge requests found
Pipeline #
#pragma once
#include <functional>
#include <memory>
#include <shared_mutex>
#include "progress_indicator.hpp"
#include "ui_context.hpp"
#include "event.hpp"
namespace rmrf::ui {
/**
* This class is designed to be the first level adapter to curses.
* It implements some basic information handling and a registry for
* views.
*/
class display : private std::enable_shared_from_this<display> {
public:
typedef display self_type;
typedef std::shared_ptr<self_type> ptr_type;
private:
typedef std::shared_mutex mutex_type;
typedef std::lock_guard<mutex_type> lock_type;
mutable mutex_type m;
public:
display();
virtual ~display();
public:
template<typename F, typename ...Args>
decltype(auto) sync(F &&f, Args &&... args) {
lock_type lock(m);
return std::forward<F>(f)(shared_from_this(), std::forward<Args>(args)...);
}
};
}
#include "ui/event.hpp"
namespace rmrf::ui {
event::event(std::shared_ptr<ui_context> sender) {
this->event_sender = sender;
}
event::~event() {
this->event_sender = nullptr;
this->handled = false;
}
event::event(const std::shared_ptr<ui_context> &sender) : event_sender(sender), handled(false) {
}
event::~event() {
}
std::shared_ptr<ui_context> event::get_sender() {
return this->event_sender;
}
std::shared_ptr<ui_context> event::get_sender() const {
return this->event_sender;
}
bool event::has_been_handled() {
return this->handled;
}
bool event::has_been_handled() const {
return this->handled;
}
void event::set_handled() {
this->handled = true;
}
void event::set_handled() {
this->handled = true;
}
}
......@@ -9,51 +9,51 @@
namespace rmrf::ui {
/**
* This class is used to share publish event updates.
* This class is used to share publish event updates.
*/
class event {
private:
std::shared_ptr<ui_context> event_sender;
bool handled;
std::shared_ptr<ui_context> event_sender;
bool handled;
public:
/**
* In order to construct an event one needs at least to specify
* the sender.
*
* @param sender The source of the event.
*/
event(std::shared_ptr<ui_context> sender);
/**
* A class implementing an event also needs to make sure that
* the special payload of the event is beeing taken care of.
*/
~event();
/**
* Use this methos in order to obtain the sender of this event.
*
* @return The sender
*/
std::shared_ptr<ui_context> get_sender();
/**
* Use this function in order to get a human readable description
* of the event.
*
* This does not need to be translated due to its purpose beeing
* debugging.
*
* @return A pointer to the description string
*/
std::shared_ptr<std::string> get_event_description();
/**
* Use this function in order to check if the event has been handled yet.
*
* @return true if the event was already dealt with or otherwise false.
*/
bool has_been_handled();
/**
* Call this function once the purpose of the event has been taken care of.
*/
void set_handled();
/**
* In order to construct an event one needs at least to specify
* the sender.
*
* @param sender The source of the event.
*/
explicit event(const std::shared_ptr<ui_context> &sender);
/**
* A class implementing an event also needs to make sure that
* the special payload of the event is beeing taken care of.
*/
virtual ~event();
/**
* Use this methos in order to obtain the sender of this event.
*
* @return The sender
*/
std::shared_ptr<ui_context> get_sender() const;
/**
* Use this function in order to get a human readable description
* of the event.
*
* This does not need to be translated due to its purpose beeing
* debugging.
*
* @return A pointer to the description string
*/
std::shared_ptr<std::string> get_event_description() const;
/**
* Use this function in order to check if the event has been handled yet.
*
* @return true if the event was already dealt with or otherwise false.
*/
bool has_been_handled() const;
/**
* Call this function once the purpose of the event has been taken care of.
*/
void set_handled();
};
}
......@@ -2,5 +2,4 @@
namespace rmrf::ui {
}
......@@ -6,36 +6,36 @@
namespace rmrf::ui {
/**
* This class is used to share progress information on running tasks.
* This class is used to share progress information on running tasks.
*/
class progress_indicator {
public:
virtual ~progress_indicator();
/**
* Query the progress state
* @return The current progress in percent
*/
virtual int get_progress();
/**
* This method shall be used in order to obtain
* the total amount of steps to be done.
*/
virtual int get_total_work();
/**
* This method shall be used to retrieve the
* current progress as a number of finished jobs.
*/
virtual int get_current_work();
/**
* This method shall be used in order to obtain the
* description of the total operation.
*/
virtual std::shared_ptr<std::string> get_operation_description();
/**
* This method shall be used in order to retrieve a
* description of the current step.
*/
virtual std::shared_ptr<std::string> get_current_job_description();
virtual ~progress_indicator();
/**
* Query the progress state
* @return The current progress in percent
*/
virtual int get_progress() const;
/**
* This method shall be used in order to obtain
* the total amount of steps to be done.
*/
virtual int get_total_work() const;
/**
* This method shall be used to retrieve the
* current progress as a number of finished jobs.
*/
virtual int get_current_work() const;
/**
* This method shall be used in order to obtain the
* description of the total operation.
*/
virtual std::shared_ptr<std::string> get_operation_description() const;
/**
* This method shall be used in order to retrieve a
* description of the current step.
*/
virtual std::shared_ptr<std::string> get_current_job_description() const;
};
}
......@@ -11,12 +11,12 @@ namespace rmrf::ui {
*/
class ui_context {
public:
virtual ~ui_context();
/**
* Use this method in order to get a fully qualified debug name
* of the context.
*/
virtual std::shared_ptr<std::string> get_name();
virtual ~ui_context();
/**
* Use this method in order to get a fully qualified debug name
* of the context.
*/
virtual std::shared_ptr<std::string> get_name() const;
};
}
......@@ -5,30 +5,32 @@
namespace rmrf::ui {
view::view(std::shared_ptr<view> parent) : parent_view{parent} {
if(this->parent_view != nullptr) {
this->parent_view->add_child(this);
}
view::view(const std::shared_ptr<view> &parent) : parent_view{parent}, child_views{} {
if (this->parent_view) {
this->parent_view->add_child(this->shared_from_this());
}
}
view::~view() {
if(this->parent_view != nullptr) {
this->parent_view->remove_child(this);
}
// Delete all childs that still exist
this->child_views.clear();
// Delete all childs that still exist
this->child_views.clear();
// Notify our parent about us being destructed
if (this->parent_view) {
this->parent_view->remove_child(this->shared_from_this());
}
}
std::shared_ptr<view> view::get_parent() {
return this->parent_view;
std::shared_ptr<view> view::get_parent() const {
return this->parent_view;
}
void view::add_child(std::unique_ptr<view> child) {
this->child_views.push_back(child);
void view::add_child(const std::shared_ptr<view> &child) {
this->child_views.push_back(child);
}
void view::remove_child(std::unique_ptr<view> child) {
this->child_views.remove(child);
void view::remove_child(const std::shared_ptr<view> &child) {
this->child_views.remove(child);
}
}
......@@ -4,51 +4,23 @@
#include <memory>
#include <shared_mutex>
#include "progress_indicator.hpp"
#include "ui_context.hpp"
#include "event.hpp"
#include "ui/display.hpp"
#include "ui/event.hpp"
#include "ui/progress_indicator.hpp"
#include "ui/ui_context.hpp"
namespace rmrf::ui {
/**
* This class is designed to be the first level adapter to curses.
* It implements some basic information handling and a registry for
* views.
*/
class display : public std::enable_shared_from_this<display> {
public:
typedef display self_type;
typedef std::shared_ptr<self_type> ptr_type;
private:
typedef std::shared_mutex mutex_type;
typedef std::lock_guard<mutex_type> lock_type;
mutable mutex_type m;
public:
display();
~display();
public:
template<typename F, typename ...Args>
decltype(auto) sync(F &&f, Args &&... args) {
lock_type lock(m);
return std::forward<F>(f)(shared_from_this(), std::forward<Args>(args)...);
}
};
/**
* This abstract class implements a view page.
*/
class view : public ui_context {
class view : public ui_context, private std::enable_shared_from_this<view> {
private:
std::shared_ptr<view> parent_view;
std::list<std::unique_ptr<view>> child_views;
std::list<std::shared_ptr<view>> child_views;
private:
void add_child(std::unique_ptr<view> child);
void remove_child(std::unique_ptr<view> child);
void add_child(const std::shared_ptr<view> &child);
void remove_child(const std::shared_ptr<view> &child);
public:
/**
* This method will be called when an operation is taking place. It may add
......@@ -56,7 +28,7 @@ public:
*
* @param progress The progress_indicator from the new running task to add
*/
virtual void add_progress_indicator(std::shared_ptr<progress_indicator> progress);
virtual void add_progress_indicator(const std::shared_ptr<progress_indicator> &progress);
/**
* This method will be called on a regular basis when the view needs to be updated
......@@ -68,27 +40,27 @@ public:
* @param event The event that caused the update.
* @return True if rerendering is required or otherwise false.
*/
virtual bool update(std::shared_ptr<display> display, std::shared_ptr<event> event);
virtual bool update(const std::shared_ptr<display> &display, const std::shared_ptr<event> &event);
/**
* This method gets called when events need to be processed that do not
* necessarily come from the UI thread.
*
* @param event The event that caused the update.
*/
virtual void schedule_update(std::shared_ptr<event> event);
virtual void schedule_update(const std::shared_ptr<event> &event);
/**
* Use this method in order to retrieve the parent of this view.
* @warn Keep in mind that this might be null.
* @return The parent
*/
std::shared_ptr<view> get_parent();
std::shared_ptr<view> get_parent() const;
/**
* This constructor shall be capable of creating the view.
*
* @param parent The parent view of this view. This may be null if there is none.
*/
view(std::shared_ptr<view> parent);
~view();
explicit view(const std::shared_ptr<view> &parent);
virtual ~view();
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment