| •1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#pragma once |
| 22 |
|
| 23 |
#include <string> |
| 24 |
#include <mutex> |
| 25 |
|
| 26 |
#include "DataTypes.h" |
| 27 |
#include "DataModel/LayoutItem.h" |
| 28 |
#include "DataModel/LockableItem.h" |
| 29 |
|
| 30 |
class Manager; |
| 31 |
|
| 32 |
namespace DataModel |
| 33 |
{ |
| 34 |
enum CounterType : uint8_t |
| 35 |
{ |
| 36 |
CounterTypeIncrement = 0, |
| 37 |
CounterTypeDecrement |
| 38 |
}; |
| 39 |
|
| 40 |
class Counter : public LayoutItem |
| 41 |
{ |
| 42 |
public: |
| 43 |
inline Counter(__attribute__((unused)) Manager* manager, const CounterID counterID) |
| 44 |
: LayoutItem(counterID), |
| 45 |
counter(0), |
| 46 |
max(0), |
| 47 |
min(0) |
| 48 |
{ |
| 49 |
} |
| 50 |
|
| 51 |
inline Counter(const std::string& serialized) |
| 52 |
: LayoutItem(CounterNone) |
| 53 |
{ |
| 54 |
Deserialize(serialized); |
| 55 |
} |
| 56 |
|
| 57 |
virtual ~Counter() |
| 58 |
{ |
| 59 |
} |
| 60 |
|
| 61 |
inline ObjectType GetObjectType() const override |
| 62 |
{ |
| 63 |
return ObjectTypeCounter; |
| 64 |
} |
| 65 |
|
| 66 |
inline std::string GetLayoutType() const override |
| 67 |
{ |
| 68 |
return Languages::GetText(Languages::TextCounter); |
| 69 |
} |
| 70 |
|
| 71 |
std::string Serialize() const override; |
| 72 |
|
| 73 |
void Deserialize(const std::string& serialized) override; |
| 74 |
|
| 75 |
bool Check(const CounterType type); |
| 76 |
|
| 77 |
bool Count(const CounterType type); |
| 78 |
|
| 79 |
inline int GetCounter() const |
| 80 |
{ |
| 81 |
return counter; |
| 82 |
} |
| 83 |
|
| 84 |
inline void SetMax(int max) |
| 85 |
{ |
| 86 |
this->max = max; |
| 87 |
} |
| 88 |
|
| 89 |
inline int GetMax() const |
| 90 |
{ |
| 91 |
return max; |
| 92 |
} |
| 93 |
|
| 94 |
inline void SetMin(int min) |
| 95 |
{ |
| 96 |
this->min = min; |
| 97 |
} |
| 98 |
|
| 99 |
inline int GetMin() const |
| 100 |
{ |
| 101 |
return min; |
| 102 |
} |
| 103 |
|
| 104 |
private: |
| 105 |
mutable std::mutex countMutex; |
| 106 |
int counter; |
| 107 |
int max; |
| 108 |
int min; |
| 109 |
}; |
| 110 |
} |