Debian Codegraph @

DataModel/Relation.h

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches 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 "DataModel/Accessory.h"
27 #include "DataModel/LockableItem.h"
28 #include "DataModel/ObjectIdentifier.h"
29 #include "DataModel/Serializable.h"
30 #include "DataTypes.h"
31 #include "Logger/Logger.h"
32
33 class Manager;
34
35 namespace DataModel
36 {
37 class Relation : protected Serializable, public LockableItem
38 {
39 public:
40 enum RelationType : unsigned char
41 {
42 RelationTypeCalculate = 0,
43 RelationTypeLocoSlave = (ObjectTypeLoco << 3), // FIXME: 2024-03-17: not used anymore, TypeMultipeUnitSlave instead
44 RelationTypeTrackSignal = (ObjectTypeTrack << 3),
45 RelationTypeTrackFeedback = (ObjectTypeTrack << 3) + 1,
46 RelationTypeFeedbackAtSet = (ObjectTypeFeedback << 3),
47 RelationTypeFeedbackAtUnset = (ObjectTypeFeedback << 3) + 1,
48 RelationTypeRouteAtLock = (ObjectTypeRoute << 3),
49 RelationTypeRouteAtUnlock = (ObjectTypeRoute << 3) + 1,
50 RelationTypeClusterTrack = (ObjectTypeCluster << 3),
51 RelationTypeMultipleUnitLoco = (ObjectTypeMultipleUnit << 3),
52 };
53
54 typedef unsigned short Data;
55 static const Data DefaultData = 0;
56
57 inline Relation(Manager* manager,
58 const ObjectIdentifier& object1,
59 const ObjectIdentifier& object2,
60 const RelationType type,
61 const Priority priority = 0,
62 const Data data = 0)
63 : manager(manager),
64 object1(object1),
65 object2(object2),
66 type(type),
67 priority(priority),
68 data(data)
69 {
70 }
71
72 inline Relation(Manager* manager,
73 const std::string& serialized)
74 : manager(manager),
75 data(0)
76 {
77 Deserialize(serialized);
78 }
79
80 virtual ~Relation()
81 {
82 }
83
84 virtual std::string Serialize() const override;
85 virtual bool Deserialize(const std::string& serialized) override;
86
87 inline ObjectID ObjectID1() const
88 {
89 return object1.GetObjectID();
90 }
91
92 inline void ObjectID1(ObjectID objectID1)
93 {
94 object1.SetObjectID(objectID1);
95 }
96
97 inline ObjectType ObjectType2() const
98 {
99 return object2.GetObjectType();
100 }
101
102 inline ObjectID ObjectID2() const
103 {
104 return object2.GetObjectID();
105 }
106
107 inline ObjectIdentifier ObjectIdentifier2() const
108 {
109 return object2;
110 }
111
112 LockableItem* GetObject2();
113
114 inline RelationType GetType() const
115 {
116 return type;
117 }
118
119 inline Priority GetPriority() const
120 {
121 return priority;
122 }
123
124 inline Data GetData() const
125 {
126 return data;
127 }
128
129 inline bool CompareObject2(const ObjectIdentifier& identifier) const
130 {
131 return object2 == identifier;
132 }
133
134 bool Reserve(Logger::Logger* logger, const ObjectIdentifier& locoBaseIdentifier) override;
135 bool Lock(Logger::Logger* logger, const ObjectIdentifier& locoBaseIdentifier) override;
136 bool Release(Logger::Logger* logger, const ObjectIdentifier& locoBaseIdentifier) override;
137 bool Execute(Logger::Logger* logger, const ObjectIdentifier& locoBaseIdentifier, const Delay delay);
138
139 private:
140 inline ObjectType ObjectType1() const
141 {
142 return object1.GetObjectType();
143 }
144
145 Manager* manager;
146 ObjectIdentifier object1;
147 ObjectIdentifier object2;
148 RelationType type;
149 Priority priority;
150 Data data;
151 };
152 } // namespace DataModel
153