1
0
Fork 0

Merge pull request #205 from nscooling/dirtyRefactor

refactored class DirtyValue
This commit is contained in:
JF002 2021-02-14 14:37:26 +01:00 committed by GitHub
commit e62f8734be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,11 +21,10 @@ namespace Pinetime {
template <class T> template <class T>
class DirtyValue { class DirtyValue {
public: public:
explicit DirtyValue(T v) { value = v; } DirtyValue() = default; // Use NSDMI
explicit DirtyValue(T& v) { value = v; } explicit DirtyValue(T const& v):value{v}{} // Use MIL and const-lvalue-ref
bool IsUpdated() const { return isUpdated; } bool IsUpdated() const { return isUpdated; }
T& Get() { this->isUpdated = false; return value; } T const& Get() { this->isUpdated = false; return value; } // never expose a non-const lvalue-ref
DirtyValue& operator=(const T& other) { DirtyValue& operator=(const T& other) {
if (this->value != other) { if (this->value != other) {
this->value = other; this->value = other;
@ -34,9 +33,10 @@ namespace Pinetime {
return *this; return *this;
} }
private: private:
T value; T value{}; // NSDMI - default initialise type
bool isUpdated = true; bool isUpdated{true}; // NSDMI - use brace initilisation
}; };
class Clock : public Screen { class Clock : public Screen {
public: public:
Clock(DisplayApp* app, Clock(DisplayApp* app,
@ -64,13 +64,13 @@ namespace Pinetime {
Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown; Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
uint8_t currentDay = 0; uint8_t currentDay = 0;
DirtyValue<int> batteryPercentRemaining {0}; DirtyValue<int> batteryPercentRemaining {};
DirtyValue<bool> bleState {false}; DirtyValue<bool> bleState {};
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime; DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime{};
DirtyValue<uint32_t> stepCount {0}; DirtyValue<uint32_t> stepCount {};
DirtyValue<uint8_t> heartbeat {0}; DirtyValue<uint8_t> heartbeat {};
DirtyValue<bool> heartbeatRunning {false}; DirtyValue<bool> heartbeatRunning {};
DirtyValue<bool> notificationState {false}; DirtyValue<bool> notificationState {};
lv_obj_t* label_time; lv_obj_t* label_time;
lv_obj_t* label_date; lv_obj_t* label_date;