Debian Codegraph @

DataModel/Counter.h

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 /*
2 RailControl - Model Railway Control Software
3
4 Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org
5
6 RailControl is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 RailControl is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with RailControl; see the file LICENCE. If not see
18 <http://www.gnu.org/licenses/>.
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 } // namespace DataModel