Skip to content

Commit e62f873

Browse files
authored
Merge pull request #205 from nscooling/dirtyRefactor
refactored class DirtyValue
2 parents 57ce58f + 751ffab commit e62f873

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

src/displayapp/screens/Clock.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ namespace Pinetime {
2121
template <class T>
2222
class DirtyValue {
2323
public:
24-
explicit DirtyValue(T v) { value = v; }
25-
explicit DirtyValue(T& v) { value = v; }
24+
DirtyValue() = default; // Use NSDMI
25+
explicit DirtyValue(T const& v):value{v}{} // Use MIL and const-lvalue-ref
2626
bool IsUpdated() const { return isUpdated; }
27-
T& Get() { this->isUpdated = false; return value; }
28-
27+
T const& Get() { this->isUpdated = false; return value; } // never expose a non-const lvalue-ref
2928
DirtyValue& operator=(const T& other) {
3029
if (this->value != other) {
3130
this->value = other;
@@ -34,9 +33,10 @@ namespace Pinetime {
3433
return *this;
3534
}
3635
private:
37-
T value;
38-
bool isUpdated = true;
36+
T value{}; // NSDMI - default initialise type
37+
bool isUpdated{true}; // NSDMI - use brace initilisation
3938
};
39+
4040
class Clock : public Screen {
4141
public:
4242
Clock(DisplayApp* app,
@@ -64,13 +64,13 @@ namespace Pinetime {
6464
Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
6565
uint8_t currentDay = 0;
6666

67-
DirtyValue<int> batteryPercentRemaining {0};
68-
DirtyValue<bool> bleState {false};
69-
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime;
70-
DirtyValue<uint32_t> stepCount {0};
71-
DirtyValue<uint8_t> heartbeat {0};
72-
DirtyValue<bool> heartbeatRunning {false};
73-
DirtyValue<bool> notificationState {false};
67+
DirtyValue<int> batteryPercentRemaining {};
68+
DirtyValue<bool> bleState {};
69+
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime{};
70+
DirtyValue<uint32_t> stepCount {};
71+
DirtyValue<uint8_t> heartbeat {};
72+
DirtyValue<bool> heartbeatRunning {};
73+
DirtyValue<bool> notificationState {};
7474

7575
lv_obj_t* label_time;
7676
lv_obj_t* label_date;

0 commit comments

Comments
 (0)