Commit 87cace34 authored by prudhomm's avatar prudhomm
Browse files

lifecore changes

* added Cloning factory aka abstract factory
  it will be used in the boundary conditions classes
* testsuite/lifecore/test_factory.cpp has a test for clone factories
  now
* test_factory is now enabled

this is the first COMMIT that makes boost:: a requirement !

factories rely on boost::function<> for functors.
parent 7b1a1e04
...@@ -7,9 +7,18 @@ Bugs fixed in 0.5.0: ...@@ -7,9 +7,18 @@ Bugs fixed in 0.5.0:
New in 0.5.0: New in 0.5.0:
============= =============
[lifecore]
* Added the Cloning Factory pattern (aka Abstract Factory)
implementation (CP)
[lifefem] [lifefem]
* Added discontinuous finite element(discontinuous galerkin) (DADP) * Added discontinuous finite element(discontinuous galerkin) (DADP)
* Sanitized/revamped the boundary conditions classes (CP) * Sanitized/revamped the boundary conditions classes (CP)
** split BC classes into their own files
** improved documentation
** reduced code redundancy and code size
** use clone factory for BCFunction
** use boost::shared_ptr<> for better memory management
[testsuite] [testsuite]
* Added test for 3D/0D coupling (AM) * Added test for 3D/0D coupling (AM)
...@@ -161,4 +170,4 @@ New in 0.1.0pre3: ...@@ -161,4 +170,4 @@ New in 0.1.0pre3:
* fixed some bugs and miscompilation in a few places * fixed some bugs and miscompilation in a few places
-- Christophe Prud'homme <prudhomm@debian.org>, Mon Oct 11 16:24:19 2004 -- Christophe Prud'homme <prudhomm@debian.org>, Wed Oct 13 12:18:05 2004
...@@ -24,12 +24,12 @@ include_HEADERS = GetPot.hpp debug.hpp\ ...@@ -24,12 +24,12 @@ include_HEADERS = GetPot.hpp debug.hpp\
chrono.hpp dataString.hpp dataTime.hpp fortran_wrap.hpp \ chrono.hpp dataString.hpp dataTime.hpp fortran_wrap.hpp \
lifeV.hpp post_proc.hpp subDomainNeighbors.hpp switch.hpp \ lifeV.hpp post_proc.hpp subDomainNeighbors.hpp switch.hpp \
util_string.hpp bareItems.hpp basisElSh.hpp dataTransient.hpp \ util_string.hpp bareItems.hpp basisElSh.hpp dataTransient.hpp \
singleton.hpp policy.hpp singleton.hpp policy.hpp typeInfo.hpp
lib_LTLIBRARIES = liblifecore.la lib_LTLIBRARIES = liblifecore.la
liblifecore_la_SOURCES = bareItems.cpp basisElSh.cpp GetPot.cpp dataString.cpp debug.cpp \ liblifecore_la_SOURCES = bareItems.cpp basisElSh.cpp GetPot.cpp dataString.cpp debug.cpp \
dataTime.cpp subDomainNeighbors.cpp switch.cpp util_string.cpp dataTransient.cpp dataTime.cpp subDomainNeighbors.cpp switch.cpp util_string.cpp dataTransient.cpp typeInfo.cpp
liblifecore_la_LIBADD = $(aztec_libs) liblifecore_la_LIBADD = $(aztec_libs)
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <debug.hpp> #include <debug.hpp>
#include <typeInfo.hpp>
namespace LifeV namespace LifeV
{ {
...@@ -60,7 +61,8 @@ struct factoryDefaultError ...@@ -60,7 +61,8 @@ struct factoryDefaultError
_M_ex() _M_ex()
{ {
std::ostringstream __ex_str; std::ostringstream __ex_str;
__ex_str << "[factory] Unknown Type : " << id; //__ex_str << "[factory] Unknown Type : " << id;
__ex_str << "[factory] Unknown Type : ";
_M_ex = __ex_str.str(); _M_ex = __ex_str.str();
} }
...@@ -84,10 +86,10 @@ struct factoryDefaultError ...@@ -84,10 +86,10 @@ struct factoryDefaultError
\class factory \class factory
\brief Implements a generic object factory \brief Implements a generic object factory
\sa factoryDefaultError, factoryClone, STypeInfo \sa factoryDefaultError, factoryClone, TypeInfo
@author Christophe Prud'homme @author Christophe Prud'homme
@version $Id: factory.hpp,v 1.1 2004-10-05 13:07:19 prudhomm Exp $ @version $Id: factory.hpp,v 1.2 2004-10-13 10:17:38 prudhomm Exp $
*/ */
template template
< <
...@@ -151,5 +153,95 @@ private: ...@@ -151,5 +153,95 @@ private:
id_to_product_type _M_associations; id_to_product_type _M_associations;
}; };
/*!
\class factoryClone
\brief Implements a generic cloning object factory
\sa factory, factoryDefaultError
\author Christophe Prud'homme
*/
template <
class AbstractProduct,
class ProductCreator = boost::function<AbstractProduct* (const AbstractProduct*)>,
template<typename, class> class FactoryErrorPolicy = factoryDefaultError
>
class factoryClone
:
public FactoryErrorPolicy<TypeInfo, AbstractProduct>
{
public:
/** @name Typedefs
*/
//@{
typedef FactoryErrorPolicy<TypeInfo,AbstractProduct> super;
//@}
/** @name Constructors, destructor
*/
//@{
//@}
/** @name Operator overloads
*/
//@{
//@}
/** @name Accessors
*/
//@{
//@}
/** @name Mutators
*/
//@{
//@}
/** @name Methods
*/
//@{
bool registerProduct(const TypeInfo& id, ProductCreator creator)
{
return _M_associations.insert( typename id_to_product_type::value_type( id, creator ) ).second;
}
bool unregisterProduct( const TypeInfo& id )
{
return _M_associations.erase(id) == 1;
}
AbstractProduct* createObject( const AbstractProduct* model )
{
if ( model == 0 ) return 0;
typename id_to_product_type::const_iterator i = _M_associations.find( typeid(*model) );
if ( i != _M_associations.end() )
{
return (i->second)(model);
}
return super::onUnknownType(typeid(*model));
}
//@}
private:
typedef std::map<TypeInfo, ProductCreator> id_to_product_type;
id_to_product_type _M_associations;
};
} }
#endif /* __factory_H */ #endif /* __factory_H */
...@@ -30,7 +30,7 @@ check_PROGRAMS = test_casts test_copy test_mark_to_bc test_getpot\ ...@@ -30,7 +30,7 @@ check_PROGRAMS = test_casts test_copy test_mark_to_bc test_getpot\
test_pairs test_pf test_prova test_rotate \ test_pairs test_pf test_prova test_rotate \
test_seq test_size test_typedefs test_using \ test_seq test_size test_typedefs test_using \
test_valarray test_vsize test_debug \ test_valarray test_vsize test_debug \
test_singleton test_singleton test_factory
...@@ -52,6 +52,7 @@ test_debug_SOURCES = test_debug.cpp ...@@ -52,6 +52,7 @@ test_debug_SOURCES = test_debug.cpp
test_getpot_SOURCES = test_getpot.cpp test_getpot_SOURCES = test_getpot.cpp
test_singleton_SOURCES = test_singleton.cpp test_singleton_SOURCES = test_singleton.cpp
test_factory_SOURCES = test_factory.cpp
POTFILES = mesh.pot mesh2.pot mesh3.pot POTFILES = mesh.pot mesh2.pot mesh3.pot
......
...@@ -79,13 +79,15 @@ public: ...@@ -79,13 +79,15 @@ public:
F( const F& f ) F( const F& f )
: :
str( f.str ) str( f.str )
{} {
LifeV::Debug() << "calling F::copy constructor\n";
}
const char* hello() const { return str.c_str(); } const char* hello() const { return str.c_str(); }
std::string str; std::string str;
}; };
typedef LifeV::singleton< LifeV::factory< A, std::string > > AFactory; typedef LifeV::singleton< LifeV::factory< A, std::string > > AFactory;
typedef LifeV::singleton< LifeV::factoryClone< A > > AFactoryClone;
namespace { namespace {
A* createB() { return new B; } A* createB() { return new B; }
...@@ -98,6 +100,10 @@ const bool regC = AFactory::instance().registerProduct( "C", &createC ); ...@@ -98,6 +100,10 @@ const bool regC = AFactory::instance().registerProduct( "C", &createC );
const bool regD = AFactory::instance().registerProduct( "D", &createD ); const bool regD = AFactory::instance().registerProduct( "D", &createD );
const bool regE = AFactory::instance().registerProduct( "E", &createE ); const bool regE = AFactory::instance().registerProduct( "E", &createE );
const bool regF = AFactory::instance().registerProduct( "F", &createF ); const bool regF = AFactory::instance().registerProduct( "F", &createF );
// cloning: dolly is not far away ;)
A* createFc( A const* f ) { return new F( ( F const& )*f ); }
const bool regFc = AFactoryClone::instance().registerProduct( typeid(F), &createFc );
} }
int int
...@@ -108,4 +114,7 @@ main( int argc, char** argv ) ...@@ -108,4 +114,7 @@ main( int argc, char** argv )
std::cerr << "D hello must be Yo : " << AFactory::instance().createObject( "D" )->hello() << "\n"; std::cerr << "D hello must be Yo : " << AFactory::instance().createObject( "D" )->hello() << "\n";
std::cerr << "E hello must be Ciao : " << AFactory::instance().createObject( "E" )->hello() << "\n"; std::cerr << "E hello must be Ciao : " << AFactory::instance().createObject( "E" )->hello() << "\n";
std::cerr << "F hello must be salut : " << AFactory::instance().createObject( "F" )->hello() << "\n"; std::cerr << "F hello must be salut : " << AFactory::instance().createObject( "F" )->hello() << "\n";
F f;
std::cerr << "Clone F hello must be salut : " << AFactoryClone::instance().createObject( &f )->hello() << "\n";
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment