From 47931f41d579371c9c78ae7061317bf28848db2f Mon Sep 17 00:00:00 2001 From: Finlay Davidson Date: Thu, 16 Mar 2023 21:49:44 +0100 Subject: [PATCH] staticstack: Move to src/utility --- src/StaticStack.h | 43 --------------------------------- src/displayapp/DisplayApp.h | 6 ++--- src/utility/StaticStack.h | 47 +++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 46 deletions(-) delete mode 100644 src/StaticStack.h create mode 100644 src/utility/StaticStack.h diff --git a/src/StaticStack.h b/src/StaticStack.h deleted file mode 100644 index 598febce..00000000 --- a/src/StaticStack.h +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include - -template -class StaticStack { -public: - T Pop(); - void Push(T element); - void Reset(); - T Top(); - -private: - std::array elementArray; - // Number of elements in stack, points to the next empty slot - size_t stackPointer = 0; -}; - -// Returns random data when popping from empty array. -template -T StaticStack::Pop() { - if (stackPointer > 0) { - stackPointer--; - } - return elementArray[stackPointer]; -} - -template -void StaticStack::Push(T element) { - if (stackPointer < elementArray.size()) { - elementArray[stackPointer] = element; - stackPointer++; - } -} - -template -void StaticStack::Reset() { - stackPointer = 0; -} - -template -T StaticStack::Top() { - return elementArray[stackPointer - 1]; -} diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index 58df99c0..28d29cd4 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -19,7 +19,7 @@ #include "displayapp/Messages.h" #include "BootErrors.h" -#include "StaticStack.h" +#include "utility/StaticStack.h" namespace Pinetime { @@ -126,8 +126,8 @@ namespace Pinetime { void ApplyBrightness(); static constexpr size_t returnAppStackSize = 10; - StaticStack returnAppStack; - StaticStack appStackDirections; + Utility::StaticStack returnAppStack; + Utility::StaticStack appStackDirections; bool isDimmed = false; }; diff --git a/src/utility/StaticStack.h b/src/utility/StaticStack.h new file mode 100644 index 00000000..40df9354 --- /dev/null +++ b/src/utility/StaticStack.h @@ -0,0 +1,47 @@ +#include +#include + +namespace Pinetime { + namespace Utility { + template + class StaticStack { + public: + T Pop(); + void Push(T element); + void Reset(); + T Top(); + + private: + std::array elementArray; + // Number of elements in stack, points to the next empty slot + size_t stackPointer = 0; + }; + + // Returns random data when popping from empty array. + template + T StaticStack::Pop() { + if (stackPointer > 0) { + stackPointer--; + } + return elementArray[stackPointer]; + } + + template + void StaticStack::Push(T element) { + if (stackPointer < elementArray.size()) { + elementArray[stackPointer] = element; + stackPointer++; + } + } + + template + void StaticStack::Reset() { + stackPointer = 0; + } + + template + T StaticStack::Top() { + return elementArray[stackPointer - 1]; + } + } +}