AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
LinkedSegmentIterator.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
20
21namespace agxSDK
22{
27 template<typename T>
29 {
30 public:
35
40
47
48 public:
49
55
63
64
69 LinkedSegmentIterator( T* segment );
70
76
82 LinkedSegmentIterator& operator= ( const LinkedSegmentIterator& other );
84
85
88 agx::Bool operator== ( const LinkedSegmentIterator& other ) const;
89
93 agx::Bool operator!= ( const LinkedSegmentIterator& other ) const;
94
101
108
115
122
126 LinkedSegmentIterator operator+ ( agx::UInt numSegments ) const;
127
131 LinkedSegmentIterator operator- ( agx::UInt numSegments ) const;
132
136 agx::UInt operator- ( const LinkedSegmentIterator& other ) const;
137
141 T* operator* () const;
142
143 T* operator-> () const;
144
148 T* get() const;
149
155
161
166
171
175 agx::Bool equals( const LinkedSegmentIterator& other ) const;
176
180 agx::UInt index() const;
181
186
191
196
200 agx::Bool isEnd() const;
201
202 private:
206 static agx::UInt modSize( agx::UInt index, const LinkedSegmentContainer& segments );
207
208 private:
209 const LinkedSegmentContainer* containerPtr() const;
210
211 template<typename U>
212 friend class LinkedSegmentRange;
213 void setBoundarylessGivenEndOfRange( const LinkedSegmentIterator& end );
214
215 private:
216 agx::UInt m_index;
217 agx::Bool m_boundaryless;
218 const LinkedSegmentContainer* m_segments;
219 };
220
221 template<typename T>
223 {
224 return LinkedSegmentIterator( 0u, false, segments );
225 }
226
227 template<typename T>
229 {
230 return LinkedSegmentIterator( segments.size(), false, segments );
231 }
232
233 template<typename T>
235 agx::UInt numSegments )
236 {
237 return LinkedSegmentIterator( it.m_index + numSegments, true, *it.m_segments );
238 }
239
240
241
242 template<typename T>
244 : m_index(agx::InvalidIndex)
245 , m_boundaryless(false)
246 , m_segments(nullptr)
247 {
248 }
249
250
251
252 template<typename T>
254 agx::Bool boundaryless,
255 const LinkedSegmentContainer& segments )
256 : m_index( boundaryless ?
257 modSize( index, segments ) :
258 std::min<agx::UInt>( index, segments.size() ) ),
259 m_boundaryless( boundaryless ),
260 m_segments( &segments )
261 {
262 }
263
264 template<typename T>
266 : m_index( segment->getIndex() )
267 , m_boundaryless( false )
268 , m_segments( &segment->getLinkedStructure()->getSegmentsContainer() )
269 {
270 }
271
272 template<typename T>
274 : m_index( other.m_index ), m_boundaryless( other.m_boundaryless ), m_segments( other.m_segments )
275 {
276 }
277
278
279
280 template<typename T>
282 {
283 this->m_index = other.m_index;
284 this->m_boundaryless = other.m_boundaryless;
285 this->m_segments = other.m_segments;
286
287 return *this;
288 }
289
290
291
292 template<typename T>
294 {
295 return m_index == other.m_index && containerPtr() == other.containerPtr();
296 }
297
298 template<typename T>
300 {
301 return !( *this == other );
302 }
303
304 template<typename T>
306 {
307 m_index = findNextIndex( m_index );
308 return *this;
309 }
310
311 template<typename T>
313 {
314 LinkedSegmentIterator it( *this );
315 ++(*this);
316 return it;
317 }
318
319 template<typename T>
321 {
322 m_index = findPrevIndex( m_index );
323 return *this;
324 }
325
326 template<typename T>
328 {
329 LinkedSegmentIterator it( *this );
330 --(*this);
331 return it;
332 }
333
334 template<typename T>
336 {
337 const auto newIndex = m_index + numSegments;
338 if ( m_boundaryless )
339 return LinkedSegmentIterator( modSize( newIndex, *m_segments ), true, *m_segments );
340 return LinkedSegmentIterator( std::min<agx::UInt>( newIndex, m_segments->size() ), false, *m_segments );
341 }
342
343 template<typename T>
345 {
346 if ( numSegments > m_index )
347 return m_boundaryless ?
348 LinkedSegmentIterator( m_segments->size() + m_index - numSegments, true, *m_segments ) :
349 LinkedSegmentIterator::begin( *m_segments );
350 return LinkedSegmentIterator( m_index - numSegments, m_boundaryless, *m_segments );
351 }
352
353 template<typename T>
355 {
356 agxAssert( containerPtr() == other.containerPtr() );
357 return other.m_index <= m_index ?
358 m_index - other.m_index :
359 m_index + ( m_segments->size() - other.m_index );
360 }
361
362 template<typename T>
364 {
365 return get();
366 }
367
368 template<typename T>
370 {
371 return get();
372 }
373
374 template<typename T>
376 {
377 return (*m_segments)[ m_index ]->template as<T>();
378 }
379
380 template<typename T>
382 {
383 return ++(*this);
384 }
385
386 template<typename T>
388 {
389 return --(*this);
390 }
391
392 template<typename T>
394 {
395 LinkedSegmentIterator copy( *this );
396 return ++copy;
397 }
398
399 template<typename T>
401 {
402 LinkedSegmentIterator copy( *this );
403 return --copy;
404 }
405
406 template<typename T>
408 {
409 return (*this) == other;
410 }
411
412 template<typename T>
414 {
415 return m_index;
416 }
417
418 template<typename T>
420 {
421 agxAssert( m_boundaryless || index < m_segments->size() );
422 return m_boundaryless ?
423 modSize( index + 1, *m_segments ) :
424 index + 1;
425 }
426
427 template<typename T>
429 {
430 agxAssert( m_boundaryless || index > 0 );
431 return m_boundaryless &&
432 index == 0 ?
433 m_segments->size() - 1 :
434 index - 1;
435 }
436
437 template<typename T>
439 {
440 return m_boundaryless;
441 }
442
443
444 template <typename T>
446 {
447 return m_index == agx::InvalidIndex || m_segments == nullptr || m_index == m_segments->size();
448 }
449
450 template<typename T>
452 {
453 return segments.empty() ?
454 0ul :
455 ( index % segments.size() );
456 }
457
458 template<typename T>
459 inline const LinkedSegmentContainer* LinkedSegmentIterator<T>::containerPtr() const
460 {
461 return m_segments;
462 }
463
464 template<typename T>
465 inline void LinkedSegmentIterator<T>::setBoundarylessGivenEndOfRange( const LinkedSegmentIterator& end )
466 {
467 m_boundaryless = m_index > end.m_index;
468 }
469}
470
472namespace std
473{
474 template<typename T>
475 struct iterator_traits<agxSDK::LinkedSegmentIterator<T>>
476 {
477 using difference_type = agx::UInt;
478 using value_type = T*;
479 using iterator_category = std::random_access_iterator_tag;
480 };
481}
483
Optionally unbounded linked structure segment iterator object to iterate segments in a SegmentStructu...
LinkedSegmentIterator operator+(agx::UInt numSegments) const
LinkedSegmentIterator prev() const
agx::Bool equals(const LinkedSegmentIterator &other) const
LinkedSegmentIterator()
Create an iterator that doesn't point anywhere.
LinkedSegmentIterator & inc()
Increments this by one (same as ++it).
agx::UInt findPrevIndex(agx::UInt index) const
LinkedSegmentIterator & operator--()
Decrement this iterator by one.
LinkedSegmentIterator & dec()
Decrements this by one (same as –it).
agx::Bool operator!=(const LinkedSegmentIterator &other) const
static LinkedSegmentIterator begin(const agxSDK::LinkedSegmentContainer &segments)
LinkedSegmentIterator next() const
agx::UInt findNextIndex(agx::UInt index) const
LinkedSegmentIterator & operator++()
Increment this iterator by one.
static LinkedSegmentIterator end(const agxSDK::LinkedSegmentContainer &segments)
LinkedSegmentIterator operator-(agx::UInt numSegments) const
agx::Bool operator==(const LinkedSegmentIterator &other) const
static LinkedSegmentIterator incremented(const LinkedSegmentIterator &it, agx::UInt numSegments)
Segment range object for linked structure.
bool empty() const
Definition: Container.h:136
size_t size() const
Definition: Container.h:134
#define agxAssert(expr)
Definition: debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
agx::Vector< agxSDK::LinkedSegmentRef > LinkedSegmentContainer
Definition: LinkedSegment.h:29
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
bool Bool
Definition: Integer.h:40
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
uint64_t UInt
Definition: Integer.h:27
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
STL namespace.