Debian Codegraph @

DataModel/Switch.h

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
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
25 #include "DataModel/AccessoryBase.h"
26 #include "DataModel/LayoutItem.h"
27 #include "DataModel/LockableItem.h"
28 #include "DataTypes.h"
29
30 class Manager;
31
32 namespace DataModel
33 {
34 class Switch : public AccessoryBase, public LayoutItem, public LockableItem
35 {
36 public:
37 Switch() = delete;
38 Switch(const Switch&) = delete;
39 Switch& operator=(const Switch&) = delete;
40
41 Switch(const SwitchID switchID)
42 : AccessoryBase(),
43 LayoutItem(switchID),
44 LockableItem()
45 {
46 }
47
48 Switch(__attribute__((unused)) Manager* manager, const SwitchID switchID)
49 : Switch(switchID)
50 {
51 }
52
53 Switch(const std::string& serialized)
54 {
55 Deserialize(serialized);
56 }
57
58 ObjectType GetObjectType() const override
59 {
60 return ObjectTypeSwitch;
61 }
62
63 std::string GetLayoutType() const override
64 {
65 return Languages::GetText(Languages::TextSwitch);
66 }
67
68 std::string Serialize() const override;
69
70 using HardwareHandle::Deserialize;
71 bool Deserialize(const std::string& serialized) override;
72
73 void SetAccessoryState(const AccessoryState state);
74
75 virtual inline void SetAccessoryType(AccessoryType type) override
76 {
77 AccessoryBase::SetAccessoryType(type);
78 SetSizeFromType();
79 }
80
81 bool UsesAddress(Address address) const;
82
83 std::map<DataModel::AccessoryState,Languages::TextSelector> GetStateOptions() const;
84
85 AccessoryState CalculateInvertedSwitchState(const Address address, const AccessoryState state) const;
86
87 static DataModel::LayoutItem::LayoutItemSize CalculateHeightFromType(AccessoryType type);
88
89 Switch& operator=(const Hardware::AccessoryCacheEntry& accessory);
90
91 private:
92 inline void SetSizeFromType()
93 {
94 SetWidth(Width1);
95 SetHeight(CalculateHeightFromType(GetAccessoryType()));
96 }
97 };
98 } // namespace DataModel