35 #include <type_traits>
79 typename std::enable_if<!std::is_pointer<U>::value, U*>::type
86 typename std::enable_if<std::is_pointer<U>::value, U>::type
96 typename std::enable_if<!std::is_pointer<U>::value, U*>::type
106 typename std::enable_if<std::is_pointer<U>::value, U>::type
126 void removeIf(
const std::function<
bool(T*)> cond);
141 virtual void clear();
152 void read(std::istream& is);
172 const T*
getObject(
const unsigned int id)
const;
207 void resize(
const unsigned int N,
const T& obj);
212 const typename std::vector<T*>::const_iterator
begin()
const;
217 const typename std::vector<T*>::iterator
begin();
222 const typename std::vector<T*>::const_iterator
end()
const;
227 const typename std::vector<T*>::iterator
end();
238 void setId(T*
object,
unsigned int id)
279 virtual std::string
getName()
const = 0;
339 logger(
DEBUG,
"BaseHandler<T>::BaseHandler() finished");
354 copyContentsFromOtherHandler(BH);
355 logger(
DEBUG,
"BaseHandler<T>::BaseHandler(const BaseHandler &BH) finished");
362 logger(
DEBUG,
"BaseHandler<T>::~BaseHandler() finished");
369 for (
const T*
const obj : BH.
objects_)
371 addObject(obj->copy());
378 typename std::enable_if<!std::is_pointer<U>::value, U*>::type
381 U* oCopy =
object.copy();
389 typename std::enable_if<std::is_pointer<U>::value, U>::type
392 return copyAndAddObject(*
object);
398 typename std::enable_if<!std::is_pointer<U>::value, U*>::type
401 U* oCopy =
object.copy();
402 addGhostObject(oCopy);
409 typename std::enable_if<std::is_pointer<U>::value, U>::type
412 return copyAndAddGhostObject(*
object);
419 objects_.push_back(O);
421 getLastObject()->setIndex(getSize() - 1);
423 if (O->getId() + 1 > nextId_)
425 nextId_ = O->getId() + 1;
433 objects_.push_back(
object);
435 getLastObject()->setIndex(getSize() - 1);
437 getLastObject()->setId(nextId_);
446 objects_.push_back(O);
448 getLastObject()->setIndex(getSize() - 1);
455 for (
int i = 0;
i < objects_.size(); ++
i) {
456 if (cond(objects_[
i]))
474 logger.assert_debug(index < getSize(),
475 "In: void %::removeObject(const unsigned int index) const, "
476 "no object exists with index %, number of objects is %",
481 const unsigned int lastIndex = objects_.size() - 1;
483 T*
const objectToDelete = objects_[index];
486 if (index != lastIndex)
489 T*
const objectToMove = objects_[lastIndex];
491 objects_[index] = objectToMove;
492 objects_[lastIndex] = objectToDelete;
495 objects_[index]->moveInHandler(index);
498 objects_[lastIndex]->moveInHandler(lastIndex);
506 delete objectToDelete;
515 logger(
WARN,
"In: void %::removeLastObject, no Object exists in this BaseHandler.",
getName());
518 T*
const object = objects_.back();
531 for (T*
const obj : objects_)
549 std::stringstream line;
553 setStorageCapacity(N);
554 for (
unsigned int i = 0;
i < N;
i++)
556 readAndAddObject(is);
570 if (
id < objects_.size() && objects_[id]->getId() == id)
575 for (T* obj : objects_)
577 if (obj->getId() == id)
580 #ifndef MERCURY_USE_MPI
581 logger(
ERROR,
"[BaseHandler::getObjectById()] in Object* %: Object with ID % could not be found.",
getName(),
id);
595 std::vector<T*> list;
596 for (T* obj : objects_)
598 if (obj->getId() == id)
603 #ifndef MERCURY_USE_MPI
604 logger(
ERROR,
"[BaseHandler::getObjectById()] in Object* %: Object with ID % could not be found.",
getName(),
id);
615 logger.assert_debug(index < getSize(),
616 "[%::getObject()] Object couldn't be found because index (%) is higher than number of objects (%).",
618 return objects_[index];
626 logger.assert_debug(index < getSize(),
627 "[%::getObject() const] Object couldn't be found because index (%) is higher than number of objects (%).",
629 return objects_[index];
636 return objects_.back();
643 return objects_.back();
650 return objects_.size();
657 return objects_.size();
664 return objects_.capacity();
682 while (getSize() < N)
683 copyAndAddObject(obj);
684 while (getSize() > N)
692 return objects_.begin();
699 return objects_.begin();
706 return objects_.end();
713 return objects_.end();
std::string getName(int argc, char *argv[])
extracts the file name from the command line input
virtual void writeVTK() const
now empty function for writing VTK files.
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
unsigned nextGroupId_
value of the next BaseObject::groupId_. Value increased by one each time a groupId is assigned...
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
LL< Log::DEBUG > DEBUG
Debug information.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
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::complex< Mdouble > i
std::vector< T * > getObjectsById(const unsigned int id)
Gets a vector of pointers to the objects with the specific id.
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
virtual void addGhostObject(T *O)
Adds a new Object to the BaseHandler. called by the to avoid increasing the id.
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.
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddGhostObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler. This is one locally for inserting mpi part...
virtual void addExistingObject(T *O)
Adds an existing object to the BaseHandler without changing the id of the object. ...
void removeIf(const std::function< bool(T *)> cond)
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...
unsigned getNextGroupId()
Should be called each time you assign a groupId. Returns the value of nextGroupId_ and increases next...
virtual void removeObject(unsigned const int index)
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.
void resize(const unsigned int N, const T &obj)
Resizes the container to contain N elements.
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.
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) ...
void setNextId(unsigned int id)
virtual void readAndAddObject(std::istream &is)=0
Reads Object into the BaseHandler from restart data.
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.
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...