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
 
size_t size (int aType=UNDEFINED_TYPE)
 
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 43 of file multivector.h.

Member Typedef Documentation

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

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

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

Constructor & Destructor Documentation

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

Definition at line 165 of file multivector.h.

166  {
167  }

Member Function Documentation

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

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

184  {
185  int bucket = ( aType != UNDEFINED_TYPE ) ? aType : first();
186  return ITERATOR( this, operator[]( bucket ).begin(), bucket, aType );
187  }
ITERATOR begin(int aType=UNDEFINED_TYPE)
Definition: multivector.h:183
static constexpr int UNDEFINED_TYPE
Type value to indicate no specific type.
Definition: multivector.h:50
int first() const
Get first non-empty type or first type if all are empty.
Definition: multivector.h:270
ITERATOR_BASE< T, MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::iterator > ITERATOR
The non-const iterator
Definition: multivector.h:160
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 195 of file multivector.h.

196  {
197  int bucket = ( aType != UNDEFINED_TYPE ) ? aType : first();
198  return CONST_ITERATOR( this, operator[]( bucket ).begin(), bucket, aType );
199  }
ITERATOR begin(int aType=UNDEFINED_TYPE)
Definition: multivector.h:183
static constexpr int UNDEFINED_TYPE
Type value to indicate no specific type.
Definition: multivector.h:50
int first() const
Get first non-empty type or first type if all are empty.
Definition: multivector.h:270
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:162
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
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 189 of file multivector.h.

Referenced by LIB_EDIT_FRAME::BlockDeleteSelectedItems(), 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().

190  {
191  int bucket = ( aType != UNDEFINED_TYPE ) ? aType : last();
192  return ITERATOR( this, operator[]( bucket ).end(), bucket, aType );
193  }
int last() const
Get last non-empty type or first type if all are empty.
Definition: multivector.h:281
ITERATOR end(int aType=UNDEFINED_TYPE)
Definition: multivector.h:189
static constexpr int UNDEFINED_TYPE
Type value to indicate no specific type.
Definition: multivector.h:50
ITERATOR_BASE< T, MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::iterator > ITERATOR
The non-const iterator
Definition: multivector.h:160
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 201 of file multivector.h.

202  {
203  int bucket = ( aType != UNDEFINED_TYPE ) ? aType : last();
204  return CONST_ITERATOR( this, operator[]( bucket ).end(), bucket, aType );
205  }
int last() const
Get last non-empty type or first type if all are empty.
Definition: multivector.h:281
ITERATOR end(int aType=UNDEFINED_TYPE)
Definition: multivector.h:189
static constexpr int UNDEFINED_TYPE
Type value to indicate no specific type.
Definition: multivector.h:50
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:162
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 174 of file multivector.h.

Referenced by LIB_EDIT_FRAME::BlockDeleteSelectedItems(), LIB_PART::SetConversion(), and LIB_PART::SetUnitCount().

175  {
176  ITERATOR it( aIterator );
177  it.m_it = (*aIterator.m_parent)[ aIterator.m_curType ].erase( aIterator.m_it );
178  it.validate();
179 
180  return it;
181  }
ITERATOR_BASE< T, MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::iterator > ITERATOR
The non-const iterator
Definition: multivector.h:160
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 270 of file multivector.h.

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

