Skip to content

Commit

Permalink
refactor: add override specifier to virtual functions for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
zackees committed Nov 27, 2024
1 parent fa0bf03 commit 13b0ace
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/chipsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,13 @@ class APA102Controller : public CPixelLEDController<RGB_ORDER> {
public:
APA102Controller() {}

virtual void init() {
virtual void init() override {
mSPI.init();
}

protected:
/// @copydoc CPixelLEDController::showPixels()
virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
virtual void showPixels(PixelController<RGB_ORDER> & pixels) override {
PixelIterator iterator = pixels.as_iterator(this->getRgbw());
switch (GAMMA_CORRECTION_MODE) {
case kFiveBitGammaCorrectionMode_Null: {
Expand Down
3 changes: 3 additions & 0 deletions src/cled_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class CLEDController {
mRgbMode = arg;
return *this; // builder pattern.
}
#ifndef __AVR__
virtual ~CLEDController() {}
#endif
Rgbw getRgbw() const { return mRgbMode; }

/// Create an led controller object, add it to the chain of controllers
Expand Down
6 changes: 3 additions & 3 deletions src/cpixel_ledcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ template<EOrder RGB_ORDER, int LANES=1, uint32_t MASK=0xFFFFFFFF> class CPixelLE
/// @param data the CRGB color to set the LEDs to
/// @param nLeds the number of LEDs to set to this color
/// @param scale_pre_mixed the RGB scaling of color adjustment + global brightness to apply to each LED (in RGB8 mode).
virtual void showColor(const CRGB& data, int nLeds, uint8_t brightness) {
virtual void showColor(const CRGB& data, int nLeds, uint8_t brightness) override {
// CRGB premixed, color_correction;
// getAdjustmentData(brightness, &premixed, &color_correction);
// ColorAdjustment color_adjustment = {premixed, color_correction, brightness};
Expand All @@ -44,7 +44,7 @@ template<EOrder RGB_ORDER, int LANES=1, uint32_t MASK=0xFFFFFFFF> class CPixelLE
/// @param data the RGB data to write out to the strip
/// @param nLeds the number of LEDs being written out
/// @param scale_pre_mixed the RGB scaling of color adjustment + global brightness to apply to each LED (in RGB8 mode).
virtual void show(const struct CRGB *data, int nLeds, uint8_t brightness) {
virtual void show(const struct CRGB *data, int nLeds, uint8_t brightness) override {
ColorAdjustment color_adjustment = getAdjustmentData(brightness);
PixelController<RGB_ORDER, LANES, MASK> pixels(data, nLeds < 0 ? -nLeds : nLeds, color_adjustment, getDither());
if(nLeds < 0) {
Expand All @@ -66,7 +66,7 @@ template<EOrder RGB_ORDER, int LANES=1, uint32_t MASK=0xFFFFFFFF> class CPixelLE

/// Get the number of lanes of the Controller
/// @returns LANES from template
int lanes() { return LANES; }
int lanes() override { return LANES; }
};


Expand Down
9 changes: 6 additions & 3 deletions src/fastpin.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ FASTLED_NAMESPACE_BEGIN
/// Abstract class for "selectable" things
class Selectable {
public:
#ifndef __AVR__
virtual ~Selectable() {}
#endif
virtual void select() = 0; ///< Select this object
virtual void release() = 0; ///< Release this object
virtual bool isSelected() = 0; ///< Check if this object is currently selected
Expand Down Expand Up @@ -178,9 +181,9 @@ class Pin : public Selectable {
port_ptr_t port() __attribute__ ((always_inline)) { return mPort; }
port_t mask() __attribute__ ((always_inline)) { return mPinMask; }

virtual void select() { hi(); }
virtual void release() { lo(); }
virtual bool isSelected() { return (*mPort & mPinMask) == mPinMask; }
virtual void select() override { hi(); }
virtual void release() override { lo(); }
virtual bool isSelected() override { return (*mPort & mPinMask) == mPinMask; }
};

class OutputPin : public Pin {
Expand Down
1 change: 1 addition & 0 deletions src/fl/file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class FileHandle: public Referent {
class FsImpl : public Referent {
public:
struct Visitor {
virtual ~Visitor() {}
virtual void accept(const char* path) = 0;
};
FsImpl() = default;
Expand Down
25 changes: 25 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,37 @@ message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
# Define common compiler flags and definitions
set(COMMON_COMPILE_FLAGS
-Wall
#-Wextra
#-Wpedantic
-funwind-tables
-g3
-ggdb
-fno-omit-frame-pointer
-O0
-fno-inline
-Werror=suggest-override
-Werror=return-type
#-Werror=missing-declarations
#-Werror=redundant-decls
#-Werror=init-self
#-Werror=missing-field-initializers
#-Werror=pointer-arith
#-Werror=write-strings
#-Werror=format=2
#-Werror=implicit-fallthrough
#-Werror=missing-include-dirs
#-Werror=date-time
-Werror=non-virtual-dtor
#-Werror=reorder
#-Werror=sign-compare
#-Werror=float-equal
#-Werror=conversion
#-Werror=switch-enum
#-Werror=switch-default
#-Werror=unused-parameter
#-Werror=unused-variable
#-Werror=unused-value
-Werror=infinite-recursion
)

set(COMMON_COMPILE_DEFINITIONS
Expand Down
6 changes: 3 additions & 3 deletions tests/test_refptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class MyClass : public fl::Referent {
~MyClass() {
destructor_signal = 0xdeadbeef;
}
virtual void ref() { Referent::ref(); }
virtual void unref() { Referent::unref(); }
virtual void destroy() { Referent::destroy(); }
virtual void ref() override { Referent::ref(); }
virtual void unref() override { Referent::unref(); }
virtual void destroy() override { Referent::destroy(); }
uint32_t destructor_signal = 0;
};

Expand Down

0 comments on commit 13b0ace

Please sign in to comment.