Page MenuHomec4science

container.hh
No OneTemporary

File Metadata

Created
Sun, Jul 7, 23:25

container.hh

/**
* @file container.hh
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Tue Jul 22 14:47:56 2014
*
* @brief This is the generic container class
*
* @section LICENSE
*
* Copyright INRIA and CEA
*
* The LibMultiScale is a C++ parallel framework for the multiscale
* coupling methods dedicated to material simulations. This framework
* provides an API which makes it possible to program coupled simulations
* and integration of already existing codes.
*
* This Project was initiated in a collaboration between INRIA Futurs Bordeaux
* within ScAlApplix team and CEA/DPTA Ile de France.
* The project is now continued at the Ecole Polytechnique Fédérale de Lausanne
* within the LSMS/ENAC laboratory.
*
* This software is governed by the CeCILL-C license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*
*/
#ifndef __LIBMULTISCALE_CONTAINER_HH__
#define __LIBMULTISCALE_CONTAINER_HH__
/* -------------------------------------------------------------------------- */
//#include "comm_group.hh"
#include "cube.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
class Communicator;
class ReferenceManagerInterface;
struct CommGroup;
struct ComponentNull;
/* -------------------------------------------------------------------------- */
class ContainerInterface {
/* ------------------------------------------------------------------------ */
/* Constructors/Destructors */
/* ------------------------------------------------------------------------ */
public:
ContainerInterface() : comm_group(nullptr){};
virtual ~ContainerInterface(){};
/* ------------------------------------------------------------------------ */
/* Methods */
/* ------------------------------------------------------------------------ */
//! return bounding box
Cube &getBoundingBox() { return bounding_box; };
//! ste bounding box
void setBoundingBox(Cube &c) { bounding_box = c; };
//! return the communication group
CommGroup &getCommGroup() {
if (comm_group == nullptr)
LM_FATAL("invalid group");
return *comm_group;
};
//! return the ReferenceManager
std::shared_ptr<ReferenceManagerInterface> getRefManager() {
if (refmanager.expired())
LM_THROW("cannot access undefined Reference Manager");
return refmanager.lock();
};
bool hasRefManager() { return !refmanager.expired(); };
//! set the ReferenceManager
void setRefManager(std::weak_ptr<ReferenceManagerInterface> refMgr) {
refmanager = refMgr;
};
//! return the communication group
virtual void setCommGroup(CommGroup &group) { comm_group = &group; };
//! copy the container info
virtual void copyContainerInfo(ContainerInterface &cont) {
bounding_box = cont.getBoundingBox();
comm_group = &cont.getCommGroup();
}
/* ------------------------------------------------------------------------ */
/* Class Members */
/* ------------------------------------------------------------------------ */
protected:
std::weak_ptr<ReferenceManagerInterface> refmanager;
private:
Cube bounding_box;
CommGroup *comm_group;
};
/* -------------------------------------------------------------------------- */
template <typename T> class ContainerArray;
/* -------------------------------------------------------------------------- */
/**
* Interface Container<T>.
* Generic container
*/
template <typename T> class Container_base : public ContainerInterface {
/* ------------------------------------------------------------------------ */
/* Typedefs */
/* ------------------------------------------------------------------------ */
public:
typedef ContainerArray<T> ContainerSubset;
typedef T Ref;
class iterator_base;
/* ------------------------------------------------------------------------ */
/* Constructors/Destructors */
/* ------------------------------------------------------------------------ */
Container_base(){};
virtual ~Container_base(){};
/* ------------------------------------------------------------------------ */
/* Methods */
/* ------------------------------------------------------------------------ */
//! sort contained items
virtual void sort() { LM_TOIMPLEMENT; };
//! search for a given item index
virtual UInt search(T &el) { LM_TOIMPLEMENT; };
//! add a given item
virtual void push_back(const T &el) { LM_TOIMPLEMENT; };
//! get an item from its index
virtual T &get(UInt index) = 0;
//! get an item from its index
virtual T &operator[](UInt index){return this->get(index);};
//! remove an item from its index
virtual void remove(UInt index) { LM_TOIMPLEMENT; };
//! return the number of items
virtual UInt size(DOFType dt = dt_local) = 0;
};
/* -------------------------------------------------------------------------- */
template <typename T> class Container_base<T>::iterator_base {
public:
iterator_base(Container_base<T> &cont) : iterator_base() {
this->cont = &cont;
}
iterator_base() : cont(nullptr){};
virtual ~iterator_base(){};
virtual void operator++() = 0;
virtual T &operator*() = 0;
virtual bool operator!=(const iterator_base &) const = 0;
virtual bool operator==(const iterator_base &) const = 0;
protected:
Container_base<T> *cont;
};
/* -------------------------------------------------------------------------- */
#define DECLARE_CONTAINER_ACCEPT_FUNCTIONS \
template <typename D> void accept(D &dumper) { dumper.dump(*this); }
__END_LIBMULTISCALE__
#endif /* __LIBMULTISCALE_CONTAINER_HH__ */

Event Timeline