Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90682926
factory_multiscale.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Nov 3, 20:44
Size
4 KB
Mime Type
text/x-c++
Expires
Tue, Nov 5, 20:44 (2 d)
Engine
blob
Format
Raw Data
Handle
22119075
Attached To
rLIBMULTISCALE LibMultiScale
factory_multiscale.hh
View Options
/**
* @file factory_multiscale.hh
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Wed Dec 04 12:14:29 2013
*
* @brief This is the central factory for all the objects created through the
* parser
*
* @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 __LIBMULTISCALE_FACTORY_MULTISCALE_HH__
#define __LIBMULTISCALE_FACTORY_MULTISCALE_HH__
/* -------------------------------------------------------------------------- */
#include "domain_interface.hh"
#include "domain_multiscale.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
template
<
typename
T
>
class
FactoryMultiScale
:
public
T
,
public
IDManager
<
T
>
{
/* ------------------------------------------------------------------------ */
/* Typedefs */
/* ------------------------------------------------------------------------ */
typedef
std
::
string
ID
;
/* ------------------------------------------------------------------------ */
/* Constructors/Destructors */
/* ------------------------------------------------------------------------ */
protected
:
FactoryMultiScale
(
UInt
Dim
);
// virtual ~FactoryMultiScale();
/* ------------------------------------------------------------------------ */
/* Methods */
/* ------------------------------------------------------------------------ */
public
:
//! public function that create an factory from a reference code
// template <typename IT>
void
createObject
(
std
::
stringstream
&
line
);
//! call init onto all factorys stored
void
init
();
//! action
void
action
();
//! routines which truly creates a new object connected to obj parameter
template
<
typename
Obj
>
void
create
(
Obj
&
obj
);
//! parse a config line
UInt
parseLine
(
std
::
stringstream
&
line
,
ActionType
atype
);
//! request the singleton
template
<
typename
IT
>
static
IT
*
getManager
(
UInt
dim
);
template
<
typename
IT
>
static
IT
&
getManager
();
public
:
/* ------------------------------------------------------------------------ */
/* Class Members */
/* ------------------------------------------------------------------------ */
protected
:
//! dimension for all the built objects
UInt
dim
;
std
::
string
obj_id_being_created
;
std
::
string
obj_type_being_created
;
ActionType
obj_kind_being_created
;
};
/* -------------------------------------------------------------------------- */
__END_LIBMULTISCALE__
/* -------------------------------------------------------------------------- */
#include <typeinfo>
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
/* -------------------------------------------------------------------------- */
template
<
typename
T
>
template
<
typename
IT
>
IT
*
FactoryMultiScale
<
T
>::
getManager
(
UInt
dim
)
{
LM_ASSERT
(
!
(
IDManager
<
T
>::
static_pointer
),
"manager already constructed"
);
IDManager
<
T
>::
static_pointer
=
new
IT
(
dim
);
return
dynamic_cast
<
IT
*>
(
IDManager
<
T
>::
static_pointer
);
}
/* -------------------------------------------------------------------------- */
template
<
typename
T
>
template
<
typename
IT
>
IT
&
FactoryMultiScale
<
T
>::
getManager
()
{
if
(
!
IDManager
<
T
>::
static_pointer
)
LM_THROW
(
"Manager "
<<
typeid
(
T
).
name
()
<<
" was not created"
);
IT
&
ref
=
dynamic_cast
<
IT
&>
(
*
IDManager
<
T
>::
static_pointer
);
return
ref
;
}
/* -------------------------------------------------------------------------- */
__END_LIBMULTISCALE__
#endif
/* __LIBMULTISCALE_FACTORY_MULTISCALE_HH__ */
Event Timeline
Log In to Comment