Page MenuHomec4science

reference_manager_interface.hh
No OneTemporary

File Metadata

Created
Fri, Jun 28, 10:19

reference_manager_interface.hh

/**
* @file reference_manager_interface.hh
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Mon Sep 08 23:40:22 2014
*
* @brief This is the interface for managers of reference and coherency with
* migrations
*
* @section LICENSE
*
* Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* LibMultiScale is free software: you can redistribute it and/or modify it
* under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* LibMultiScale is distributed in the hope that it will be useful, but
* WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with LibMultiScale. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __AKANTU_REFERENCE_MANAGER_INTERFACE_HH__
#define __AKANTU_REFERENCE_MANAGER_INTERFACE_HH__
/* -------------------------------------------------------------------------- */
#include "attached_object.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
/* -------------------------------------------------------------------------- */
template <typename T> class ContainerArray;
template <typename Ref> class ReferenceManager;
/* -------------------------------------------------------------------------- */
class ReferenceManagerInterface {
/* ------------------------------------------------------------------------ */
/* Constructors/Destructors */
/* ------------------------------------------------------------------------ */
public:
ReferenceManagerInterface() : flag_need_check_movements(false){};
virtual ~ReferenceManagerInterface(){};
/* ------------------------------------------------------------------------ */
/* Methods */
/* ------------------------------------------------------------------------ */
//! set the Activate/UnActivate state of the reference manager
virtual void setState(bool state) { flag_need_check_movements = state; };
//! request to manage a subset
template <typename Cont> void addSubSet(Cont &sub);
// //! request remove a subset from the manager
template <typename Cont>
void removeSubSet(const std::string &name, Cont &sub);
//! request attaching a given vector v with a given container c
template <typename Cont> void attachVector(ContainerArray<Real> &v, Cont &c);
//! request detaching a given vector v with a given container c
template <typename Cont> void detachVector(ContainerArray<Real> &v, Cont &c);
//! request attaching a generic AttachedObject with a given container c
template <typename Cont> void attachObject(AttachedObject &obj, Cont &c);
//! request detaching a generic AttachedObject with a given container c
template <typename Cont> void detachObject(AttachedObject &obj, Cont &c);
//! automatic cast with containing type Ref
template <typename Ref> ReferenceManager<Ref> &castSelf();
/* ------------------------------------------------------------------------ */
/* Class Members */
/* ------------------------------------------------------------------------ */
protected:
bool flag_need_check_movements;
};
/* -------------------------------------------------------------------------- */
__END_LIBMULTISCALE__
#include "reference_manager.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
template <typename Cont>
void ReferenceManagerInterface::addSubSet(Cont &subset) {
using Ref = typename Cont::Ref;
this->castSelf<Ref>().addSubSet(dynamic_cast<ContainerArray<Ref> &>(subset));
}
/* -------------------------------------------------------------------------- */
template <typename Cont>
void ReferenceManagerInterface::removeSubSet(const std::string &name, Cont &) {
typedef typename Cont::Ref Ref;
this->castSelf<Ref>().removeSubSet(name);
}
/* -------------------------------------------------------------------------- */
template <typename Cont>
void ReferenceManagerInterface::attachVector(ContainerArray<Real> &v, Cont &c) {
typedef typename Cont::Ref Ref;
this->castSelf<Ref>().attachVector(v, c);
}
/* -------------------------------------------------------------------------- */
template <typename Cont>
void ReferenceManagerInterface::attachObject(AttachedObject &obj, Cont &c) {
typedef typename Cont::Ref Ref;
this->castSelf<Ref>().attachObject(obj,
static_cast<ContainerArray<Ref> &>(c));
}
/* -------------------------------------------------------------------------- */
template <typename Cont>
void ReferenceManagerInterface::detachObject(AttachedObject &obj, Cont &c) {
typedef typename Cont::Ref Ref;
this->castSelf<Ref>().detachObject(obj,
static_cast<ContainerArray<Ref> &>(c));
}
/* -------------------------------------------------------------------------- */
template <typename Ref>
ReferenceManager<Ref> &ReferenceManagerInterface::castSelf() {
ReferenceManager<Ref> *_ptr = dynamic_cast<ReferenceManager<Ref> *>(this);
if (_ptr == NULL)
LM_FATAL("provided type ("
<< typeid(Ref).name()
<< ") do not match the current reference manager");
return *_ptr;
}
/* -------------------------------------------------------------------------- */
__END_LIBMULTISCALE__
#endif /* __AKANTU_REFERENCE_MANAGER_INTERFACE_HH__ */

Event Timeline