Debian Codegraph @

DataModel/Cluster.h

raw symbols ◀ ▶ SCIP
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 <mutex>
24 #include <string>
25 #include <vector>
26
27 #include "DataTypes.h"
28 #include "DataModel/Object.h"
29
30 class Manager;
31
32 namespace DataModel
33 {
34 class Relation;
35 class Track;
36
37 class Cluster : public Object
38 {
39 public:
•40 inline Cluster(Manager* manager,
41 const ClusterID clusterID)
42 : Object(clusterID),
•43 manager(manager),
44 orientation(OrientationRight)
45 {
•46 }
47
•48 inline Cluster(Manager* manager,
49 const std::string& serialized)
50 : Object(ClusterNone),
•51 manager(manager),
52 orientation(OrientationRight)
53 {
54 Deserialize(serialized);
55 }
56
57 virtual ~Cluster()
58 {
59 DeleteTracks();
60 }
61
62 inline ObjectType GetObjectType() const override
63 {
64 return ObjectTypeCluster;
65 }
66
67 std::string Serialize() const override;
•68 void Deserialize(const std::string& serialized) override;
69
70 inline bool CanSetLocoBaseOrientation(const Orientation orientation,
71 const ObjectIdentifier& locoBaseIdentifier)
72 {
73 std::lock_guard<std::mutex> Guard(orientationMutex);
74 return CanSetLocoBaseOrientationUnlocked(orientation, locoBaseIdentifier);
75 }
76
77 bool SetLocoBaseOrientation(const Orientation orientation,
78 const ObjectIdentifier& locoBaseIdentifier);
79
80 inline Orientation GetLocoOrientation() const
81 {
82 return orientation;
83 }
84
85 inline const std::vector<DataModel::Relation*>& GetTracks() const
86 {
87 return tracks;
88 }
89
90 void DeleteTracks();
91 void DeleteTrack(DataModel::Track* trackToDelete);
92 void AssignTracks(const std::vector<DataModel::Relation*>& newTracks);
93
94 private:
95 bool CanSetLocoBaseOrientationUnlocked(const Orientation orientation,
96 const ObjectIdentifier& locoBaseIdentifier);
97
•98 Manager* manager;
99 Orientation orientation;
100 mutable std::mutex orientationMutex;
101 std::vector<DataModel::Relation*> tracks;
102 };
103 } // namespace DataModel