AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
LinkedSegmentRange.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. 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{
26 template<typename T>
28 {
29 public:
35
42
49
51
52
54
59
64
68 T* front() const;
69
73 T* back() const;
74
78 T* operator[]( agx::UInt rangeIndex ) const;
79
83 agx::UInt size() const;
84
88 agx::Bool empty() const;
89
90 private:
96 void updateSizeAndState();
98
99 private:
102 agx::UInt m_size;
103 };
104
105
106
107
108 template<typename T>
110 : m_begin()
111 , m_end()
112 , m_size(0)
113 {
114 }
115
116
117
118 template<typename T>
120 : m_begin( begin ), m_end( end ), m_size( 0u )
121 {
122 updateSizeAndState();
123 }
124
125
126
127 template<typename T>
129 : m_begin( begin ), m_end( m_begin.m_index, false, *m_begin.m_segments ), m_size( 0u )
130 {
131 // It's undefined, but possible, to create a range from begin to 10 * container.size().
132 // This assert alerts the user something's probably wrong in their algorithm.
133 // Note: numSegments == container.size() is valid since it can be the range from
134 // begin to end.
135 agxAssert( numSegments <= m_begin.m_segments->size() );
136
137 m_end.m_index += numSegments;
138 if ( m_end.m_index > m_end.m_segments->size() )
139 m_end.m_index = m_end.modSize( m_end.m_index, *m_end.m_segments );
140
141 updateSizeAndState();
142 }
143
144
145
146 template<typename T>
150
151
152
153 template<typename T>
155 {
156 this->m_begin = other.m_begin;
157 this->m_end = other.m_end;
158 this->m_size = other.m_size;
159
160 return *this;
161 }
162
163
164
165 template<typename T>
167 {
168 return m_begin;
169 }
170
171 template<typename T>
173 {
174 return m_end;
175 }
176
177 template<typename T>
179 {
180 if ( empty() )
181 return nullptr;
182
183 return *m_begin;
184 }
185
186 template<typename T>
188 {
189 if ( empty() )
190 return nullptr;
191
192 return *( --LinkedSegmentIterator<T>( m_end ) );
193 }
194
195 template<typename T>
196 inline T* LinkedSegmentRange<T>::operator[]( agx::UInt rangeIndex ) const
197 {
198 agxAssert( rangeIndex < m_size );
199 return LinkedSegmentIterator<T>::incremented( m_begin, rangeIndex ).get();
200 }
201
202 template<typename T>
204 {
205 return m_size;
206 }
207
208 template<typename T>
210 {
211 return m_size == 0ul;
212 }
213
214 template<typename T>
216 {
217 // Undefined to have container.end() as begin of this range.
218 agxAssert( m_begin.m_segments->empty() || m_begin.m_index != m_begin.m_segments->size() );
219
220 m_size = std::distance( m_begin, m_end );
221
222 // If this range passes begin/end the state of the end iterator should
223 // be the same as begin, enabling iterate from end to begin.
224 m_begin.setBoundarylessGivenEndOfRange( m_end );
225 m_end.m_boundaryless = m_begin.m_boundaryless;
226 }
227}
#define m_size
Definition agx/Vector.h:429
Optionally unbounded linked structure segment iterator object to iterate segments in a SegmentStructu...
static LinkedSegmentIterator incremented(const LinkedSegmentIterator &it, agx::UInt numSegments)
Segment range object for linked structure.
T * operator[](agx::UInt rangeIndex) const
LinkedSegmentRange()
Create an empty range.
agxSDK::LinkedSegmentRange< T > & operator=(const agxSDK::LinkedSegmentRange< T > &other)
agxSDK::LinkedSegmentIterator< T > begin() const
agxSDK::LinkedSegmentIterator< T > end() const
#define agxAssert(expr)
Definition debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition macros.h:96
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition Constraint.h:31
bool Bool
Definition Integer.h:40
uint64_t UInt
Definition Integer.h:27