SG::AuxVectorBase Class Reference

Manage index tracking and synchronization of auxiliary data. More...

#include <AuxVectorBase.h>

Inheritance diagram for SG::AuxVectorBase:
SG::AuxVectorData DataVector< T, DataModel_detail::NoBase >

List of all members.

Classes

class  ResortAuxHelper
 Helper to factor out template-independent part of resortAux.

Public Member Functions

 AuxVectorBase ()
 Default constructor.
virtual ~AuxVectorBase ()
 Destructor.
bool trackIndices () const
 Return true if index tracking is enabled for this container.
void setStore (const SG::IConstAuxStore *store)
 Set the store associated with this object.
void setStore (SG::IAuxStore *store)
 Set the store associated with this object.
void setStore (const DataLink< SG::IConstAuxStore > &store)
 Set the store associated with this object.
void setConstStore (const SG::IConstAuxStore *store)
 Synonym for setStore with IConstAuxStore.
void setNonConstStore (SG::IAuxStore *store)
 Synonym for setStore with IAuxStore.

Protected Member Functions

template<class DVL >
void initAuxVectorBase (SG::OwnershipPolicy ownPolicy, SG::IndexTrackingPolicy indexTrackingPolicy)
 Initialize index tracking mode.
void swap (AuxVectorBase &other)
 Swap with another container.
template<class ForwardIterator >
void setIndices (ForwardIterator beg, ForwardIterator end, size_t first=0)
 Set container/index for all elements within a range.
template<class ForwardIterator >
void clearIndex (ForwardIterator elt)
 Clear the container / index for element elt.
template<class ForwardIterator >
void clearIndices (ForwardIterator beg, ForwardIterator end)
 Clear the container / index for a range of elements.
template<class DVL >
void resize (size_t size)
 Resize the aux data associated with this container.
template<class DVL >
void reserve (size_t size)
 Change the capacity of the aux data associated with this container.
template<class DVL >
void shift (DVL &cont, size_t pos, ptrdiff_t offs)
 Shift the elements of the container.
void moveAux (size_t index, SG::AuxElement *p, bool clear=false)
 Set index on an element and copy auxiliary data.
void moveAux (size_t index, const void *p, bool clear=false)
 Set index on an element and copy auxiliary data.
template<class ForwardIterator >
void moveAux (size_t index, ForwardIterator beg, ForwardIterator end)
 Set index on a range of elements and copy auxiliary data.
void swapElementsAux (size_t aindex, size_t bindex, SG::AuxElement *a, SG::AuxElement *b, AuxVectorBase *bcont)
 Swap indices and auxiliary data between two elements.
void swapElementsAux (size_t aindex, size_t bindex, const void *a, const void *b, AuxVectorBase *bcont)
 Swap indices and auxiliary data between two elements.
template<class ForwardIterator >
void resortAux (size_t index, ForwardIterator beg, ForwardIterator end)
 Reset indices / reorder aux data after elements have been permuted.

Friends

class ResortAuxHelper

Detailed Description

Manage index tracking and synchronization of auxiliary data.

An object, usually a DataVector, can have vectors of auxiliary data associated with it. In order to be able to find the auxiliary data for a given container element, the elements must hold their indices within the container (done by the AuxElement class).

When the container changes, this information must be updated. Indices need to be changed, and corresponding changes need to be made in the vectors of associated auxiliary data. Most of the code in this class consists of helpers that effect these changes. These are intended to be called only by the deriving container class.

This class also contains a flag to control whether or not indices should be tracked like this. This is controlled by the type of the payload and by the selected ownership and indexing policies.

If the payload type does not derive from SG::AuxElement, then no index tracking is possible, and the flag is always false.

Otherwise, it depends on the setting of the policies. The default value for the index tracking policy is DEFAULT_TRACK_INDICES. In that case, we track indices if this container owns its elements (OWN_ELEMENTS) and we don't if the container does not down its elements (VIEW_ELEMENTS). This is the usual case. However, the index tracking policy may also be set to ALWAYS_TRACK_INDICES or NEVER_TRACK_INDICES to override this. (The major foreseen use case for this is to allow index tracking for a view container populated with objects allocated from a DataPool.)