271  {
272  int i = 0;
273 
274  while( ( i < TYPES_COUNT ) && ( m_data[ i ].empty() ) )
275  ++i;
276 
277  return ( i == TYPES_COUNT ) ? FIRST_TYPE : FIRST_TYPE + i;
278  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Contained items by type
Definition: multivector.h:292
bool empty(int aType=UNDEFINED_TYPE)
Definition: multivector.h:224
static constexpr int TYPES_COUNT
Definition: multivector.h:266
static constexpr int FIRST_TYPE
Definition: multivector.h:264
size_t i
Definition: json11.cpp:597
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 281 of file multivector.h.

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

282  {
283  int i = TYPES_COUNT - 1;
284 
285  while( ( i >= 0 ) && ( m_data[ i ].empty() ) )
286  --i;
287 
288  return ( i < 0 ) ? FIRST_TYPE : FIRST_TYPE + i;
289  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Contained items by type
Definition: multivector.h:292
bool empty(int aType=UNDEFINED_TYPE)
Definition: multivector.h:224
static constexpr int TYPES_COUNT
Definition: multivector.h:266
static constexpr int FIRST_TYPE
Definition: multivector.h:264
size_t i
Definition: json11.cpp:597
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 247 of file multivector.h.

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

248  {
249  if( ( aType < FIRST_TYPE ) || ( aType > LAST_TYPE ) )
250  throw std::out_of_range( "MULTIVECTOR out of range" );
251 
252  return m_data[ aType - FIRST_TYPE ];
253  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Contained items by type
Definition: multivector.h:292
static constexpr int LAST_TYPE
Definition: multivector.h:265
static constexpr int FIRST_TYPE
Definition: multivector.h:264
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 255 of file multivector.h.

256  {
257  if( ( aType < FIRST_TYPE ) || ( aType > LAST_TYPE ) )
258  throw std::out_of_range( "MULTIVECTOR out of range" );
259 
260  return m_data[ aType - FIRST_TYPE ];
261  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Contained items by type
Definition: multivector.h:292
static constexpr int LAST_TYPE
Definition: multivector.h:265
static constexpr int FIRST_TYPE
Definition: multivector.h:264
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

Definition at line 169 of file multivector.h.

Referenced by LIB_PART::AddDrawItem(), LIB_EDIT_FRAME::BlockCopySelectedItems(), LIB_PART::LIB_PART(), MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T >::push_back(), and LIB_PART::SetFields().

170  {
171  operator[]( aItem->Type() ).push_back( aItem );
172  }
void push_back(T *aItem)
Definition: multivector.h:169
ITEM_PTR_VECTOR & operator[](int aType)
Definition: multivector.h:247
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)
inline

Definition at line 207 of file multivector.h.

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

208  {
209  if( aType != UNDEFINED_TYPE )
210  {
211  return operator[]( aType ).size();
212  }
213  else
214  {
215  size_t cnt = 0;
216 
217  for( int i = 0; i < TYPES_COUNT; ++i)
218  cnt += m_data[ i ].size();
219 
220  return cnt;
221  }
222  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Contained items by type
Definition: multivector.h:292
static constexpr int TYPES_COUNT
Definition: multivector.h:266
static constexpr int UNDEFINED_TYPE
Type value to indicate no specific type.
Definition: multivector.h:50
size_t size(int aType=UNDEFINED_TYPE)
Definition: multivector.h:207
size_t i
Definition: json11.cpp:597
ITEM_PTR_VECTOR & operator[](int aType)
Definition: multivector.h:247
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 229 of file multivector.h.

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

230  {
231  for( int i = 0; i < TYPES_COUNT; ++i )
232  m_data[ i ].sort();
233  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Contained items by type
Definition: multivector.h:292
static constexpr int TYPES_COUNT
Definition: multivector.h:266
void sort()
Definition: multivector.h:229
size_t i
Definition: json11.cpp:597
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 238 of file multivector.h.

Referenced by LIB_PART::RemoveDuplicateDrawItems().

239  {
240  for( int i = 0; i < TYPES_COUNT; ++i )
241  {
242  if( m_data[ i ].size() > 1 )
243  m_data[ i ].unique();
244  }
245  }
ITEM_PTR_VECTOR m_data[TYPES_COUNT]
Contained items by type
Definition: multivector.h:292
static constexpr int TYPES_COUNT
Definition: multivector.h:266
size_t size(int aType=UNDEFINED_TYPE)
Definition: multivector.h:207
size_t i
Definition: json11.cpp:597

Member Data Documentation

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
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
template<typename T, int FIRST_TYPE_VAL, int LAST_TYPE_VAL>
constexpr int MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::TYPES_COUNT = LAST_TYPE - FIRST_TYPE + 1
static
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

Type value to indicate no specific type.

Mostly used to access the container as a flat list or to return data for the whole container.

Definition at line 50 of file multivector.h.

Referenced by MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T >::begin(), MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T >::end(), and MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::ITERATOR_BASE< ITEM_TYPE, ITEM_CONTAINER, ITEM_CONTAINER_IT >::ITERATOR_BASE().


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