Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
Jack.h
1// trax track library
2// AD 2014
3//
4// "Mr. Spock, sometimes I think if I hear that word 'frequency' once more, I'll cry."
5//
6// Lieutenant Uhura
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// The signal is the message.
28
29#pragma once
30
69
70#include "Configuration.h"
71#include "Identified.h"
72#include "ObjectID.h"
73
74#include <cassert>
75
76namespace trax{
77
78 struct Plug;
79 struct JackEnumerator;
80
82 struct Jack : Identified<Jack>
83 {
85 virtual const char* TypeName() const noexcept = 0;
86
87
89 virtual IDType RefPlugID() const noexcept = 0;
90
91
93 virtual void RefPlugID( IDType id ) noexcept = 0;
94
95
98 virtual void Pulse () noexcept = 0; // no parameters
99
100
104 virtual void Insert( Plug* pPlug ) noexcept = 0;
105
106
110 virtual void InsertAtTail( Plug* pPlug ) = 0;
111
112
115 virtual void InsertAndAppend( Plug* pPlug ) noexcept = 0;
116
117
120 virtual Plug* GetPlug() const noexcept = 0;
121
122
124 virtual bool Plugged() const noexcept = 0;
125
126
128 virtual void Clear() noexcept = 0;
129 };
130
131
132 class Jack_Imp : public ObjectID_Imp<Jack> {
133 public:
134 Jack_Imp() = delete;
135 Jack_Imp(const Jack_Imp& jack) = delete;
136 dclspc Jack_Imp(Jack_Imp&& jack) noexcept;
137 explicit dclspc Jack_Imp(const std::string& name);
138
139 Jack_Imp& operator=(const Jack_Imp&) = delete;
140 Jack_Imp& operator=(Jack_Imp&& jack) = delete;
141
142 dclspc ~Jack_Imp() noexcept;
143
144 dclspc const char* TypeName() const noexcept override;
145
146 IDType dclspc RefPlugID() const noexcept override;
147
148 void dclspc RefPlugID(IDType id) noexcept override;
149
150 void dclspc Pulse() noexcept override;
151
152 void dclspc Insert(Plug* pPlug) noexcept override;
153
154 void dclspc InsertAtTail(Plug* pPlug) override;
155
156 void dclspc InsertAndAppend(Plug* pPlug) noexcept override;
157
158 dclspc Plug* GetPlug() const noexcept override;
159
160 bool dclspc Plugged() const noexcept override;
161
162 void dclspc Clear() noexcept override;
163 private:
164 Plug* m_pPlug;
165 bool m_bPulsing;
166 IDType m_RefPlugID;
167
168 void DoClear() noexcept;
169 };
170
171
177 struct JackEnumerator{
178
181 typedef JackEnumerator collection_type;
182 typedef Jack value_type;
184
185
192 Jack& GetJack( int idx )
193 {
194 return const_cast<Jack&>(_GetJack( idx ));
195 }
196
197 const Jack& GetJack( int idx ) const{
198 return _GetJack( idx );
199 }
200
201
202
204 virtual int CountJacks() const = 0;
205
206
207 virtual ~JackEnumerator() = default;
208 protected:
209 JackEnumerator( const JackEnumerator& ) = default;
210 JackEnumerator( JackEnumerator&& ) = default;
211 JackEnumerator& operator=( const JackEnumerator& ) = default;
212 JackEnumerator& operator=( JackEnumerator&& ) = default;
213 JackEnumerator() = default;
214
215 virtual const Jack& _GetJack( int idx ) const = 0; // must be const; no forewarding of Jacks ...
216 };
217
218
219 template< class EnumeratorType,
220 class PointerType = Jack*,
221 class ReferenceType = Jack&>
222 class JackIterator{// : public std::iterator<std::random_access_iterator_tag,Jack,ptrdiff_t, PointerType, ReferenceType>{
223 public:
224 using iterator_category = std::random_access_iterator_tag;
225 using value_type = Jack;
226 using difference_type = ptrdiff_t;
227 using pointer = PointerType;
228 using reference = ReferenceType;
229
231 JackIterator( EnumeratorType& Container, bool bEnd = false )
232 : m_Container( Container ),
233 m_IndexCurrent( bEnd ? Container.CountJacks() : 0 )
234 {}
235
238 JackIterator& operator++() noexcept{
239 ++m_IndexCurrent;
240 return *this;
241 }
242
243 JackIterator operator++( int ){
244 JackIterator retval( *this );
245 operator++();
246 return retval;
247 }
248
249 ReferenceType operator*() const{
250 return m_Container.GetJack( m_IndexCurrent );
251 }
252
253 JackIterator& operator--(){
254 --m_IndexCurrent;
255 return *this;
256 }
257
258 JackIterator operator--( int ){
259 JackIterator retval( *this );
260 operator--();
261 return retval;
262 }
263
264 ReferenceType operator[]( int n ) const{
265 return m_Container.GetJack( m_IndexCurrent + n );
266 }
267
268 ReferenceType operator->() const{
269 return m_Container.GetJack( m_IndexCurrent );
270 }
271
272 bool operator==( const JackIterator& iter ) const{
273 assert( &m_Container == &iter.m_Container );
274 return m_IndexCurrent == iter.m_IndexCurrent;
275 }
276
277 bool operator!=( const JackIterator& iter ) const noexcept{
278 assert( &m_Container == &iter.m_Container );
279 return m_IndexCurrent != iter.m_IndexCurrent;
280 }
281
282 bool operator<( const JackIterator& iter ) const{
283 assert( &m_Container == &iter.m_Container );
284 return m_IndexCurrent < iter.m_IndexCurrent;
285 }
286
287 bool operator<=( const JackIterator& iter ) const{
288 assert( &m_Container == &iter.m_Container );
289 return m_IndexCurrent <= iter.m_IndexCurrent;
290 }
291
292 bool operator>( const JackIterator& iter ) const{
293 assert( &m_Container == &iter.m_Container );
294 return m_IndexCurrent > iter.m_IndexCurrent;
295 }
296
297 bool operator>=( const JackIterator& iter ) const{
298 assert( &m_Container == &iter.m_Container );
299 return m_IndexCurrent >= iter.m_IndexCurrent;
300 }
301
302 void operator+=( int n ){
303 m_IndexCurrent += n;
304 }
305
306 void operator-=( int n ){
307 m_IndexCurrent -= n;
308 }
309
310 JackIterator operator+( int n ) const{
311 JackIterator iter( *this );
312 iter.m_IndexCurrent += n;
313 }
314
315 JackIterator operator-( int n ) const{
316 JackIterator iter( *this );
317 iter.m_IndexCurrent -= n;
318 }
320 private:
321 EnumeratorType& m_Container;
322 int m_IndexCurrent;
323 };
324
325 inline JackIterator<JackEnumerator> begin( JackEnumerator& jackEnumerator ){
326 return JackIterator<JackEnumerator>( jackEnumerator );
327 }
328
329 inline JackIterator<const JackEnumerator,const Jack*, const Jack&> begin( const JackEnumerator& jackEnumerator ){
330 return JackIterator<const JackEnumerator, const Jack*, const Jack&>( jackEnumerator );
331 }
332
333 inline JackIterator<JackEnumerator> end( JackEnumerator& jackEnumerator ){
334 return JackIterator<JackEnumerator>( jackEnumerator, true );
335 }
336
337 inline JackIterator<const JackEnumerator, const Jack*, const Jack&> end( const JackEnumerator& jackEnumerator ){
338 return JackIterator<const JackEnumerator, const Jack*, const Jack&>( jackEnumerator, true );
339 }
340}
void dclspc Pulse() noexcept override
This function gets called from the owner of a Jack on a certain event.
void dclspc InsertAndAppend(Plug *pPlug) noexcept override
Inserts the plug at this Jack. If a plug is already inserted this will be appended into pPlug's Jack.
void dclspc Clear() noexcept override
Clear the Jack from any plug.
dclspc Plug * GetPlug() const noexcept override
Gets a connected plug if any.
void dclspc InsertAtTail(Plug *pPlug) override
Inserts the plug at this Jack if no plug is already inserted. Inserts it at the tail of this plug cha...
dclspc const char * TypeName() const noexcept override
bool dclspc Plugged() const noexcept override
Is a Plug already plugged into this jack?
void dclspc Insert(Plug *pPlug) noexcept override
Connects together a Plug with a Jack.
IDType dclspc RefPlugID() const noexcept override
Definition Jack.h:222
JackIterator(EnumeratorType &Container, bool bEnd=false)
Construction.
Definition Jack.h:231
Definition ObjectID.h:38
constexpr auto operator*(const Interval< Valtype > &i1, Valtype2 scalar) noexcept -> Interval< decltype(Valtype{} *Valtype2{})>
Interval operator.
Definition Interval.h:628
constexpr bool operator!=(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Interval operator.
Definition Interval.h:701
constexpr bool operator>(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Definition Interval.h:665
void operator+=(Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Interval operator.
Definition Interval.h:586
constexpr bool operator==(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Interval operator.
Definition Interval.h:696
constexpr bool operator<(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Definition Interval.h:657
constexpr Interval< Valtype > operator+(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Interval operator.
Definition Interval.h:591
constexpr Interval< Valtype > operator-(const Interval< Valtype > &i1, Valtype l) noexcept
Interval operator.
Definition Interval.h:613
constexpr Value< Dimension< L, M, T > > & operator-=(Value< Dimension< L, M, T > > &a, const Value< Dimension< L, M, T > > &b) noexcept
Dimensionated Values operator.
Definition DimensionedValues.h:490
constexpr bool operator>=(const Value< Dimension< L, M, T > > &a, const Value< Dimension< L, M, T > > &b) noexcept
Dimensionated Values operator.
Definition DimensionedValues.h:659
constexpr bool operator<=(const Value< Dimension< L, M, T > > &a, const Value< Dimension< L, M, T > > &b) noexcept
Dimensionated Values operator.
Definition DimensionedValues.h:655
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
Type used for IDs in the trax library.
Definition IDType.h:43
Interface for enumerating the Jacks an object provides.
Definition Jack.h:177
virtual int CountJacks() const =0
Jack & GetJack(int idx)
Definition Jack.h:192
const Jack & GetJack(int idx) const
Definition Jack.h:197
A jack a plug can get connected with.
Definition Jack.h:83
virtual Plug * GetPlug() const noexcept=0
Gets a connected plug if any.
virtual IDType RefPlugID() const noexcept=0
virtual void Pulse() noexcept=0
This function gets called from the owner of a Jack on a certain event.
virtual void InsertAndAppend(Plug *pPlug) noexcept=0
Inserts the plug at this Jack. If a plug is already inserted this will be appended into pPlug's Jack.
virtual void InsertAtTail(Plug *pPlug)=0
Inserts the plug at this Jack if no plug is already inserted. Inserts it at the tail of this plug cha...
virtual const char * TypeName() const noexcept=0
virtual bool Plugged() const noexcept=0
Is a Plug already plugged into this jack?
virtual void Insert(Plug *pPlug) noexcept=0
Connects together a Plug with a Jack.
virtual void Clear() noexcept=0
Clear the Jack from any plug.
A Plug of some object can get plugged into a jack of some object, specific to a certain event.
Definition Plug.h:57