111 virtual void readObject(std::istream& is) = 0;
116 void read(std::istream& is);
131 const T*
getObject(
const unsigned int id)
const;
161 const typename std::vector<T*>::const_iterator
begin()
const;
166 const typename std::vector<T*>::iterator
begin();
171 const typename std::vector<T*>::const_iterator
end()
const;
176 const typename std::vector<T*>::iterator
end();
196 virtual std::string
getName()
const = 0;
234 logger(
DEBUG,
"Basehandler<T>::BaseHandler() finished");
248 copyContentsFromOtherHandler(BH);
249 logger(
DEBUG,
"BaseHandler<T>::BaseHandler(const BaseHandler &BH) finished");
255 logger(
DEBUG,
"BaseHandler<T>::~BaseHandler() finished");
263 addObject(obj->copy());
278 U* oCopy = O->copy();
286 objects_.push_back(O);
288 getLastObject()->setIndex(getNumberOfObjects() - 1);
290 getLastObject()->setId(nextId_);
294 if (getNumberOfObjects() > maxObjects_)
295 maxObjects_ = getNumberOfObjects();
305 if (index >= getNumberOfObjects())
307 logger(
ERROR,
"In: void %::removeOject(const unsigned int index) const, no object exists with index %, number of objects is %", getName(), index, getNumberOfObjects());
318 std::size_t lastIndex = objects_.size() - 1;
321 T* objectToDelete = objects_[index];
323 if (index != lastIndex)
326 T* objectToMove = objects_[lastIndex];
328 objects_[index] = objectToMove;
329 objects_[lastIndex] = objectToDelete;
332 objects_[index]->moveInHandler(index);
335 objects_[lastIndex]->moveInHandler(lastIndex);
339 delete objectToDelete;
347 if (getNumberOfObjects() == 0)
349 logger(
WARN,
"In: void %::removeLastObject, no Object exists in this BaseHandler.", getName());
353 delete objects_.back();
363 for (
auto obj : objects_)
380 std::stringstream line(std::stringstream::in | std::stringstream::out);
383 logger(
VERBOSE,
"In %::read(is): reading in % objects.", getName(), N);
384 for (
unsigned int i = 0; i < N; i++)
399 if (
id < objects_.size() && objects_[id]->getId() == id)
404 for (T* obj : objects_ )
406 if (obj->getId() == id)
409 logger(
ERROR,
"[BaseHandler::getObjectById()] in Object* %: Object with ID % could not be found.", getName(),
id);
418 return objects_[index];
420 if (index >= getNumberOfObjects())
422 logger(
ERROR,
"[BaseHandler::getObject(const unsigned int index)] in Object* %: Object couldn't be found because index (%) is higher than number of objects.", getName(), index);
427 return objects_[index];
437 return objects_[index];
439 if (index >= getNumberOfObjects())
441 logger(
ERROR,
"[BaseHandler::getObject(const unsigned int index) const] in Object* %: No object exist with index % number of objects is %", getName(), index, getNumberOfObjects());
446 return objects_[index];
454 return objects_.back();
460 return objects_.back();
466 return objects_.size();
472 return objects_.capacity();
484 return objects_.begin();
490 return objects_.begin();
496 return objects_.end();
502 return objects_.end();
517 if (DPMBase_ ==
nullptr)
519 logger(
ERROR,
"[BaseHandler::getDPMBase()] in Object* %: pointer to DPMBase class is not set.", getName());
531 if (DPMBase_ ==
nullptr)
533 logger(
ERROR,
"[BaseHandler::getDPMBase() const] in Object* %: pointer to DPMBase class is not set.", getName());
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
virtual void readObject(std::istream &is)=0
Reads Object into the BaseHandler from restart data.
LL< Log::DEBUG > DEBUG
Debug information.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
void setStorageCapacity(const unsigned int N)
Sets the storage capacity of this BaseHandler.
T * getObjectById(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
unsigned int nextId_
identifier for next object created
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
void read(std::istream &is)
Reads all objects from restart data.
LL< Log::ERROR > ERROR
Error log level.
BaseHandler()
Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null point...
void removeLastObject()
Removes the last Object from the BaseHandler.
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
LL< Log::WARN > WARN
Warning log level.
U * copyAndAddObject(const U &O)
Creates a copy of a Object and adds it to the BaseHandler.
void getLineFromStringStream(std::istream &in, std::stringstream &out)
Reads a line from one stringstream into another, and prepares the latter for reading in...
virtual void removeObject(unsigned const int id)
Removes an Object from the BaseHandler.
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
virtual std::string getName() const =0
Gets the name of this handler.
virtual void addObject(T *O)
Adds a new Object to the BaseHandler.
std::vector< T * > objects_
The actual list of Object pointers.
Container to store the pointers to all objects that one creates in a simulation.
LL< Log::VERBOSE > VERBOSE
Verbose information.
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
DPMBase * DPMBase_
A pointer back to the DPMBase class.
T * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
unsigned int getStorageCapacity() const
Gets the storage capacity of this BaseHandler.
virtual ~BaseHandler()
Destructor, it destructs the BaseHandler and all Object it contains.
void copyContentsFromOtherHandler(const BaseHandler< T > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
unsigned int maxObjects_
An integer to keep track of the largest number of objects ever stored in this BaseHandler.
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...