LCOV - code coverage report
Current view: top level - src/Display - DisplayElement.hpp (source / functions) Hit Total Coverage
Test: 19d2efc7037c2e176feca44750a12594c76f466f Lines: 0 2 0.0 %
Date: 2019-11-24 14:50:27 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <Display/DisplayInterface.hpp>
       4             : #include <Helpers/LinkedList.hpp>
       5             : 
       6             : BEGIN_CS_NAMESPACE
       7             : 
       8             : /**
       9             :  * @brief   An interface for elements that draw to a display.
      10             :  */
      11             : class DisplayElement : public DoublyLinkable<DisplayElement> {
      12             :   protected:
      13             :     /**
      14             :      * @brief   Create a new DisplayElement.
      15             :      * 
      16             :      * @param   display
      17             :      *          The display that this display element draws to.
      18             :      */
      19             :     DisplayElement(DisplayInterface &display) : display(display) {
      20             :         // The elements are sorted by the address of their displays.
      21             :         // This way, all display elements that draw to the same display are next
      22             :         // to each other. This means that the display buffer can be reused.
      23             :         elements.insertSorted(
      24             :             this, [](const DisplayElement &lhs, const DisplayElement &rhs) {
      25             :                 return &lhs.getDisplay() < &rhs.getDisplay();
      26             :             });
      27             :     }
      28             : 
      29             :   public:
      30             :     virtual ~DisplayElement() { elements.remove(this); }
      31             : 
      32             :     /// Draw this DisplayElement to the display buffer.
      33             :     virtual void draw() = 0;
      34             : 
      35             :     /// Get a reference to the display that this element draws to.
      36           0 :     DisplayInterface &getDisplay() { return display; }
      37             :     /// Get a const reference to the display that this element draws to.
      38             :     const DisplayInterface &getDisplay() const { return display; }
      39             : 
      40             :     /// Get the list of all DisplayElement instances.
      41           0 :     static DoublyLinkedList<DisplayElement> &getAll() { return elements; }
      42             : 
      43             :   protected:
      44             :     DisplayInterface &display;
      45             : 
      46             :     static DoublyLinkedList<DisplayElement> elements;
      47             : };
      48             : 
      49             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-5-g4ff2ed6