Follow practices suggested by "Effective C++"

The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:

* A class with virtual functions can no longer publicly inherit base
  classed without a vtable. The inherited object may either be moved
  to a member variable, or inherited privately. The latter would be
  used for classes that inherit 'List::Element' or 'Avl_node'. In order
  to enable the 'List' and 'Avl_tree' to access the meta data, the
  'List' must become a friend.

* Instead of adding a virtual destructor to abstract base classes,
  we inherit the new 'Interface' class, which contains a virtual
  destructor. This way, single-line abstract base classes can stay
  as compact as they are now. The 'Interface' utility resides in
  base/include/util/interface.h.

* With the new warnings enabled, all member variables must be explicitly
  initialized. Basic types may be initialized with '='. All other types
  are initialized with braces '{ ... }' or as class initializers. If
  basic types and non-basic types appear in a row, it is nice to only
  use the brace syntax (also for basic types) and align the braces.

* If a class contains pointers as members, it must now also provide a
  copy constructor and assignment operator. In the most cases, one
  would make them private, effectively disallowing the objects to be
  copied. Unfortunately, this warning cannot be fixed be inheriting
  our existing 'Noncopyable' class (the compiler fails to detect that
  the inheriting class cannot be copied and still gives the error).
  For now, we have to manually add declarations for both the copy
  constructor and assignment operator as private class members. Those
  declarations should be prepended with a comment like this:

        /*
         * Noncopyable
         */
        Thread(Thread const &);
        Thread &operator = (Thread const &);

  In the future, we should revisit these places and try to replace
  the pointers with references. In the presence of at least one
  reference member, the compiler would no longer implicitly generate
  a copy constructor. So we could remove the manual declaration.

Issue #465
This commit is contained in:
Norman Feske
2017-12-21 15:42:15 +01:00
committed by Christian Helmuth
parent 2a33d9aa76
commit eba9c15746
763 changed files with 4936 additions and 3288 deletions

View File

@ -32,6 +32,12 @@ class Framebuffer_window : public Scout::Window
{
private:
/*
* Noncopyable
*/
Framebuffer_window(Framebuffer_window const &);
Framebuffer_window &operator = (Framebuffer_window const &);
/**
* Constants
*/
@ -40,10 +46,10 @@ class Framebuffer_window : public Scout::Window
/**
* Widgets
*/
Scout::Titlebar<PT> _titlebar;
Scout::Sky_texture<PT, 512, 512> _bg_texture;
int _bg_offset;
Scout::Fade_icon<PT, 32, 32> _sizer;
Scout::Titlebar<PT> _titlebar { };
Scout::Sky_texture<PT, 512, 512> _bg_texture { };
int _bg_offset { 0 };
Scout::Fade_icon<PT, 32, 32> _sizer { };
Scout::Element *_content;
bool _config_alpha;
bool _config_resize_handle;
@ -57,7 +63,7 @@ class Framebuffer_window : public Scout::Window
Framebuffer_window(Scout::Graphics_backend &gfx_backend,
Scout::Element *content,
Scout::Point position,
Scout::Area size,
Scout::Area /* size */,
Scout::Area max_size,
char const *name,
bool config_alpha,
@ -68,7 +74,7 @@ class Framebuffer_window : public Scout::Window
Scout::Area(content->min_size().w() + 2,
content->min_size().h() + 1 + _TH),
max_size, false),
_bg_offset(0), _content(content), _config_alpha(config_alpha),
_content(content), _config_alpha(config_alpha),
_config_resize_handle(config_resize_handle),
_config_decoration(config_decoration)
{

View File

@ -222,7 +222,7 @@ class Liquid_fb::Main : public Scout::Event_handler
config_resize_handle, config_decoration };
/* create background animator if configured */
Constructible<Background_animator> _fb_win_bg_anim;
Constructible<Background_animator> _fb_win_bg_anim { };
void _init_background_animator()
{
if (config_animate) {

View File

@ -37,8 +37,14 @@ class Window_content : public Scout::Element
{
private:
/*
* Noncopyable
*/
Content_event_handler(Content_event_handler const &);
Content_event_handler &operator = (Content_event_handler const &);
Input::Session_component &_input_session;
Scout::Point _old_mouse_position;
Scout::Point _old_mouse_position { };
Element *_element;
public:
@ -46,7 +52,8 @@ class Window_content : public Scout::Element
Content_event_handler(Input::Session_component &input_session,
Scout::Element *element)
:
_input_session(input_session),_element(element) { }
_input_session(input_session), _element(element)
{ }
void handle_event(Scout::Event const &ev) override
{
@ -118,6 +125,14 @@ class Window_content : public Scout::Element
alloc.free(alpha, w*h);
}
private:
/*
* Noncopyable
*/
Fb_texture(Fb_texture const &);
Fb_texture &operator = (Fb_texture const &);
};
Genode::Ram_session &_ram;
@ -145,7 +160,7 @@ class Window_content : public Scout::Element
*/
Scout::Area _designated_size;
Genode::Signal_context_capability _mode_sigh;
Genode::Signal_context_capability _mode_sigh { };
public:

View File

@ -62,7 +62,7 @@ namespace Nitlog {
/**
* Pixel-type-independent interface to graphics backend
*/
struct Canvas_base
struct Canvas_base : Genode::Interface
{
virtual void draw_string(Point, Font const &, Color, char const *) = 0;
@ -108,10 +108,10 @@ class Log_entry
char _label[64];
char _text[LOG_W];
char _attr[LOG_W];
Color _color;
int _label_len;
int _text_len;
int _id;
Color _color { };
int _label_len = 0;
int _text_len = 0;
int _id = 0;
public:
@ -186,22 +186,20 @@ class Log_window
private:
Canvas_base &_canvas;
Log_entry _entries[LOG_H]; /* log entries */
int _dst_entry; /* destination entry for next write */
int _view_pos; /* current view port on the entry array */
bool _scroll; /* scroll mode (when text hits bottom) */
char _attr[LOG_W]; /* character attribute buffer */
bool _dirty; /* schedules the log window for a redraw */
Genode::Lock _dirty_lock;
Log_entry _entries[LOG_H]; /* log entries */
int _dst_entry = 0; /* destination entry for next write */
int _view_pos = 0; /* current view port on the entry array */
bool _scroll = false; /* scroll mode (when text hits bottom) */
char _attr[LOG_W]; /* character attribute buffer */
bool _dirty = true; /* schedules the log window for a redraw */
Genode::Lock _dirty_lock { };
public:
/**
* Constructor
*/
Log_window(Canvas_base &canvas)
: _canvas(canvas), _dst_entry(0), _view_pos(0), _dirty(true)
{ }
Log_window(Canvas_base &canvas) : _canvas(canvas) { }
/**
* Write log entry
@ -357,7 +355,8 @@ class Log_view
Nitpicker::Area _size;
Nitpicker::Session::View_handle _handle;
typedef Nitpicker::Session::Command Command;
typedef Nitpicker::Session::Command Command;
typedef Nitpicker::Session::View_handle View_handle;
public:
@ -374,7 +373,7 @@ class Log_view
void top()
{
_nitpicker.enqueue<Command::To_front>(_handle);
_nitpicker.enqueue<Command::To_front>(_handle, View_handle());
_nitpicker.execute();
}
@ -443,7 +442,8 @@ struct Nitlog::Main
Attached_dataspace _ev_ds { _env.rm(), _nitpicker.input()->dataspace() };
Nitpicker::Point _old_mouse_pos;
Nitpicker::Point _old_mouse_pos { };
unsigned _key_cnt = 0;
Signal_handler<Main> _input_handler {