MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseHandler< T > Class Template Referenceabstract

Container to store all Object. More...

#include <BaseHandler.h>

Public Member Functions

 BaseHandler ()
 Default BaseHandler constructor, it simply creates an empty BaseHandler. More...
 
 BaseHandler (const BaseHandler< T > &BH)
 Copy constructor, it copies the BaseHandler and all Object it contains. More...
 
virtual ~BaseHandler ()
 Assignment operator. More...
 
void copyAndAddObject (const T &O)
 Creates a copy of a Object and adds it to the BaseHandler. More...
 
void copyAndAddObject (const T *O)
 Creates a copy of a Object and adds it to the BaseHandler. More...
 
virtual void addObject (T *O)
 Adds a new Object to the BaseHandler. More...
 
virtual void removeObject (unsigned const int id)
 Removes a Object from the BaseHandler. More...
 
void removeLastObject ()
 Removes the last Object from the BaseHandler. More...
 
void clear ()
 Empties the whole BaseHandler by removing all Object. More...
 
virtual void readObject (std::istream &is)=0
 Reads Object into the BaseHandler from restart data. More...
 
T * getObject (const unsigned int id) const
 Gets a pointer to the Object at the specified index in the BaseHandler. More...
 
T * getLastObject () const
 Gets a pointer to the last Object in this BaseHandler. More...
 
unsigned int getNumberOfObjects () const
 Gets the number of Object in this BaseHandler. More...
 
unsigned int getStorageCapacity () const
 Gets the storage capacity of this BaseHandler. More...
 
void setStorageCapacity (const unsigned int N)
 Sets the storage capacity of this BaseHandler. More...
 
const std::vector< T * >
::const_iterator 
begin () const
 Gets the begin of the const_iterator over all Object in this BaseHandler. More...
 
const std::vector< T * >::iterator begin ()
 Gets the begin of the iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector< T * >
::const_iterator 
end () const
 Gets the end of the const_iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector< T * >::iterator end ()
 Gets the end of the iterator over all BaseBoundary in this BaseHandler. More...
 

Private Attributes

std::vector< T * > objects_
 The actual list of Object pointers. More...
 
unsigned int maxObjects_
 An integer to keep track of the largest number of objects ever stored in this BaseHandler. More...
 
int nextId_
 identifier for next object created More...
 

Detailed Description

template<class T>
class BaseHandler< T >

Container to store all Object.

Bug:
Had to take out two function from Basehandler to get cmake to compile the code, should take to Dinant about this

The BaseHandler is a container to store all Object. It is implemented by a vector of pointers to the Object.

Definition at line 38 of file BaseHandler.h.

Constructor & Destructor Documentation

template<class T>
BaseHandler< T >::BaseHandler ( )
inline

Default BaseHandler constructor, it simply creates an empty BaseHandler.

Definition at line 42 of file BaseHandler.h.

43  {
44  clear();
45  #ifdef CONSTUCTOR_OUTPUT
46  std::cout << "BaseHandler::BaseHandler() finished" << std::endl;
47  #endif
48  }
void clear()
Empties the whole BaseHandler by removing all Object.
Definition: BaseHandler.h:162
template<class T>
BaseHandler< T >::BaseHandler ( const BaseHandler< T > &  BH)
inline

Copy constructor, it copies the BaseHandler and all Object it contains.

Parameters
[in]BHThe BaseHandler that has te be copied.

Definition at line 52 of file BaseHandler.h.

53  {
54  clear();
55  for (typename std::vector<T*>::const_iterator it=BH.begin();it!=BH.end();it++)
56  {
57  addObject((*it)->copy());
58  }
59  #ifdef CONSTUCTOR_OUTPUT
60  std::cout << "BaseHandler::BaseHandler(const BaseHandler &BH) finished" << std::endl;
61  #endif
62  }
virtual void addObject(T *O)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:106
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:220
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:233
void clear()
Empties the whole BaseHandler by removing all Object.
Definition: BaseHandler.h:162
template<class T>
virtual BaseHandler< T >::~BaseHandler ( )
inlinevirtual

Assignment operator.

Parameters
[in]rhsThe BaseHandler on the right hand side of the assignment.// Destructor, it simply destructs the BaseHandler and all Object it contains.

Definition at line 83 of file BaseHandler.h.

84  {
85  clear();
86  #ifdef DESTRUCTOR_OUTPUT
87  std::cout << "BaseHandler::~BaseHandler() finished" << std::endl;
88  #endif
89  }
void clear()
Empties the whole BaseHandler by removing all Object.
Definition: BaseHandler.h:162

Member Function Documentation

