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.The non-const iterator. 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 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
 

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) const
 
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
 Contained items by type. More...
 

Private Attributes

ITEM_PTR_VECTOR m_data [TYPES_COUNT]
 

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

Definition at line 167 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 const iterator.

Definition at line 164 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 170 of file multivector.h.

171  {
172  }

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 188 of file multivector.h.

189  {
190  int bucket = ( aType != UNDEFINED_TYPE ) ? aType : first();
191  return ITERATOR( this, operator[]( bucket ).begin(), bucket, aType );
192  }
ITERATOR begin(int aType=UNDEFINED_TYPE)
Definition: multivector.h:188
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 const iterator.
Definition: multivector.h:164
int first() const
< Get first non-empty type or first type if all are empty.
Definition: multivector.h:298

Referenced by MULTIVECTOR< LIB_ITEM, LIB_SHAPE_T, LIB_FIELD_T >::begin(), LIB_SYMBOL::Compare(), CADSTAR_SCH_ARCHIVE_LOADER::fixUpLibraryPins(), LIB_SYMBOL::GetNextDrawItem(), LIB_SYMBOL::SetConversion(), and LIB_SYMBOL::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 200 of file multivector.h.

201  {
202  int bucket = ( aType != UNDEFINED_TYPE ) ? aType : first();
203  return CONST_ITERATOR( this, operator[]( bucket ).begin(), bucket, aType );
204  }
ITERATOR begin(int aType=UNDEFINED_TYPE)
Definition: multivector.h:188
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
Definition: multivector.h:167
int first() const
< Get first non-empty type or first type if all are empty.
Definition: multivector.h:298

◆ 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 212 of file multivector.h.

213  {
214  if( aType != UNDEFINED_TYPE )
215  {
216  operator[]( aType ).clear();
217  }
218  else
219  {
220  for( int i = 0; i < TYPES_COUNT; ++i)
221  m_data[ i ].clear();
222  }
223  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Definition: multivector.h:320
static constexpr int TYPES_COUNT
Definition: multivector.h:294
void clear(int aType=UNDEFINED_TYPE)
Definition: multivector.h:212
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:265

Referenced by MULTIVECTOR< LIB_ITEM, LIB_SHAPE_T, LIB_FIELD_T >::clear(), LIB_SYMBOL::deleteAllFields(), and LIB_SYMBOL::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) const
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 194 of file multivector.h.

195  {
196  int bucket = ( aType != UNDEFINED_TYPE ) ? aType : last();
197  return ITERATOR( this, operator[]( bucket ).end(), bucket, aType );
198  }
ITERATOR end(int aType=UNDEFINED_TYPE)
Definition: multivector.h:194
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 const iterator.
Definition: multivector.h:164
int last() const
Contained items by type.
Definition: multivector.h:309

Referenced by LIB_SYMBOL::Compare(), MULTIVECTOR< LIB_ITEM, LIB_SHAPE_T, LIB_FIELD_T >::end(), CADSTAR_SCH_ARCHIVE_LOADER::fixUpLibraryPins(), LIB_SYMBOL::GetNextDrawItem(), MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::ITERATOR_BASE< ITEM_TYPE, ITEM_CONTAINER, ITEM_CONTAINER_IT >::operator++(), LIB_SYMBOL::SetConversion(), LIB_SYMBOL::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 206 of file multivector.h.

207  {
208  int bucket = ( aType != UNDEFINED_TYPE ) ? aType : last();
209  return CONST_ITERATOR( this, operator[]( bucket ).end(), bucket, aType );
210  }
ITERATOR end(int aType=UNDEFINED_TYPE)
Definition: multivector.h:194
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
Definition: multivector.h:167
int last() const
Contained items by type.
Definition: multivector.h:309

◆ 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 179 of file multivector.h.

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

Referenced by LIB_SYMBOL::RemoveDrawItem(), LIB_SYMBOL::SetConversion(), and LIB_SYMBOL::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.

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

Definition at line 298 of file multivector.h.

Referenced by MULTIVECTOR< LIB_ITEM, LIB_SHAPE_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

Contained items by type.

Definition at line 309 of file multivector.h.

Referenced by MULTIVECTOR< LIB_ITEM, LIB_SHAPE_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 265 of file multivector.h.

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

Referenced by MULTIVECTOR< LIB_ITEM, LIB_SHAPE_T, LIB_FIELD_T >::clear(), MULTIVECTOR< LIB_ITEM, LIB_SHAPE_T, LIB_FIELD_T >::push_back(), and MULTIVECTOR< LIB_ITEM, LIB_SHAPE_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 278 of file multivector.h.

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

◆ 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 225 of file multivector.h.

226  {
227  if( aType != UNDEFINED_TYPE )
228  {
229  return operator[]( aType ).size();
230  }
231  else
232  {
233  size_t cnt = 0;
234 
235  for( int i = 0; i < TYPES_COUNT; ++i)
236  cnt += m_data[ i ].size();
237 
238  return cnt;
239  }
240  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Definition: multivector.h:320
static constexpr int TYPES_COUNT
Definition: multivector.h:294
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:265
size_t size(int aType=UNDEFINED_TYPE) const
Definition: multivector.h:225

Referenced by LIB_SYMBOL::Compare(), MULTIVECTOR< LIB_ITEM, LIB_SHAPE_T, LIB_FIELD_T >::empty(), LIB_SYMBOL::GetFieldCount(), LIB_SYMBOL::GetPinCount(), MULTIVECTOR< LIB_ITEM, LIB_SHAPE_T, LIB_FIELD_T >::size(), and MULTIVECTOR< LIB_ITEM, LIB_SHAPE_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 247 of file multivector.h.

248  {
249  for( int i = 0; i < TYPES_COUNT; ++i )
250  m_data[ i ].sort();
251  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Definition: multivector.h:320
static constexpr int TYPES_COUNT
Definition: multivector.h:294
void sort()
Definition: multivector.h:247

Referenced by LIB_SYMBOL::AddDrawItem(), SCH_SCREEN::Append(), LIB_SYMBOL::operator=(), LIB_SYMBOL::SetConversion(), LIB_SYMBOL::SetFields(), LIB_SYMBOL::SetUnitCount(), and MULTIVECTOR< LIB_ITEM, LIB_SHAPE_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 256 of file multivector.h.

257  {
258  for( int i = 0; i < TYPES_COUNT; ++i )
259  {
260  if( m_data[ i ].size() > 1 )
261  m_data[ i ].unique();
262  }
263  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Definition: multivector.h:320
static constexpr int TYPES_COUNT
Definition: multivector.h:294
size_t size(int aType=UNDEFINED_TYPE) const
Definition: multivector.h:225

Referenced by LIB_SYMBOL::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: