LCOV - code coverage report
Current view: top level - src/Selectors - Selectable.hpp (source / functions) Hit Total Coverage
Test: 90a1b9beff85a60dc6ebcea034a947a845e56960 Lines: 8 9 88.9 %
Date: 2019-11-30 15:53:32 Functions: 11 12 91.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <AH/Error/Error.hpp>
       4             : #include <AH/STL/type_traits>
       5             : #include <Def/Def.hpp>
       6             : #include <stdint.h>
       7             : 
       8             : BEGIN_CS_NAMESPACE
       9             : 
      10             : template <setting_t N> // TODO: check bounds here?
      11             : class Selectable {
      12             :   protected:
      13          29 :     Selectable(setting_t initialSelection = 0)
      14          29 :         : initialSelection{initialSelection} {}
      15             : 
      16             :   public:
      17             :     virtual void select(setting_t setting) = 0;
      18             : 
      19          77 :     static setting_t validateSetting(setting_t setting) {
      20             :         static_assert(std::is_unsigned<setting_t>::value,
      21             :                       "Error: setting_t should be an unsigned integer type.");
      22          77 :         if (setting >= N) {
      23           1 :             ERROR(F("Error: Setting ")
      24             :                       << setting
      25             :                       << F(" is not less than the number of settings (") << N
      26             :                       << ')',
      27             :                   0xFFFE);
      28           0 :             return N - 1;
      29             :         }
      30          76 :         return setting;
      31          77 :     }
      32             : 
      33          10 :     setting_t getInitialSelection() const { return initialSelection; }
      34             : 
      35             :     void setInitialSelection(setting_t initialSelection) {
      36             :         this->initialSelection = validateSetting(initialSelection);
      37             :     }
      38             : 
      39             :   private:
      40             :     setting_t initialSelection;
      41             : };
      42             : 
      43             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-5-g4ff2ed6