template<class T>
virtual void BaseHandler< T >::addObject ( T *  O)
inlinevirtual

Adds a new Object to the BaseHandler.

Reimplemented in ParticleHandler, and BoundaryHandler.

Definition at line 106 of file BaseHandler.h.

Referenced by BoundaryHandler::addObject(), ParticleHandler::addObject(), BaseHandler< BaseBoundary >::BaseHandler(), and BaseHandler< BaseBoundary >::copyAndAddObject().

107  {
108  objects_.push_back(O);
109  //Set the index of the particle
110  getLastObject()->set_Index(getNumberOfObjects()-1);
111  //set the non changing particle identifier
112  getLastObject()->set_Id(nextId_);
113  //Update Id for next particle
114  nextId_++;
115  //Update the maximum number of Particles
117  }
T * getLastObject() const
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:192
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:247
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Definition: BaseHandler.h:199
int nextId_
identifier for next object created
Definition: BaseHandler.h:253
unsigned int maxObjects_
An integer to keep track of the largest number of objects ever stored in this BaseHandler.
Definition: BaseHandler.h:250
template<class T>
const std::vector<T*>::const_iterator BaseHandler< T >::begin ( ) const
inline
template<class T>
const std::vector<T*>::iterator BaseHandler< T >::begin ( )
inline

Gets the begin of the iterator over all BaseBoundary in this BaseHandler.

Returns
A iterator pointing to the first Object.

Definition at line 227 of file BaseHandler.h.

228  {
229  return objects_.begin();
230  }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:247
template<class T>
void BaseHandler< T >::clear ( )
inline

Empties the whole BaseHandler by removing all Object.

Definition at line 162 of file BaseHandler.h.

Referenced by BaseHandler< BaseBoundary >::BaseHandler(), ParticleHandler::clear(), MD::read(), MD::read_v2(), ChuteBottom::setup_particles_initial_conditions(), and BaseHandler< BaseBoundary >::~BaseHandler().

163  {
164  objects_.clear();
165  nextId_=0;
166  maxObjects_=0;
167  }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:247
int nextId_
identifier for next object created
Definition: BaseHandler.h:253
unsigned int maxObjects_
An integer to keep track of the largest number of objects ever stored in this BaseHandler.
Definition: BaseHandler.h:250
template<class T>
void BaseHandler< T >::copyAndAddObject ( const T &  O)
inline

Creates a copy of a Object and adds it to the BaseHandler.

Parameters
[in]OA reference to the Object that has to be copied.

Definition at line 93 of file BaseHandler.h.

Referenced by Chute::add_particle(), InsertionBoundary::checkBoundaryActionsBeforeTimeStep(), Chute::create_bottom(), MD::load_par_ini_file(), MD::read_next_from_data_file(), Chute::setup_particles_initial_conditions(), and ChuteBottom::setup_particles_initial_conditions().

94  {
95  addObject(O.copy());
96  }
virtual void addObject(T *O)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:106
template<class T>
void BaseHandler< T >::copyAndAddObject ( const T *  O)
inline

Creates a copy of a Object and adds it to the BaseHandler.

Parameters
[in]OA pointer to the Object (or derived class) that has to be copied.

Definition at line 100 of file BaseHandler.h.

101  {
102  addObject(O->copy());
103  }
virtual void addObject(T *O)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:106
template<class T>
const std::vector<T*>::iterator BaseHandler< T >::end ( )
inline

Gets the end of the iterator over all BaseBoundary in this BaseHandler.

Returns
An iterator pointing to the last BaseBoundary.

Definition at line 240 of file BaseHandler.h.

241  {
242  return objects_.end();
243  }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:247
template<class T>
T* BaseHandler< T >::getLastObject ( ) const
inline

Gets a pointer to the last Object in this BaseHandler.

Returns
A pointer to the last Object in the BaseHandler.

Definition at line 192 of file BaseHandler.h.

Referenced by BaseHandler< BaseBoundary >::addObject(), Chute::IsInsertable(), MD::read(), MD::read_v1(), MD::read_v2(), and BaseHandler< BaseBoundary >::removeObject().

193  {
194  return objects_.back();
195  }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:247
template<class T>
T* BaseHandler< T >::getObject ( const unsigned int  id) const
inline

Gets a pointer to the Object at the specified index in the BaseHandler.

Parameters
[in]idThe index of the requested Object.
Returns
A pointer to the requested Object.

Definition at line 176 of file BaseHandler.h.

