Debian Codegraph @

DataModel/Cluster.h

raw symbols ◀ ▶
Source reconstructed at patch state 1 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 <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(__attribute__((unused)) Manager* manager, const ClusterID clusterID)
41 : Object(clusterID),
42 orientation(OrientationRight)
43 {
44 }
45
46 inline Cluster(const std::string& serialized)
47 : Object(ClusterNone),
48 orientation(OrientationRight)
49 {
50 Deserialize(serialized);
51 }
52
53 virtual ~Cluster()
54 {
55 DeleteTracks();
56 }
57
58 inline ObjectType GetObjectType() const override
59 {
60 return ObjectTypeCluster;
61 }
62
63 std::string Serialize() const override;
64 void Deserialize(const std::string& serialized) override;
65
66 inline bool CanSetLocoBaseOrientation(const Orientation orientation,
67 const ObjectIdentifier& locoBaseIdentifier)
68 {
69 std::lock_guard<std::mutex> Guard(orientationMutex);
70 return CanSetLocoBaseOrientationUnlocked(orientation, locoBaseIdentifier);
71 }
72
73 bool SetLocoBaseOrientation(const Orientation orientation,
74 const ObjectIdentifier& locoBaseIdentifier);
75
76 inline Orientation GetLocoOrientation() const
77 {
78 return orientation;
79 }
80
81 inline const std::vector<DataModel::Relation*>& GetTracks() const
82 {
83 return tracks;
84 }
85
86 void DeleteTracks();
87 void DeleteTrack(DataModel::Track* trackToDelete);
88 void AssignTracks(const std::vector<DataModel::Relation*>& newTracks);
89
90 private:
91 bool CanSetLocoBaseOrientationUnlocked(const Orientation orientation,
92 const ObjectIdentifier& locoBaseIdentifier);
93
94 Orientation orientation;
95 mutable std::mutex orientationMutex;
96 std::vector<DataModel::Relation*> tracks;
97 };
98 } // namespace DataModel