The derived container should initialize this class by calling initAuxVectorBase. The derived container class is passed as a template argument; the ownership and index tracking policies are also passed. This method can be called again if the policies change.

There are only a couple user-callable methods. The trackIndices method returns the current state of the index tracking flag. There are also wrappers for setStore method, which enforce the condition that one can't set a store for a container that does not do index tracking.

The remaining methods are intended to be called only from the derived container class (and thus they are declared as protected). Besides a swap method, these include


Constructor & Destructor Documentation

SG::AuxVectorBase::AuxVectorBase (  ) 

Default constructor.

This will disable index tracking by default. The constructor should be followed by a call to initAuxVectorBase. (This is separated from the constructor because calling non-default constructors of DataVector base classes can be awkward in the case of virtual derivation.)


Member Function Documentation

template<class ForwardIterator >
void SG::AuxVectorBase::clearIndex ( ForwardIterator  elt  )  [inline, protected]

Clear the container / index for element elt.

Parameters:
elt Iterator to the element to clear.

ForwardIterator should be an iterator over the DataVector (not a base iterator).

template<class ForwardIterator >
void SG::AuxVectorBase::clearIndices ( ForwardIterator  beg,
ForwardIterator  end 
) [inline, protected]

Clear the container / index for a range of elements.

Parameters:
beg Beginning of the range.
end End of the range.

ForwardIterator should be an iterator over the DataVector (not a base iterator).

template<class DVL >
void SG::AuxVectorBase::initAuxVectorBase ( SG::OwnershipPolicy  ownPolicy,
SG::IndexTrackingPolicy  indexTrackingPolicy 
) [inline, protected]

Initialize index tracking mode.

Parameters:
ownPolicy The container ownership policy.
indexTrackingPolicy The requested index tracking policy.

DVL should be the most-derived class for this container.

This handles the logic for setting the state of index tracking. If this container does not handle aux data, then index tracking is always off. Otherwise, it depends on the requested policies. In any case, it is an error to turn off index tracking for a container that has an associated aux store.

template<class ForwardIterator >
void SG::AuxVectorBase::moveAux ( size_t  index,
ForwardIterator  beg,
ForwardIterator  end 
) [inline, protected]

Set index on a range of elements and copy auxiliary data.

Parameters:
index Container index at which the first new element is being added.
beg The start of the range of new elements.
end The end of the range of new elements.

The elements in the range are being a added to the container at index. If the new elements have associated auxiliary data, copy it to the container starting at index. Then set the container / index on the elements in the range.

ForwardIterator should be an iterator over the DataVector (not a base iterator).

void SG::AuxVectorBase::moveAux ( size_t  index,
const void *  p,
bool  clear = false 
) [inline, protected]

Set index on an element and copy auxiliary data.

Parameters:
index Container index at which the new element is being added.
p The new element being added.
clear If true, then any auxiliary data initially associated with p are cleared after being copied.

Overload for the no-auxdata case.

void SG::AuxVectorBase::moveAux ( size_t  index,
SG::AuxElement p,
bool  clear = false 
) [protected]

Set index on an element and copy auxiliary data.

Parameters:
index Container index at which the new element is being added.
p The new element being added.
clear If true, then any auxiliary data initially associated with p are cleared after being copied.

Element p is being added to the container at index. If p has associated auxiliary data, copy it to the container at index. Then set the container / index on p.

template<class DVL >
void SG::AuxVectorBase::reserve ( size_t  size  )  [inline, protected]

Change the capacity of the aux data associated with this container.

Parameters:
size The new container size.

DVL should be the most-derived class for this container.

template<class DVL >
void SG::AuxVectorBase::resize ( size_t  size  )  [inline, protected]

Resize the aux data associated with this container.

Parameters:
size The new container size.

DVL should be the most-derived class for this container.

template<class ForwardIterator >
void SG::AuxVectorBase::resortAux ( size_t  index,
ForwardIterator  beg,
ForwardIterator  end 
) [inline, protected]

Reset indices / reorder aux data after elements have been permuted.

Parameters:
index Index in the container of the start of the range.
beg Start of the range of elements to process.
end End of the range of elements to process.

Call this after some operation that has permuted the elements in the container (such as sort). The index information in the elements will be used to permute all auxiliary data in the same way. Finally, all the indices will be reset in the correct order.

