Debian Codegraph @

DataModel/HardwareHandle.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 <map>
24 #include <string>
25
26 #include "DataTypes.h"
27 #include "DataModel/Serializable.h"
28
29 namespace DataModel
30 {
31 class HardwareHandle
32 {
33 // simply stores controlID, protocol and base address of an object
34 // this is only to prevent copying code and use a base class instead
35 public:
36 inline HardwareHandle()
37 : controlID(ControlNone),
38 protocol(ProtocolNone),
39 address(AddressDefault),
40 serverAddress(AddressNone)
41 {
42 }
43
44 virtual ~HardwareHandle()
45 {
46 }
47
48 inline void SetControlID(ControlID controlID)
49 {
50 this->controlID = controlID;
51 }
52
53 inline ControlID GetControlID() const
54 {
55 return controlID;
56 }
57
58 inline void SetProtocol(Protocol protocol)
59 {
60 this->protocol = protocol;
61 }
62
63 inline Protocol GetProtocol() const
64 {
65 return protocol;
66 }
67
68 inline void SetAddress(Address address)
69 {
70 if (address == AddressNone)
71 {
72 this->address = AddressDefault;
73 }
74 else
75 {
76 this->address = address;
77 }
78 }
79
80 inline Address GetAddress() const
81 {
82 return address;
83 }
84
85 inline void SetServerAddress(const Address serverAddress)
86 {
87 if (serverAddress == AddressNone)
88 {
89 this->serverAddress = this->address;
90 }
91 else
92 {
93 this->serverAddress = serverAddress;
94 }
95 }
96
97 inline Address GetServerAddress() const
98 {
99 return serverAddress;
100 }
101
102 protected:
103 virtual std::string Serialize() const;
•104 virtual void Deserialize(const std::map<std::string,std::string>& arguments);
105
106 private:
107 ControlID controlID;
108 Protocol protocol;
109 Address address;
110 Address serverAddress;
111 };
112 } // namespace DataModel
113