Referenced by MD::Check_and_Duplicate_Periodic_Particles(), Chute::clean_chute(), MD::compute_particle_masses(), MD::do_integration_after_force_computation(), Chute::getLargestParticle(), Chute::getSmallestParticle(), TangentialSpringParticle::moveInHandler(), MD::output_xballs_data_particle(), MD::print(), MD::read_next_from_data_file(), MD::Remove_Duplicate_Periodic_Particles(), BaseHandler< BaseBoundary >::removeObject(), MD::removeParticle(), MD::set_dt(), MD::set_FixedParticles(), and MD::solve().

177  {
178  if (id>=getNumberOfObjects())
179  {
180  std::cerr<<"In: Object* BaseHandler::getObject(const unsigned int id) const"<<std::endl;
181  std::cerr<<"No Object exist with index "<<id<<" number of objects is "<<getNumberOfObjects()<<std::endl;
182  throw;
183  }
184  else
185  {
186  return objects_[id];
187  }
188  }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:247
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Definition: BaseHandler.h:199
template<class T>
unsigned int BaseHandler< T >::getStorageCapacity ( ) const
inline

Gets the storage capacity of this BaseHandler.

Returns
The storage capacity of this BaseHandler.

Definition at line 206 of file BaseHandler.h.

Referenced by MD::print().

207  {
208  return objects_.capacity();
209  }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:247
template<class T>
virtual void BaseHandler< T >::readObject ( std::istream &  is)
pure virtual

Reads Object into the BaseHandler from restart data.

Parameters
[in]isThe input stream from which the information is read.

Implemented in ParticleHandler, and BoundaryHandler.

template<class T>
void BaseHandler< T >::removeLastObject ( )
inline

Removes the last Object from the BaseHandler.

Definition at line 147 of file BaseHandler.h.

Referenced by Chute::IsInsertable(), and MD::read_next_from_data_file().

148  {
149  if (getNumberOfObjects()==0)
150  {
151  std::cerr<<"In: void BaseHandler::removeLastObject const"<<std::endl;
152  std::cerr<<"No Object exist in this BaseHandler"<<std::endl;
153  throw;
154  }
155  //Physically removes Object
156  delete objects_.back();
157  //Remove the (now double) reference to that last Object
158  objects_.pop_back();
159  }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:247
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Definition: BaseHandler.h:199
template<class T>
virtual void BaseHandler< T >::removeObject ( unsigned const int  id)
inlinevirtual

Removes a Object from the BaseHandler.

The Object at position id is removed by moving the last Object in the vector to the position of id.

Parameters
[in]idThe index of which Object has to be removed from the BaseHandler

Definition at line 122 of file BaseHandler.h.

Referenced by DeletionBoundary::checkBoundaryAfterParticleMoved(), CircularPeriodicBoundary::checkBoundaryAfterParticleMoved(), ChuteBottom::make_rough_bottom(), and MD::removeParticle().

123  {
124  if (id>=getNumberOfObjects())
125  {
126  std::cerr<<"In: void BaseHandler::removeObject(const unsigned int id) const"<<std::endl;
127  std::cerr<<"No Object exist with index "<<id<<" number of objects is "<<getNumberOfObjects()<<std::endl;
128  throw;
129  }
130 
131  //Physically remove Object
132  delete objects_[id];
133 
134  //If the Object was the last Object nothing has to be done, otherwise some additional work is neccesary
135  if (getObject(id) != getLastObject())
136  {
137  //Copy the pointer to the last Object to position id
138  objects_[id] = getLastObject();
139  objects_[id]->moveInHandler(id);
140  }
141  //Remove the (now double) reference to that last Object
142  objects_.pop_back();
143  }
T * getObject(const unsigned int id) const
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:176
T * getLastObject() const
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:192
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:247
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Definition: BaseHandler.h:199
template<class T>
void BaseHandler< T >::setStorageCapacity ( const unsigned int  N)
inline

Sets the storage capacity of this BaseHandler.

Parameters
[in]NThe storage capacity the BaseHandler will have

Definition at line 213 of file BaseHandler.h.

Referenced by MD::constructor(), ChuteBottom::make_rough_bottom(), MD::read_v1(), and ChuteBottom::setup_particles_initial_conditions().

214  {
215  objects_.reserve(N);
216  }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:247

Member Data Documentation

template<class T>
unsigned int BaseHandler< T >::maxObjects_
private

An integer to keep track of the largest number of objects ever stored in this BaseHandler.

Definition at line 250 of file BaseHandler.h.

Referenced by BaseHandler< BaseBoundary >::addObject(), and BaseHandler< BaseBoundary >::clear().

template<class T>
int BaseHandler< T >::nextId_
private

identifier for next object created

Definition at line 253 of file BaseHandler.h.

Referenced by BaseHandler< BaseBoundary >::addObject(), and BaseHandler< BaseBoundary >::clear().


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