KiCad PCB EDA Suite
MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL > Class Template Reference

Multivector container type. More...

#include <multivector.h>

Classes

class  ITERATOR_BASE
 Generic implementation of a flat const/non-const iterator over contained items. More...
 

Public Types

typedef boost::ptr_vector< T > ITEM_PTR_VECTOR
 Helper for defining a list of library draw object pointers. More...
 
typedef ITERATOR_BASE< T, MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::iterator > ITERATOR
 

The non-const iterator

More...
 
typedef ITERATOR_BASE< const T, const MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::const_iterator > CONST_ITERATOR
 

The const iterator

More...
 

Public Member Functions

 MULTIVECTOR ()
 
void push_back (T *aItem)
 
ITERATOR erase (const ITERATOR &aIterator)
 
ITERATOR begin (int aType=UNDEFINED_TYPE)
 
ITERATOR end (int aType=UNDEFINED_TYPE)
 
CONST_ITERATOR begin (int aType=UNDEFINED_TYPE) const
 
CONST_ITERATOR end (int aType=UNDEFINED_TYPE) const
 
void clear (int aType=UNDEFINED_TYPE)
 
size_t size (int aType=UNDEFINED_TYPE) const
 
bool empty (int aType=UNDEFINED_TYPE)
 
void sort ()
 
void unique ()
 Remove duplicate elements in list. More...
 
ITEM_PTR_VECTORoperator[] (int aType)
 
const ITEM_PTR_VECTORoperator[] (int aType) const
 

Static Public Attributes

static constexpr int UNDEFINED_TYPE = 0
 Type value to indicate no specific type. More...
 
static constexpr int FIRST_TYPE = FIRST_TYPE_VAL
 
static constexpr int LAST_TYPE = LAST_TYPE_VAL
 
static constexpr int TYPES_COUNT = LAST_TYPE - FIRST_TYPE + 1
 

Private Member Functions

int first () const
 

Get first non-empty type or first type if all are empty.

More...
 
int last () const
 

Get last non-empty type or first type if all are empty.

More...
 

Private Attributes

ITEM_PTR_VECTOR m_data [TYPES_COUNT]
 

Contained items by type

More...
 

Detailed Description

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
class MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >

Multivector container type.

Keeps items segregated by their type in multiple ptr_vectors. Provides both access as a flat list as well as access by type of item.

T is the stored type, needs to provide Type() method used to segregate items. FIRST_TYPE_VAL is the lower boundary value of the types stored in the container. LAST_TYPE_VAL is the upper boundary value of the types stored in the container.

Definition at line 45 of file multivector.h.

Member Typedef Documentation

◆ CONST_ITERATOR

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
typedef ITERATOR_BASE<const T, const MULTIVECTOR<T, FIRST_TYPE_VAL, LAST_TYPE_VAL>, typename ITEM_PTR_VECTOR::const_iterator> MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::CONST_ITERATOR

The const iterator

Definition at line 168 of file multivector.h.

◆ ITEM_PTR_VECTOR

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
typedef boost::ptr_vector<T> MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::ITEM_PTR_VECTOR

Helper for defining a list of library draw object pointers.

The Boost pointer containers are responsible for deleting object pointers placed in them. If you access a object pointer from the list, do not delete it directly.

Definition at line 54 of file multivector.h.

◆ ITERATOR

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
typedef ITERATOR_BASE<T, MULTIVECTOR<T, FIRST_TYPE_VAL, LAST_TYPE_VAL>, typename ITEM_PTR_VECTOR::iterator> MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::ITERATOR

The non-const iterator

Definition at line 165 of file multivector.h.

Constructor & Destructor Documentation

◆ MULTIVECTOR()

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::MULTIVECTOR ( )
inline

Definition at line 171 of file multivector.h.

172  {
173  }

Member Function Documentation

◆ begin() [1/2]

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
ITERATOR MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::begin ( int  aType = UNDEFINED_TYPE)
inline

Definition at line 189 of file multivector.h.

190  {
191  int bucket = ( aType != UNDEFINED_TYPE ) ? aType : first();
192  return ITERATOR( this, operator[]( bucket ).begin(), bucket, aType );
193  }
ITERATOR begin(int aType=UNDEFINED_TYPE)
Definition: multivector.h:189
static constexpr int UNDEFINED_TYPE
Type value to indicate no specific type.
Definition: multivector.h:52
ITERATOR_BASE< T, MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::iterator > ITERATOR
The non-const iterator
Definition: multivector.h:165
int first() const
Get first non-empty type or first type if all are empty.
Definition: multivector.h:299

Referenced by MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T >::begin(), LIB_PART::Compare(), LIB_PART::GetNextDrawItem(), LIB_PART::SetConversion(), and LIB_PART::SetUnitCount().

◆ begin() [2/2]

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
CONST_ITERATOR MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::begin ( int  aType = UNDEFINED_TYPE) const
inline

Definition at line 201 of file multivector.h.

