Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
Train.h
1// trax track library
2// AD 2023
3//
4// "the resolution of all the fruitless searches"
5//
6// Peter Gabriel
7//
8//
9// Copyright (c) 2025 Trend Redaktions- und Verlagsgesellschaft mbH
10// Copyright (c) 2019 Marc-Michael Horstmann
11//
12// Permission is hereby granted to any person obtaining a copy of this software
13// and associated source code (the "Software"), to use, view, and study the
14// Software for personal or internal business purposes, subject to the following
15// conditions:
16//
17// 1. Redistribution, modification, sublicensing, or commercial use of the
18// Software is NOT permitted without prior written consent from the copyright
19// holder.
20//
21// 2. The Software is provided "AS IS", without warranty of any kind, express
22// or implied.
23//
24// 3. All copies of the Software must retain this license notice.
25//
26// For further information, please contact: horstmann.marc@trendverlag.de
27
28#pragma once
29
30#include "TrainComponent.h"
31
32namespace trax{
33
34 struct SimulatorTrain;
35
36
44
46 static dclspc std::shared_ptr<Train> Make() noexcept;
47
48
50 virtual std::shared_ptr<Train> ThisTrain() const noexcept = 0;
51
52
54 virtual int GetNumberOfComponents() const noexcept = 0;
55
56
59 virtual std::shared_ptr<TrainComponent> GetComponent( int index ) const = 0;
60
61
64 virtual int GetIndexOf( const TrainComponent& component ) const noexcept = 0;
65
66
67 // Creation:
68
72
79 virtual bool Create(
80 TrainComponent& trainComponent,
81 Orientation orientation = Orientation::Value::para ) = 0;
82
91 virtual bool Create(
92 const std::vector<std::pair<std::shared_ptr<TrainComponent>,Orientation>>& trainComponents,
93 Orientation orientation = Orientation::Value::para,
94 bool bMoveTo = true,
95 DistanceType distance = DistanceType::actual ) = 0;
97
98
99 // Appending:
100
111
115 virtual void Align( EndType atEnd, TrainComponent& component, EndType withEnd ) const = 0;
116
120 virtual void Align( EndType atEnd, TrainComponent& component, Orientation orientation ) const = 0;
122
123
140
141 virtual void Append( EndType atEnd, std::shared_ptr<TrainComponent> pComponent, EndType withEnd, bool bCouple = true ) = 0;
142
143 virtual void Append( EndType atEnd, std::shared_ptr<TrainComponent> pComponent, Orientation orientation, bool bCouple = true ) = 0;
145
146
155 virtual void Take( EndType atEnd, Train& fromTrain, EndType withEnd ) = 0;
156
157
170 virtual std::pair<std::shared_ptr<Train>,std::shared_ptr<Train>> SplitAfter( int idxAt ) = 0;
171
172
173 //Removing:
174
185 virtual std::shared_ptr<Train> Separate() = 0;
186
187
196 virtual void Reduce( bool bRecursive = true ) noexcept = 0;
197
198
203 virtual void Clear() noexcept = 0;
204
205
206 //Coupling:
207
208 using TrainComponent::Couple;
209
225 virtual bool Couple( EndType thisEnd, Train& with, EndType withEnd ) noexcept = 0;
226
227
231 virtual bool IsUnCoupledInternally() const noexcept = 0;
232
233
234 // \brief Get the coupled Train.
235 // \param end End type of this Train.
236 // \returns A pointer to the other Train coupled at end, or
237 // nullptr if none and the other Train's end type.
238 // virtual std::pair<std::shared_ptr<Train>,EndType> GetCoupledTrain( EndType end ) const noexcept = 0;
239
240
243 virtual struct Jack& JackOnUnCoupleInternal() noexcept = 0;
244 };
245
246
249
252
257 RailRunner::EndType Front( Orientation orientation ) noexcept;
258
263 RailRunner::EndType Back( Orientation orientation ) noexcept;
264
269 RailRunner::EndType Front( const TrainComponent& trainComponent ) noexcept;
270
275 RailRunner::EndType Back( const TrainComponent& trainComponent ) noexcept;
276
278
279
280
281// inlines:
282 inline RailRunner::EndType Front( Orientation orientation ) noexcept{
284 }
285
286 inline RailRunner::EndType Back( Orientation orientation ) noexcept{
288 }
289
290 inline RailRunner::EndType Front( const TrainComponent& trainComponent ) noexcept{
291 return Front( trainComponent.GetOrientation() );
292 }
293
294 inline RailRunner::EndType Back( const TrainComponent& trainComponent ) noexcept{
295 return Back( trainComponent.GetOrientation() );
296 }
297
298}
Value type, dependend from dimensions.
Definition DimensionedValues.h:233
RailRunner::EndType Front(Orientation orientation) noexcept
Get the front end of an oriented element.
Definition Train.h:282
RailRunner::EndType Back(Orientation orientation) noexcept
Get the back end of an oriented element.
Definition Train.h:286
STL namespace.
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
A jack a plug can get connected with.
Definition Jack.h:83
Provides two values for orientation.
Definition Orientation.h:37
Interface for train and rolling stock that can be railed on a track and might provide brakes and powe...
Definition RailRunner.h:345
EndType
Types of the RailRunner's end's.
Definition RailRunner.h:351
@ south
Denotes the back end of a RailRunner.
Definition RailRunner.h:354
@ north
Denotes the front end of a RailRunner.
Definition RailRunner.h:353
A TrainComponent is a part of a Train.
Definition TrainComponent.h:40
A Train is a collection of TrainComponents that are coupled in a row.
Definition Train.h:43
virtual void Take(EndType atEnd, Train &fromTrain, EndType withEnd)=0
Takes all components from another Train.
virtual bool Couple(EndType thisEnd, Train &with, EndType withEnd) noexcept=0
Couples this Train with another at the respective ends.
virtual std::shared_ptr< Train > Separate()=0
Removes everything south of a broken internal coupling from this Train, and returns a new Train with ...
virtual std::pair< std::shared_ptr< Train >, std::shared_ptr< Train > > SplitAfter(int idxAt)=0
Splits this Train into two Trains at the specified index.
virtual int GetIndexOf(const TrainComponent &component) const noexcept=0
virtual void Align(EndType atEnd, TrainComponent &component, EndType withEnd) const =0
virtual int GetNumberOfComponents() const noexcept=0
virtual void Clear() noexcept=0
Removes all components from this train.
virtual bool IsUnCoupledInternally() const noexcept=0
virtual std::shared_ptr< TrainComponent > GetComponent(int index) const =0
Gets the TrainComponent at zero based index.
virtual std::shared_ptr< Train > ThisTrain() const noexcept=0
Gets a shared pointer to this.
static dclspc std::shared_ptr< Train > Make() noexcept
Makes a Train object.
virtual struct Jack & JackOnUnCoupleInternal() noexcept=0
Gets a Jack that pulses its Plug if a coupling inside the train (including all sub-Trains) is uncoupl...
virtual bool Create(TrainComponent &trainComponent, Orientation orientation=Orientation::Value::para)=0
virtual void Reduce(bool bRecursive=true) noexcept=0
Removes TrainComponents from this Train and includes them directly to the parent train....