36 #include <type_traits>
80 typename std::enable_if<!std::is_pointer<U>::value,U*>::type
87 typename std::enable_if<std::is_pointer<U>::value,U>::type
114 virtual void readObject(std::istream& is) = 0;
119 void read(std::istream& is);
134 const T*
getObject(
const unsigned int id)
const;
164 const typename std::vector<T*>::const_iterator
begin()
const;
169 const typename std::vector<T*>::iterator
begin();
174 const typename std::vector<T*>::const_iterator
end()
const;
179 const typename std::vector<T*>::iterator
end();
189 void setId(T*
object,
unsigned int id)
211 virtual std::string
getName()
const = 0;
255 logger(
DEBUG,
"Basehandler<T>::BaseHandler() finished");
270 copyContentsFromOtherHandler(BH);
271 logger(
DEBUG,
"BaseHandler<T>::BaseHandler(const BaseHandler &BH) finished");
278 logger(
DEBUG,
"BaseHandler<T>::~BaseHandler() finished");
285 for (
const T*
const obj : BH.
objects_)
287 addObject(obj->copy());
294 typename std::enable_if<!std::is_pointer<U>::value,U*>::type
297 U* oCopy =
object.copy();
305 typename std::enable_if<std::is_pointer<U>::value,U>::type
308 return copyAndAddObject(*
object);
315 objects_.push_back(
object);
317 getLastObject()->setIndex(getNumberOfObjects() - 1);
319 getLastObject()->setId(nextId_);
323 if (getNumberOfObjects() > maxObjects_)
324 maxObjects_ = getNumberOfObjects();
335 logger.assert_always(index < getNumberOfObjects(),
336 "In: void %::removeOject(const unsigned int index) const, "
337 "no object exists with index %, number of objects is %",
338 getName(), index, getNumberOfObjects());
347 const unsigned int lastIndex = objects_.size() - 1;
350 T*
const objectToDelete = objects_[index];
352 if (index != lastIndex)
355 T*
const objectToMove = objects_[lastIndex];
357 objects_[index] = objectToMove;
358 objects_[lastIndex] = objectToDelete;
361 objects_[index]->moveInHandler(index);
364 objects_[lastIndex]->moveInHandler(lastIndex);
370 delete objectToDelete;
377 if (getNumberOfObjects() == 0)
379 logger(
WARN,
"In: void %::removeLastObject, no Object exists in this BaseHandler.", getName());
382 T*
const object = objects_.back();
395 for (T*
const obj : objects_)
413 std::stringstream line(std::stringstream::in | std::stringstream::out);
416 logger(
VERBOSE,
"In %::read(is): reading in % objects.", getName(), N);
417 setStorageCapacity(N);
418 for (
unsigned int i = 0; i < N; i++)
434 if (
id < objects_.size() && objects_[id]->getId() == id)
439 for (T* obj : objects_ )
441 if (obj->getId() == id)
444 logger(
ERROR,
"[BaseHandler::getObjectById()] in Object* %: Object with ID % could not be found.", getName(),
id);
453 logger.assert(index < getNumberOfObjects(),
454 "[%::getObject()] Object couldn't be found because index (%) is higher than number of objects (%).",
455 getName(), index, getNumberOfObjects());
457 return objects_[index];
465 logger.assert(index < getNumberOfObjects(),
466 "[%::getObject() const] Object couldn't be found because index (%) is higher than number of objects (%).",
467 getName(), index, getNumberOfObjects());
468 return objects_[index];
475 return objects_.back();
482 return objects_.back();
489 return objects_.size();
496 return objects_.capacity();
510 return objects_.begin();
517 return objects_.begin();
524 return objects_.end();
531 return objects_.end();
545 logger.assert(DPMBase_!=
nullptr,
"[BaseHandler::getDPMBase()] in Object* %: pointer to DPMBase class is not set.", getName());
553 logger.assert(DPMBase_!=
nullptr,
"[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.
virtual void writeVTK()
Over written in WallHandler and ParticleHandler.
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.
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.
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler.
virtual std::string getName() const =0
Gets the name of this handler.
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.
void setId(T *object, unsigned int id)
This function sets the id and ensures that nextId is a bigger value than id.
DPMBase * DPMBase_
A pointer back to the DPMBase class.
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
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...