ForwardIterator should be an iterator over the DataVector (not a base iterator).

void SG::AuxVectorBase::setConstStore ( const SG::IConstAuxStore store  )  [inline]

Synonym for setStore with IConstAuxStore.

Parameters:
store The new store.
template<class ForwardIterator >
void SG::AuxVectorBase::setIndices ( ForwardIterator  beg,
ForwardIterator  end,
size_t  first = 0 
) [inline, protected]

Set container/index for all elements within a range.

Parameters:
beg Beginning of the range.
end End of the range.
first Index to set for the first element in the range.

For all elements in the range, the container will be set to this container, and indices will be set sequentially, starting with first.

ForwardIterator should be an iterator over the DataVector (not a base iterator).

void SG::AuxVectorBase::setNonConstStore ( SG::IAuxStore store  )  [inline]

Synonym for setStore with IAuxStore.

Parameters:
store The new store.
void SG::AuxVectorBase::setStore ( const DataLink< SG::IConstAuxStore > &  store  ) 

Set the store associated with this object.

Parameters:
store The new store.

This will clear the non-const store pointer, and also clear the cache.

It is an error to set a store for a container for which index tracking is disabled. That will raise an ExcUntrackedSetStore exception.

Reimplemented from SG::AuxVectorData.

void SG::AuxVectorBase::setStore ( SG::IAuxStore store  ) 

Set the store associated with this object.

Parameters:
store The new store.

This will set both the const and non-const store pointers, and also clear the cache.

It is an error to set a store for a container for which index tracking is disabled. That will raise an ExcUntrackedSetStore exception.

Reimplemented from SG::AuxVectorData.

void SG::AuxVectorBase::setStore ( const SG::IConstAuxStore store  ) 

Set the store associated with this object.

Parameters:
store The new store.

This will clear the non-const store pointer, and also clear the cache.

It is an error to set a store for a container for which index tracking is disabled. That will raise an ExcUntrackedSetStore exception.

Reimplemented from SG::AuxVectorData.

template<class DVL >
void SG::AuxVectorBase::shift ( DVL &  cont,
size_t  pos,
ptrdiff_t  offs 
) [inline, protected]

Shift the elements of the container.

Parameters:
cont The container that's being shifted.
pos The starting index for the shift.
offs The (signed) amount of the shift.

The container should be the derived container. The elements in the container should have already been shifted; this operation will then adjust the element indices and also shift the elements in the vectors for all aux data items. offs may be either positive or negative.

If offs is positive, then the container is growing. The container size should be increased by offs, the element at pos moved to pos + offs, and similarly for following elements. The elements between pos and pos + offs should be default-initialized.

If offs is negative, then the container is shrinking. The element at pos should be moved to pos + offs, and similarly for following elements. The container should then be shrunk by -offs elements (running destructors as appropriate).

void SG::AuxVectorBase::swap ( AuxVectorBase other  )  [inline, protected]

Swap with another container.

Parameters:
other The container with which to swap.

Reimplemented from SG::AuxVectorData.

void SG::AuxVectorBase::swapElementsAux ( size_t  aindex,
size_t  bindex,
const void *  a,
const void *  b,
AuxVectorBase bcont 
) [inline, protected]

Swap indices and auxiliary data between two elements.

Parameters:
aindex Index of the first element, in this container.
bindex Index of the second element, in bcont.
a Pointer to the first element.
b Pointer to the second element.
bcont Container holding the second element. (May be the same as this, but doesn't have to be.)

This is the no-auxdata case; it is a no-op except for checking m_trackIndices.

void SG::AuxVectorBase::swapElementsAux ( size_t  aindex,
size_t  bindex,
SG::AuxElement a,
SG::AuxElement b,
AuxVectorBase bcont 
) [protected]

Swap indices and auxiliary data between two elements.

Parameters:
aindex Index of the first element, in this container.
bindex Index of the second element, in bcont.
a Pointer to the first element.
b Pointer to the second element.
bcont Container holding the second element. (May be the same as this, but doesn't have to be.)

Elements a at aindex in this and b at bindex in bcont are being swapped. Swap the index / container references between the elements and also swap the auxiliary data if it exists.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 1 Dec 2017 for RootCore Packages by  doxygen 1.6.1