202  {
203  int bucket = ( aType != UNDEFINED_TYPE ) ? aType : first();
204  return CONST_ITERATOR( this, operator[]( bucket ).begin(), bucket, aType );
205  }
ITERATOR begin(int aType=UNDEFINED_TYPE)
Definition: multivector.h:189
static constexpr int UNDEFINED_TYPE
Type value to indicate no specific type.
Definition: multivector.h:52
ITERATOR_BASE< const T, const MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::const_iterator > CONST_ITERATOR
The const iterator
Definition: multivector.h:168
int first() const
Get first non-empty type or first type if all are empty.
Definition: multivector.h:299

◆ clear()

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
void MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::clear ( int  aType = UNDEFINED_TYPE)
inline

Definition at line 213 of file multivector.h.

214  {
215  if( aType != UNDEFINED_TYPE )
216  {
217  operator[]( aType ).clear();
218  }
219  else
220  {
221  for( int i = 0; i < TYPES_COUNT; ++i)
222  m_data[ i ].clear();
223  }
224  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Contained items by type
Definition: multivector.h:321
static constexpr int TYPES_COUNT
Definition: multivector.h:295
void clear(int aType=UNDEFINED_TYPE)
Definition: multivector.h:213
static constexpr int UNDEFINED_TYPE
Type value to indicate no specific type.
Definition: multivector.h:52
ITEM_PTR_VECTOR & operator[](int aType)
Definition: multivector.h:266

Referenced by MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T >::clear(), LIB_PART::deleteAllFields(), NESTED_SETTINGS::LoadFromFile(), and LIB_PART::operator=().

◆ empty()

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
bool MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::empty ( int  aType = UNDEFINED_TYPE)
inline

◆ end() [1/2]

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
ITERATOR MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::end ( int  aType = UNDEFINED_TYPE)
inline

Definition at line 195 of file multivector.h.

196  {
197  int bucket = ( aType != UNDEFINED_TYPE ) ? aType : last();
198  return ITERATOR( this, operator[]( bucket ).end(), bucket, aType );
199  }
ITERATOR end(int aType=UNDEFINED_TYPE)
Definition: multivector.h:195
static constexpr int UNDEFINED_TYPE
Type value to indicate no specific type.
Definition: multivector.h:52
ITERATOR_BASE< T, MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::iterator > ITERATOR
The non-const iterator
Definition: multivector.h:165
int last() const
Get last non-empty type or first type if all are empty.
Definition: multivector.h:310

Referenced by LIB_PART::Compare(), MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T >::end(), LIB_PART::GetNextDrawItem(), MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::ITERATOR_BASE< ITEM_TYPE, ITEM_CONTAINER, ITEM_CONTAINER_IT >::operator++(), LIB_PART::SetConversion(), LIB_PART::SetUnitCount(), and MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::ITERATOR_BASE< ITEM_TYPE, ITEM_CONTAINER, ITEM_CONTAINER_IT >::validate().

◆ end() [2/2]

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
CONST_ITERATOR MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::end ( int  aType = UNDEFINED_TYPE) const
inline

Definition at line 207 of file multivector.h.

208  {
209  int bucket = ( aType != UNDEFINED_TYPE ) ? aType : last();
210  return CONST_ITERATOR( this, operator[]( bucket ).end(), bucket, aType );
211  }
ITERATOR end(int aType=UNDEFINED_TYPE)
Definition: multivector.h:195
static constexpr int UNDEFINED_TYPE
Type value to indicate no specific type.
Definition: multivector.h:52
ITERATOR_BASE< const T, const MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::const_iterator > CONST_ITERATOR
The const iterator
Definition: multivector.h:168
int last() const
Get last non-empty type or first type if all are empty.
Definition: multivector.h:310

◆ erase()

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
ITERATOR MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::erase ( const ITERATOR aIterator)
inline

Definition at line 180 of file multivector.h.

181  {
182  ITERATOR it( aIterator );
183  it.m_it = (*aIterator.m_parent)[ aIterator.m_curType ].erase( aIterator.m_it );
184  it.validate();
185 
186  return it;
187  }
ITERATOR_BASE< T, MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::iterator > ITERATOR
The non-const iterator
Definition: multivector.h:165

Referenced by LIB_PART::RemoveDrawItem(), LIB_PART::SetConversion(), and LIB_PART::SetUnitCount().

◆ first()

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
int MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::first ( ) const
inlineprivate

Get first non-empty type or first type if all are empty.

Definition at line 299 of file multivector.h.

300  {
301  int i = 0;
302 
303  while( ( i < TYPES_COUNT ) && ( m_data[ i ].empty() ) )
304  ++i;
305 
306  return ( i == TYPES_COUNT ) ? FIRST_TYPE : FIRST_TYPE + i;
307  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Contained items by type
Definition: multivector.h:321
bool empty(int aType=UNDEFINED_TYPE)
Definition: multivector.h:243
static constexpr int TYPES_COUNT
Definition: multivector.h:295
static constexpr int FIRST_TYPE
Definition: multivector.h:293

Referenced by MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T >::begin().

◆ last()

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
int MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::last ( ) const
inlineprivate

Get last non-empty type or first type if all are empty.

Definition at line 310 of file multivector.h.

311  {
312  int i = TYPES_COUNT - 1;
313 
314  while( ( i >= 0 ) && ( m_data[ i ].empty() ) )
315  --i;
316 
317  return ( i < 0 ) ? FIRST_TYPE : FIRST_TYPE + i;
318  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Contained items by type
Definition: multivector.h:321
bool empty(int aType=UNDEFINED_TYPE)
Definition: multivector.h:243
static constexpr int TYPES_COUNT
Definition: multivector.h:295
static constexpr int FIRST_TYPE
Definition: multivector.h:293

Referenced by MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T >::end().

◆ operator[]() [1/2]

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
ITEM_PTR_VECTOR& MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::operator[] ( int  aType)
inline

Definition at line 266 of file multivector.h.

267  {
268  if( ( aType < FIRST_TYPE ) || ( aType > LAST_TYPE ) )
269  {
270  wxFAIL_MSG( "Attempted access to type not within MULTIVECTOR" );
271 
272  // return type is a reference so we have to return something...
273  aType = FIRST_TYPE;
274  }
275 
276  return m_data[ aType - FIRST_TYPE ];
277  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Contained items by type
Definition: multivector.h:321
static constexpr int LAST_TYPE
Definition: multivector.h:294
static constexpr int FIRST_TYPE
Definition: multivector.h:293

Referenced by MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T >::clear(), MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T >::push_back(), and MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T >::size().

◆ operator[]() [2/2]

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
const ITEM_PTR_VECTOR& MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::operator[] ( int  aType) const
inline

Definition at line 279 of file multivector.h.

280  {
281  if( ( aType < FIRST_TYPE ) || ( aType > LAST_TYPE ) )
282  {
283  wxFAIL_MSG( "Attempted access to type not within MULTIVECTOR" );
284 
285  // return type is a reference so we have to return something...
286  aType = FIRST_TYPE;
287  }
288 
289  return m_data[ aType - FIRST_TYPE ];
290  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Contained items by type
Definition: multivector.h:321
static constexpr int LAST_TYPE
Definition: multivector.h:294
static constexpr int FIRST_TYPE
Definition: multivector.h:293

◆ push_back()

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
void MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::push_back ( T *  aItem)
inline

◆ size()

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
size_t MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::size ( int  aType = UNDEFINED_TYPE) const
inline

Definition at line 226 of file multivector.h.

227  {
228  if( aType != UNDEFINED_TYPE )
229  {
230  return operator[]( aType ).size();
231  }
232  else
233  {
234  size_t cnt = 0;
235 
236  for( int i = 0; i < TYPES_COUNT; ++i)
237  cnt += m_data[ i ].size();
238 
239  return cnt;
240  }
241  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Contained items by type
Definition: multivector.h:321
static constexpr int TYPES_COUNT
Definition: multivector.h:295
static constexpr int UNDEFINED_TYPE
Type value to indicate no specific type.
Definition: multivector.h:52
ITEM_PTR_VECTOR & operator[](int aType)
Definition: multivector.h:266
size_t size(int aType=UNDEFINED_TYPE) const
Definition: multivector.h:226

Referenced by LIB_PART::Compare(), MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T >::empty(), LIB_PART::GetPinCount(), MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T >::size(), and MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T >::unique().

◆ sort()

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
void MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::sort ( )
inline

Definition at line 248 of file multivector.h.

249  {
250  for( int i = 0; i < TYPES_COUNT; ++i )
251  m_data[ i ].sort();
252  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Contained items by type
Definition: multivector.h:321
static constexpr int TYPES_COUNT
Definition: multivector.h:295
void sort()
Definition: multivector.h:248

Referenced by SCH_LEGACY_PLUGIN_CACHE::SaveSymbol(), and MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T >::sort().

◆ unique()

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
void MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::unique ( )
inline

Remove duplicate elements in list.

Definition at line 257 of file multivector.h.

258  {
259  for( int i = 0; i < TYPES_COUNT; ++i )
260  {
261  if( m_data[ i ].size() > 1 )
262  m_data[ i ].unique();
263  }
264  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Contained items by type
Definition: multivector.h:321
static constexpr int TYPES_COUNT
Definition: multivector.h:295
size_t size(int aType=UNDEFINED_TYPE) const
Definition: multivector.h:226

Referenced by LIB_PART::RemoveDuplicateDrawItems().

Member Data Documentation

◆ FIRST_TYPE

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
constexpr int MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::FIRST_TYPE = FIRST_TYPE_VAL
static

◆ LAST_TYPE

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
constexpr int MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::LAST_TYPE = LAST_TYPE_VAL
static

◆ m_data

◆ TYPES_COUNT

◆ UNDEFINED_TYPE

template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
constexpr int MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::UNDEFINED_TYPE = 0
static

The documentation for this class was generated from the following file: