Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
TraxSupportStream.h
1// trax track library
2// AD 2020
3//
4// "I only want to be sixteen
5// "and free..."
6//
7// Blind Melon
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 "trax/Event.h"
31#include "trax/Track.h"
32#include "trax/TrackLocation.h"
33#include "trax/Location.h"
34#include "trax/Curve.h"
35#include "trax/Plug.h"
36#include "trax/Switch.h"
37
38#include "common/support/CommonSupportStream.h"
39#include "dim/support/DimSupportStream.h"
40#include "spat/support/SpatSupportStream.h"
41
42#include <iomanip>
43
44namespace trax{
45
46
50
53 inline std::ostream& operator << ( std::ostream& os, const Track::EndType& endType );
54
55 inline std::istream& operator >> ( std::istream& is, Track::EndType& endType );
56
57 inline std::ostream& operator << ( std::ostream& os, const Track::End& end );
58
59 inline std::istream& operator >> ( std::istream& is, Track::End& end );
60
61 inline std::ostream& operator << ( std::ostream& ost, const Location& location );
62
63 inline std::ostream& operator << ( std::ostream& ost, const TrackLocation& location );
64
65 inline std::ostream& operator << ( std::ostream& ost, const TrackLocationRef& location );
66
67 inline std::ostream& operator << ( std::ostream& ost, const TrackRange& range );
68
69 inline std::ostream& operator<<( std::ostream& ost, const Orientation& orient );
70
71 inline std::ostream& operator<<( std::ostream& ost, const Orientation::Value& orient );
72
73
74 inline std::ostream& operator << ( std::ostream& ost, NarrowSwitch::Status status );
75
76
77 inline std::ostream& operator << ( std::ostream& os, const LineP::Data& data );
78 inline std::ostream& operator << ( std::ostream& os, const Arc::Data& data );
79 inline std::ostream& operator << ( std::ostream& os, const ArcP::Data& data );
80 inline std::ostream& operator << ( std::ostream& os, const Helix::Data& data );
81 inline std::ostream& operator << ( std::ostream& os, const HelixP::Data& data );
82 inline std::ostream& operator << ( std::ostream& os, const Cubic::Data& data );
83 inline std::ostream& operator << ( std::ostream& os, const Spline::Data& data );
84 inline std::ostream& operator << ( std::ostream& os, const Clothoid::Data& data );
85 inline std::ostream& operator << ( std::ostream& os, const Rotator::Data& data );
86 inline std::ostream& operator << ( std::ostream& os, const RotatorChain::Data& data );
87 inline std::ostream& operator << ( std::ostream& os, const PolygonalChain::Data& data );
88
89 inline std::istream& operator >> ( std::istream& is, LineP::Data& data );
90 inline std::istream& operator >> ( std::istream& is, Arc::Data& data );
91 inline std::istream& operator >> ( std::istream& is, ArcP::Data& data );
92 inline std::istream& operator >> ( std::istream& is, Helix::Data& data );
93 inline std::istream& operator >> ( std::istream& is, HelixP::Data& data );
94 inline std::istream& operator >> ( std::istream& is, CubicData& data );
95 inline std::istream& operator >> ( std::istream& is, Spline::Data& data );
96 inline std::istream& operator >> ( std::istream& is, Clothoid::Data& data );
97 inline std::istream& operator >> ( std::istream& is, Rotator::Data& data );
98 inline std::istream& operator >> ( std::istream& is, RotatorChain::Data& data );
99 inline std::istream& operator >> ( std::istream& is, PolygonalChain::Data& data );
100
101 inline std::ostream& operator << ( std::ostream& os, const PiecewiseTwist::Data& data );
102 inline std::istream& operator >> ( std::istream& is, PiecewiseTwist::Data& data );
103
104 inline std::ostream& operator << ( std::ostream& os, const EventFilter::Type& type );
105
106 inline std::istream& operator >> ( std::istream& is, EventFilter::Type& type );
107
108
109 inline std::ostream& operator << ( std::ostream& os, const JackEnumerator& jackenumerator );
110 inline std::ostream& operator << ( std::ostream& os, const Jack& jack );
111 inline std::ostream& operator << ( std::ostream& os, const Plug& plug );
112
114
115
116
117 inline std::ostream& operator << ( std::ostream& os, const Track::EndType& endType ){
118 os << "Track::EndType( " << ToString( endType ) << " )";
119 return os;
120 }
121
122 inline std::istream& operator >> ( std::istream& is, Track::EndType& endType ){
123 std::string token;
124 is >> token;
125 if( token != "Track::EndType(" )
126 throw std::runtime_error( "No Track::EndType" );
127
128 char c;
129 is >> token;
130 is >> c;
131
132 endType = ToEndType( token );
133 return is;
134 }
135
136 std::ostream& operator<<( std::ostream& os, const Track::End& end )
137 {
138 os << "Track::End( " << end.id << ", " << ToString(end.type) << " )";
139 return os;
140 }
141
142 std::istream& operator>>( std::istream& is, Track::End& end )
143 {
144 std::string token;
145 is >> token;
146 if( token != "Track::End(" )
147 throw std::runtime_error( "No Track::End" );
148
149 char c;
150 std::string typeStr;
151 is >> end.id;
152 is >> c; assert( c == ',' );
153 is >> typeStr;
154 end.type = ToEndType( typeStr );
155 is >> c; assert( c == ')' );
156 return is;
157 }
158
159 inline std::ostream& operator<<( std::ostream& ost, const Location& location )
160 {
162 location.Get( tlr );
163 ost << tlr;
164 return ost;
165 }
166
167 inline std::ostream& operator << ( std::ostream& ost, const TrackLocation& location ){
168 ost << "TrackLocation( " << location.parameter << ", " << location.orientation << " )";
169 return ost;
170 }
171
172 inline std::ostream& operator << ( std::ostream& ost, const TrackLocationRef& location ){
173 ost << "TrackLocationRef( " << location.refid << ", " << location.location << " )";
174 return ost;
175 }
176
177 inline std::ostream& operator << ( std::ostream& ost, const TrackRange& range ){
178 ost << "TrackRange( " << range.refid << ", " << range.range << " )";
179 return ost;
180 }
181
182 inline std::ostream& operator<<( std::ostream& ost, const Orientation& orient ){
183 ost << (orient == Orientation::Value::anti ? "anti" : "para");
184 return ost;
185 }
186
187 inline std::ostream& operator<<( std::ostream& ost, const Orientation::Value& orient ){
188 ost << (orient == Orientation::Value::anti ? "anti" : "para");
189 return ost;
190 }
191
192 inline std::ostream& operator<<(std::ostream& ost, NarrowSwitch::Status status){
193 ost << "NarrowSwitch::Status(" << ToString(status) << " )";
194 return ost;
195 }
196
197 inline std::ostream& operator << ( std::ostream& os, const LineP::Data& data ){
198 os << "LineP::Data( " << data.vb << ", " << data.up << " )";
199 return os;
200 }
201
202 inline std::ostream& operator << ( std::ostream& os, const Arc::Data& data ){
203 os << "Arc::Data( " << data.k << " )";
204 return os;
205 }
206
207 inline std::ostream& operator << ( std::ostream& os, const ArcP::Data& data ){
208 os << "ArcP::Data( " << data.vb2 << " )";
209 return os;
210 }
211
212 inline std::ostream& operator << ( std::ostream& os, const Helix::Data& data ){
213 os << "Helix::Data( " << data.k << ", " << data.t << " )";
214 return os;
215 }
216
217 inline std::ostream& operator << ( std::ostream& os, const HelixP::Data& data ){
218 os << "HelixP::Data( " << data.center << ", " << data.a << ", " << data.b << " )";
219 return os;
220 }
221
222 inline std::ostream& operator << ( std::ostream& os, const Cubic::Data& data ){
223 os << "Cubic::Data( " << data.a << ", " << data.b << ", " << data.c << ", " << data.d << " )";
224 return os;
225 }
226
227 inline std::ostream& operator << ( std::ostream& os, const Spline::Data& data ){
228 if( !data.empty() ){
229 os << "Spline::Data( " << data.front();
230 std::for_each(data.begin() + 1, data.end(), [&]( const CubicData& cubicData )
231 {
232 os << ", " << cubicData;
233 });
234 os << " )";
235 }
236
237 return os;
238 }
239
240 inline std::ostream& operator << ( std::ostream& os, const Clothoid::Data& data ){
241 os << "Clothoid::Data( " << data.a << " )";
242 return os;
243 }
244
245 inline std::ostream& operator << ( std::ostream& os, const Rotator::Data& data ){
246 os << "Rotator::Data( " << data.a << ", " << data.b << ", " << data.a0 << ", " << data.b0 << " )";
247 return os;
248 }
249
250 inline std::ostream& operator << ( std::ostream& os, const RotatorChain::Data& data ){
251 if( !data.empty() ){
252 os << "RotatorChain::Data( " << data.front();
253 std::for_each(data.begin() + 1, data.end(), [&]( const std::tuple<Angle,Angle,Length>& tuple )
254 {
255 os << ", " << tuple;
256 });
257 os << " )";
258 }
259
260 return os;
261 }
262
263 inline std::ostream& operator << ( std::ostream& os, const PolygonalChain::Data& data ){
264 if( !data.empty() ){
265 os << "PolygonalChain::Data( " << data.front();
266 std::for_each(data.begin() + 1, data.end(), [&]( const spat::VectorBundle<Length,One>& bundle )
267 {
268 os << ", " << bundle;
269 });
270 os << " )";
271 }
272
273 return os;
274 }
275
276 inline std::istream& operator >> ( std::istream& is, LineP::Data& data )
277 {
278 common::StreamInHead( is, "LineP::Data" );
279
280 char c;
281 is >> data.vb;
282 is >> c; assert( c == ',' );
283 is >> data.up;
284 is >> c; assert( c == ')' );
285 return is;
286 }
287
288 inline std::istream& operator >> ( std::istream& is, Arc::Data& data )
289 {
290 common::StreamInHead( is, "Arc::Data" );
291
292 char c;
293 is >> data.k;
294 is >> c; assert( c == ')' );
295 return is;
296 }
297
298 inline std::istream& operator >> ( std::istream& is, ArcP::Data& data )
299 {
300 common::StreamInHead( is, "ArcP::Data" );
301
302 char c;
303 is >> data.vb2;
304 is >> c; assert( c == ')' );
305 return is;
306 }
307
308 inline std::istream& operator >> ( std::istream& is, Helix::Data& data )
309 {
310 common::StreamInHead( is, "Helix::Data" );
311
312 char c;
313 is >> data.k;
314 is >> c; assert( c == ',' );
315 is >> data.t;
316 is >> c; assert( c == ')' );
317 return is;
318 }
319
320 inline std::istream& operator >> ( std::istream& is, HelixP::Data& data )
321 {
322 common::StreamInHead( is, "HelixP::Data" );
323
324 char c;
325 is >> data.center;
326 is >> c; assert( c == ',' );
327 is >> data.a;
328 is >> c; assert( c == ',' );
329 is >> data.b;
330 is >> c; assert( c == ')' );
331 return is;
332 }
333
334 inline std::istream& operator>>( std::istream& is, CubicData& data )
335 {
336 common::StreamInHead( is, "Cubic::Data" );
337
338 char c;
339 is >> data.a;
340 is >> c; assert( c == ',' );
341 is >> data.b;
342 is >> c; assert( c == ',' );
343 is >> data.c;
344 is >> c; assert( c == ',' );
345 is >> data.d;
346 is >> c; assert( c == ')' );
347 return is;
348 }
349
350 template<typename ValueType>
351 inline std::istream& StreamInVector( std::istream& is, std::vector<ValueType>& vector )
352 {
353 for(;;){
354 ValueType value;
355 is >> value;
356 vector.push_back( value );
357 char c;
358 is >> c;
359 if( c == ')' )
360 break;
361 assert( c == ',' );
362 }
363
364 return is;
365 }
366
367 inline std::istream& operator >> ( std::istream& is, Spline::Data& data )
368 {
369 common::StreamInHead( is, "Spline::Data" );
370 return StreamInVector( is, data );
371 }
372
373 inline std::istream& operator >> ( std::istream& is, Clothoid::Data& data )
374 {
375 common::StreamInHead( is, "Clothoid::Data" );
376
377 char c;
378 is >> data.a;
379 is >> c; assert( c == ')' );
380 return is;
381 }
382
383 inline std::istream& operator >> ( std::istream& is, Rotator::Data& data )
384 {
385 common::StreamInHead( is, "Rotator::Data" );
386
387 char c;
388 is >> data.a;
389 is >> c; assert( c == ',' );
390 is >> data.b;
391 is >> c; assert( c == ',' );
392 is >> data.a0;
393 is >> c; assert( c == ',' );
394 is >> data.b0;
395 is >> c; assert( c == ')' );
396 return is;
397 }
398
399 inline std::istream& operator >> ( std::istream& is, RotatorChain::Data& data )
400 {
401 common::StreamInHead( is, "RotatorChain::Data" );
402 return StreamInVector( is, data );
403 }
404
405 inline std::istream& operator >> ( std::istream& is, PolygonalChain::Data& data )
406 {
407 common::StreamInHead( is, "PolygonalChain::Data" );
408 return StreamInVector( is, data );
409 }
410
411 inline std::ostream& operator << ( std::ostream& os, const PiecewiseTwist::Data& data ){
412 if( !data.empty() ){
413 os << "PiecewiseTwist::Data( " << data.front();
414 std::for_each(data.begin() + 1, data.end(), [&]( const PiecewiseTwist::Data::value_type value )
415 {
416 os << ", " << value;
417 });
418 os << " )";
419 }
420
421 return os;
422 }
423
424 inline std::istream& operator >> ( std::istream& is, PiecewiseTwist::Data& data )
425 {
426 common::StreamInHead( is, "PiecewiseTwist::Data" );
427 return StreamInVector( is, data );
428 }
429
430 /*inline std::ostream& operator << ( std::ostream& os, const EventFilter::Type& type ){
431 os << "EventFilter::Type( " << EventFilter::From( type ) << " )";
432 return os;
433 }
434
435 inline std::istream& operator >> ( std::istream& is, EventFilter::Type& type ){
436 std::string token;
437 is >> token;
438 if( token != "EventFilter::Type(" )
439 throw std::runtime_error( "No EventFilter::Type" );
440
441 char c;
442 is >> token;
443 is >> c;
444
445 type = EventFilter::From( token );
446 return is;
447 }*/
448
449 inline std::ostream& operator<<( std::ostream& os, const JackEnumerator& jackenumerator )
450 {
451 os << "JackEnumerator( " << std::endl;
452 for( auto& Jack : jackenumerator )
453 {
454 os << Jack << ", " << std::endl;
455 }
456 os << " )";
457 return os;
458 }
459
460 inline std::ostream& operator<<( std::ostream& os, const Jack& jack )
461 {
462 os << jack.Reference( "name" ) << "[" << jack.Reference( "parent" ) << "]" << "( " << jack.ID() << ", ";
463 if( jack.GetPlug() )
464 os << *jack.GetPlug();
465 else
466 os << "0";
467 os << " )";
468 return os;
469 }
470
471 inline std::ostream& operator<<( std::ostream& os, const Plug& plug )
472 {
473 os << plug.Reference( "name" ) << "( " << plug.ID() << ", " << plug.JackOnPulse() << " )";
474 return os;
475 }
476}
477
478
Home of the Track and TrackBuilder interfaces.
A Location specifies a position on a track system by referencing a track and a TrackLocation on it.
Definition Location.h:110
dclspc void Get(TrackLocation &tl) const noexcept
Gets the TrackLocation - data of this track location.
std::istream & operator>>(std::istream &is, common::Interval< Valtype > &i)
Streams Interval data in.
Definition CommonSupportStream.h:72
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
dclspc Track::EndType ToEndType(const std::string &end)
Makes a status value from a status string.
Implements a Vector bundle.
Definition VectorBundle.h:42
Data definig the curve.
Definition Curve.h:613
AnglePerLength k
Curvature of the arc.
Definition Curve.h:614
Data definig the curve.
Definition Curve.h:681
spat::VectorBundle2< Length, One > vb2
Center point, tangent and normal of the arc. The curve radius is the length of vb2....
Definition Curve.h:696
Data defining the curve.
Definition Curve.h:1405
Length a
Single parameter to specify a clothoid.
Definition Curve.h:1406
Data definig a cubic curve.
Definition Curve.h:434
spat::Vector< Length > c
Definition Curve.h:463
spat::Position< Length > a
Definition Curve.h:461
spat::Vector< Length > b
Definition Curve.h:462
spat::Vector< Length > d
Definition Curve.h:464
CubicData Data
Data definig the curve.
Definition Curve.h:1073
Data definig the curve.
Definition Curve.h:823
AnglePerLength k
Curvature of the helix.
Definition Curve.h:834
AnglePerLength t
Torsion of the helix.
Definition Curve.h:835
Data definig the curve.
Definition Curve.h:915
Length a
radius (not curve radius)
Definition Curve.h:940
spat::VectorBundle2< Length, One > center
Definition Curve.h:938
Length b
b/a == tan(alpha) : slope
Definition Curve.h:941
virtual IDType ID() const noexcept=0
virtual const std::string & Reference(const std::string &name) const =0
Gets a reference that was set for this object by name.
Interface for enumerating the Jacks an object provides.
Definition Jack.h:177
A jack a plug can get connected with.
Definition Jack.h:83
virtual Plug * GetPlug() const noexcept=0
Gets a connected plug if any.
Data definig the curve.
Definition Curve.h:523
spat::VectorBundle< Length, One > vb
Position of parameter s=0 and tangent of the line.
Definition Curve.h:534
spat::Vector< One > up
Up direction.
Definition Curve.h:535
Status
Status.
Definition Switch.h:56
Provides two values for orientation.
Definition Orientation.h:37
Value
Values for orientation.
Definition Orientation.h:40
@ anti
Denoting the non parallel or opposite orientation.
Definition Orientation.h:42
A Plug of some object can get plugged into a jack of some object, specific to a certain event.
Definition Plug.h:57
virtual Jack & JackOnPulse() noexcept=0
Get a Jack that triggers a pulse if the Plug receives a pulse.
Data definig the curve.
Definition Curve.h:1580
Angle a0
Starting angle in the plain.
Definition Curve.h:1583
AnglePerLength b
Angular factor to rotate towards the up direction.
Definition Curve.h:1582
Angle b0
Starting angle.
Definition Curve.h:1584
AnglePerLength a
Angular factor to rotate in the plain.
Definition Curve.h:1581
std::vector< SegmentValueType > Data
Data defining the curve.
Definition Curve.h:1641
std::vector< SegmentValueType > Data
Data definig the curve.
Definition Curve.h:1183
Designates an end at a specific track.
Definition Track.h:303
EndType
Designates one of the two ends of a track.
Definition Track.h:292
A TrackLocation ist a location on a single track.
Definition TrackLocation.h:43
Orientation orientation
Orientation on the track. True means orientation in track direction.
Definition TrackLocation.h:45
Length parameter
Parameter along a track starting from Track::front.
Definition TrackLocation.h:44
A track location, referencing the track by id.
Definition TrackLocation.h:102
TrackLocation location
location on track.
Definition TrackLocation.h:103
IDType refid
ID of track.
Definition TrackLocation.h:104
An interval on a track, referenced by an id.
Definition TrackLocation.h:132
IDType refid
ID of track.
Definition TrackLocation.h:134
common::Interval< Length > range
range on track.
Definition TrackLocation.h:133