Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
CollectionSupportXML.h
1// trax track library
2// AD 2014
3//
4// "the resolution of all the fruitless searches"
5//
6// Peter Gabriel
7//
8// Copyright (c) 2025 Trend Redaktions- und Verlagsgesellschaft mbH
9// Copyright (c) 2019 Marc-Michael Horstmann
10//
11// Permission is hereby granted to any person obtaining a copy of this software
12// and associated source code (the "Software"), to use, view, and study the
13// Software for personal or internal business purposes, subject to the following
14// conditions:
15//
16// 1. Redistribution, modification, sublicensing, or commercial use of the
17// Software is NOT permitted without prior written consent from the copyright
18// holder.
19//
20// 2. The Software is provided "AS IS", without warranty of any kind, express
21// or implied.
22//
23// 3. All copies of the Software must retain this license notice.
24//
25// For further information, please contact: horstmann.marc@trendverlag.de
26
27#pragma once
28
29#include "common/support/CommonSupportConsole.h"
30#include "trax/support/TraxSupportXML.h"
31#include "trax/Curve.h"
32
33
46namespace trax{
47
48 struct CurveSample;
49 struct Indicator;
50 struct RoadwayTwist;
51 struct SignalCollection;
52 struct SocketRegistry;
53 struct TrackSystem;
54
55 namespace ptreesupport{
56
59 dclspc std::unique_ptr<Curve> CreateLine( const boost::property_tree::ptree& pt );
60 dclspc std::unique_ptr<Curve> CreateLineP( const boost::property_tree::ptree& pt );
61 dclspc std::unique_ptr<Curve> CreateArc( const boost::property_tree::ptree& pt );
62 dclspc std::unique_ptr<Curve> CreateArcP( const boost::property_tree::ptree& pt );
63 dclspc std::unique_ptr<Curve> CreateHelix( const boost::property_tree::ptree& pt );
64 dclspc std::unique_ptr<Curve> CreateHelixP( const boost::property_tree::ptree& pt );
65 dclspc std::unique_ptr<Curve> CreateCubic( const boost::property_tree::ptree& pt );
66 dclspc std::unique_ptr<Curve> CreateSpline( const boost::property_tree::ptree& pt );
67 dclspc std::unique_ptr<Curve> CreateClothoid( const boost::property_tree::ptree& pt );
68 dclspc std::unique_ptr<Curve> CreateRotator( const boost::property_tree::ptree& pt );
69 dclspc std::unique_ptr<Curve> CreateRotatorChain( const boost::property_tree::ptree& pt );
70 dclspc std::unique_ptr<Curve> CreatePolygonalChain( const boost::property_tree::ptree& pt );
71 dclspc std::unique_ptr<Curve> CreateSampledCurve( const boost::property_tree::ptree& pt );
72 dclspc std::unique_ptr<Curve> CreateEEPCurve( const boost::property_tree::ptree& pt );
73
74 dclspc void RegisterAllCurveReaders( class PTreeReader& toReader );
75
76 dclspc std::unique_ptr<RoadwayTwist> CreateConstantTwist( const boost::property_tree::ptree& pt );
77 dclspc std::unique_ptr<RoadwayTwist> CreateLinearTwist( const boost::property_tree::ptree& pt );
78 dclspc std::unique_ptr<RoadwayTwist> CreatePiecewiseTwist( const boost::property_tree::ptree& pt );
79 dclspc std::unique_ptr<RoadwayTwist> CreatePiecewiseLinearTwist( const boost::property_tree::ptree& pt );
80 dclspc std::unique_ptr<RoadwayTwist> CreatePiecewiseCircularTwist( const boost::property_tree::ptree& pt );
81 dclspc std::unique_ptr<RoadwayTwist> CreateDirectionalTwist( const boost::property_tree::ptree& pt );
82
83 dclspc void RegisterAllTwistReaders( class PTreeReader& toReader );
84
86
87
97 class PTreeReader{
98 public:
99 dclspc PTreeReader( const char* pLocale = nullptr );
100 dclspc PTreeReader( SocketRegistry& socketRegistry, const char* pLocale = nullptr );
101 PTreeReader( const PTreeReader& ) = delete;
102 dclspc PTreeReader( PTreeReader&& ) noexcept;
103 dclspc virtual ~PTreeReader();
104
105 PTreeReader& operator=( const PTreeReader& ) = delete;
106 PTreeReader& operator=( PTreeReader&& ) noexcept = delete;
107
108 using CurveReaderFunction = std::unique_ptr<Curve> (*)( const boost::property_tree::ptree& pt );
109
110 void dclspc RegisterCurveReader( const std::string& typeName, CurveReaderFunction readerFunc );
111
112 void dclspc UnregisterCurveReader( const std::string& typeName );
113
114
115 using TwistReaderFunction = std::unique_ptr<RoadwayTwist> (*)( const boost::property_tree::ptree& pt );
116
117 void dclspc RegisterTwistReader( const std::string& typeName, TwistReaderFunction readerFunc );
118
119 void dclspc UnregisterTwistReader( const std::string& typeName );
120
121 inline const char* GetLocale() const{
122 return m_pLocale;
123 }
124
125 virtual std::shared_ptr<trax::TrackSystem> ReadTrackSystem( const boost::property_tree::ptree& pt ) const = 0;
126 protected:
127 std::unique_ptr<Curve> CreateCurve( const boost::property_tree::ptree& pt ) const;
128
129 std::unique_ptr<RoadwayTwist> CreateTwist( const boost::property_tree::ptree& pt ) const;
130
131 private:
132 std::unique_ptr<SocketRegistry> m_pSocketRegistry;
133 class PTreeReaderBaseImpl* m_pImpl = nullptr;
134 const char* m_pLocale = nullptr;
135
136 std::unique_ptr<RoadwayTwist> CreateCombinedTwist( const boost::property_tree::ptree& pt ) const;
137
138 protected:
139 SocketRegistry& m_SocketRegistry;
140 };
141
142
143 template<class Interface>
144 inline void AttributesToReferences( const boost::property_tree::ptree& pt, Interface& refInterface ){
145 const auto iter = pt.find( "<xmlattr>" );
146 if( iter != pt.not_found() )
147 for( const auto& attribute : iter->second )
148 refInterface.Reference( attribute.first, attribute.second.data() );
149 }
150
151
154 dclspc void Read( const boost::property_tree::ptree& pt, Cubic::Data& curve );
155 dclspc void Read( const boost::property_tree::ptree& pt, CurveSample& sample );
156 dclspc void Read( const boost::property_tree::ptree& pt, EEPCurve::Data& data );
158
159 } // namespace ptreesupport
160} // namespace trax
Base class for XML readers based on ptree.
Definition CollectionSupportXML.h:97
ptree operator support
Definition CommonSupportXML.h:42
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
CubicData Data
Data definig the curve.
Definition Curve.h:1073
The dynamic data of a curve at one point.
Definition Curve.h:410
Data definig the curve.
Definition Curve.h:1944
Interface for objects that indicates system states somehow.
Definition Indicator.h:45
A RoadwayTwist is used to define the actual rotating angle around the tangent at a curve to get the c...
Definition RoadwayTwist.h:81
Collection to hold a set of Signal objects.
Definition SignalCollection.h:36
Interface for a registry that reconnects Plugs and Jacks according to their IDs.
Definition SocketRegistry.h:40
A track system is the container for tracks.
Definition TrackSystem.h:56