[Yake-svn] SF.net SVN: yake: [1909] trunk/yake
Status: Beta
Brought to you by:
psyclonist
From: <psy...@us...> - 2008-03-24 21:30:47
|
Revision: 1909 http://yake.svn.sourceforge.net/yake/?rev=1909&view=rev Author: psyclonist Date: 2008-03-24 14:30:20 -0700 (Mon, 24 Mar 2008) Log Message: ----------- * added yake::factory template library * [base] replaced macro "mess" in yakeRegistry.h with yake::factory base implementation Modified Paths: -------------- trunk/yake/src/graphics/yakeGraphicsSystem.cpp trunk/yake/yake/audio/yakeAudioSystem.h trunk/yake/yake/base/templates/yakeRegistry.h trunk/yake/yake/graphics/yakeGraphicalWorld.h trunk/yake/yake/graphics/yakeGraphicsSystem.h Added Paths: ----------- trunk/yake/yake/factory/ trunk/yake/yake/factory/config.h trunk/yake/yake/factory/dynamic_factory.h trunk/yake/yake/factory/global_dynamic_factory.h trunk/yake/yake/factory/policies.h Modified: trunk/yake/src/graphics/yakeGraphicsSystem.cpp =================================================================== --- trunk/yake/src/graphics/yakeGraphicsSystem.cpp 2008-01-20 21:50:46 UTC (rev 1908) +++ trunk/yake/src/graphics/yakeGraphicsSystem.cpp 2008-03-24 21:30:20 UTC (rev 1909) @@ -33,13 +33,10 @@ #include <yake/graphics/yakeEntity.h> #include <yake/graphics/yakeGeometryAccess.h> -//============================================================================ -// INTERFACE STRUCTURES / UTILITY CLASSES -//============================================================================ namespace yake { namespace graphics { - YAKE_IMPLEMENT_REGISTRY( IGraphicsSystem ); + YAKE_IMPLEMENT_REGISTRY(IGraphicsSystem) /// GraphicsEntity GraphicsEntity::GraphicsEntity() : mName( uniqueName::create( "graphics" ) ) Modified: trunk/yake/yake/audio/yakeAudioSystem.h =================================================================== --- trunk/yake/yake/audio/yakeAudioSystem.h 2008-01-20 21:50:46 UTC (rev 1908) +++ trunk/yake/yake/audio/yakeAudioSystem.h 2008-03-24 21:30:20 UTC (rev 1909) @@ -153,11 +153,10 @@ */ class YAKE_AUDIO_API IAudioSystem { + YAKE_DECLARE_REGISTRY_0(IAudioSystem,String) public: virtual ~IAudioSystem(); virtual WorldPtr createWorld() = 0; - - YAKE_DECLARE_REGISTRY_0( IAudioSystem, yake::String ) }; } Modified: trunk/yake/yake/base/templates/yakeRegistry.h =================================================================== --- trunk/yake/yake/base/templates/yakeRegistry.h 2008-01-20 21:50:46 UTC (rev 1908) +++ trunk/yake/yake/base/templates/yakeRegistry.h 2008-03-24 21:30:20 UTC (rev 1909) @@ -27,9 +27,6 @@ #ifndef YAKE_BASE_TEMPLATES_REGISTRY_H #define YAKE_BASE_TEMPLATES_REGISTRY_H -//============================================================================ -// IMPLEMENTATION HEADERS -//============================================================================ // Standard headers #ifndef YAKE_BASEPREREQUISITES_H #include "yake/base/yakePrerequisites.h" @@ -38,190 +35,94 @@ #include <yake/base/yakeException.h> #include <yake/base/templates/yakeSmartAssert.h> #include <yake/base/templates/yakePointer.h> -#include <yake/base/templates/yakeManager.h> -#include <yake/base/mpl/yakeBuildArguments.h> +#include <yake/factory/global_dynamic_factory.h> -//============================================================================ -// INTERFACE STRUCTURES / UTILITY CLASSES -//============================================================================ -namespace yake -{ -namespace templates -{ +namespace yake { +namespace templates { -/* Helpers */ -#define FUNCTION(number) \ - YAKE_TYPES_ONE_FREE(number) \ - SharedPtr<T> create(typename T::RegistryType::Id id, YAKE_ARGUMENTS_ONE_FREE(number)) \ - { return T::getRegistry().getObject(id)->create(YAKE_USE_ARGUMENTS(number)); } -YAKE_IMPLEMENT_FUNCTION(FUNCTION) -#undef FUNCTION - -#define FUNCTION(number) \ - YAKE_TYPES_ONE_FREE(number) \ - SharedPtr<T> create_default(YAKE_ARGUMENTS_ONE_FREE(number)) \ - { return T::getRegistry().getDefaultCreator()->create(YAKE_USE_ARGUMENTS(number)); } -YAKE_IMPLEMENT_FUNCTION(FUNCTION) -#undef FUNCTION - -/* Registry */ -// todo: functors instead of creators -// todo: if we cannot simplify manager template, remove it -template <class ConfigClass> -class Registry : public Manager< typename ConfigClass::Id, SharedPtr< typename ConfigClass::ICreator >, RegisterFunctionsNames > -{ -YAKE_DECLARE_CLASS( yake::templates::Registry ) -public: // types - typedef ConfigClass Config; - typedef typename Config::Base Base; - typedef typename Config::Id Id; - typedef typename Config::ICreator ICreator; - -public: // constructors - Registry() : m_pDefaultCreator() {} - -private: // no copy - Registry( const Registry & ); - Registry & operator=( const Registry & ); - -public: // methods -#define FUNCTION( number ) \ - YAKE_TYPES( number ) \ - SharedPtr< Base > create( Id id, YAKE_ARGUMENTS_ONE_FREE( number ) ) \ - { return getObject( id )->create( YAKE_USE_ARGUMENTS( number ) ); } -YAKE_IMPLEMENT_FUNCTION( FUNCTION ) -#undef FUNCTION - - SharedPtr< ICreator > getDefaultCreator() - { - YAKE_ASSERT( ( Manager< typename ConfigClass::Id, SharedPtr< typename ConfigClass::ICreator>,RegisterFunctionsNames >::getIdentifiers().size() ) > 0 ).debug( "No default creator available." ); // todo: does not work in release mode, should throw exception - if( !m_pDefaultCreator ) m_pDefaultCreator = getObject( *Manager< typename ConfigClass::Id, SharedPtr< typename ConfigClass::ICreator >, RegisterFunctionsNames >::getIdentifiers().begin() ); // todo: (if(!m_pDefaultCreator) m_pDefaultCreator = front(); - return m_pDefaultCreator; - } - - void setDefaultCreator( const SharedPtr< ICreator > pCreator ) - { m_pDefaultCreator = pCreator; } - -private: // data - SharedPtr< ICreator > m_pDefaultCreator; -}; - - // Note: there already has to be a registry configuration class called RegistryConfig. // Note: this macro has to be used inside the class declaration. -#define YAKE_DECLARE_REGISTRY() \ +#define YAKE_DECLARE_REGISTRY_EX(INTERFACE,IDTYPE,PARAMS) \ public: \ - typedef yake::templates::Registry< RegistryConfig > RegistryType; \ - static RegistryType& getRegistry(); + typedef YAKE_FACTORY_NS::factory<IDTYPE,INTERFACE,SharedPtr<INTERFACE> PARAMS,YAKE_FACTORY_NS::ThrowErrorPolicy,YAKE_FACTORY_NS::SingletonPolicy> factory_t; \ + typedef factory_t::key_type id_type; \ + static factory_t& getRegistry(); // Note: you have to use DECLARE_REGISTRY() before. #define YAKE_IMPLEMENT_REGISTRY( Class ) \ - Class::RegistryType& Class::getRegistry() \ + Class::factory_t& Class::getRegistry() \ { \ - static RegistryType* registry_s = 0; \ - if( !registry_s ) registry_s = new RegistryType; \ - return *registry_s; \ + static factory_t* s_instance = new factory_t(); \ + return factory_t::instance(); \ } // Note: this macro has to be used inside the class declaration. -#define YAKE_DECLARE_CONCRETE( Concrete, id ) \ +#define YAKE_DECLARE_CONCRETE( Concrete, ID ) \ public: \ - static RegistryType::Id getId() \ + static factory_t::key_type getId() \ { \ - return id; \ - } \ - static void Register() \ - { \ - getRegistry().doRegister( getId(), yake::SharedPtr< RegistryConfig::ConcreteCreator< Concrete > >( new RegistryConfig::ConcreteCreator< Concrete > ) ); \ + return ID; \ } -// getRegistry().doAdd( getId(), yake::SharedPtr< RegistryConfig::ConcreteCreator< Concrete > >::create() ); \ todo - // Registers a concrete implementation which has been declared before. #define YAKE_REGISTER_CONCRETE( Concrete ) \ namespace \ { \ static struct Concrete##Initor \ { \ + typedef Concrete::factory_t factory_t; \ Concrete##Initor() \ { \ static int counter = 0; \ if( counter++ > 0 ) return; \ - typedef Concrete ConcreteT; \ - ConcreteT::Register(); \ + Concrete::getRegistry().reg_ctor_smartptr<Concrete>(Concrete::getId()); \ } \ + ~Concrete##Initor() \ + { \ + Concrete::getRegistry().remove(Concrete::getId()); \ + } \ } g_##Concrete##Initor; \ } // nameless + template<typename Interface, typename Kt> + inline SharedPtr<Interface> create(const Kt& id) + { + return SharedPtr<Interface>(Interface::getRegistry().create(id)); + } + template<typename Interface, typename Kt, typename A0> + inline SharedPtr<Interface> create(const Kt& id, const A0& a0) + { + return SharedPtr<Interface>(Interface::getRegistry().create(id,a0)); + } + template<typename Interface> + inline SharedPtr<Interface> create_default() + { + return SharedPtr<Interface>(Interface::getRegistry().create_default()); + } + template<typename Interface, typename A0> + inline SharedPtr<Interface> create_default(const A0& a0) + { + return SharedPtr<Interface>(Interface::getRegistry().create_default(a0)); + } + } // templates +using templates::create; +using templates::create_default; } // yake // Declares a registry for types with an empty constructor. #define YAKE_DECLARE_REGISTRY_0(BaseClass, IdClass) \ public: \ - struct RegistryConfig \ - { \ - typedef BaseClass Base; \ - typedef IdClass Id; \ - struct ICreator \ - { \ - virtual yake::SharedPtr< Base > create() = 0; \ - }; \ - template <typename T> \ - struct ConcreteCreator : public ICreator \ - { \ - yake::SharedPtr<Base> create() \ - { return yake::SharedPtr<T>(new T); } \ - }; \ - }; \ - YAKE_DECLARE_REGISTRY() + YAKE_DECLARE_REGISTRY_EX(BaseClass, IdClass, ()) - // return yake::SharedPtr< T >::create(); \ Todo - - // Declares a registry for types with a constructor that takes one parameter. #define YAKE_DECLARE_REGISTRY_1(BaseClass, IdClass, Param1) \ public: \ - struct RegistryConfig \ - { \ - typedef BaseClass Base; \ - typedef IdClass Id; \ - struct ICreator \ - { \ - virtual yake::SharedPtr<Base> create(Param1 p1) = 0; \ - }; \ - template <typename T> \ - struct ConcreteCreator : public ICreator \ - { \ - yake::SharedPtr<Base> create(Param1 p1) \ - { return yake::SharedPtr<T>(new T(p1)); } \ - }; \ - }; \ - YAKE_DECLARE_REGISTRY() + YAKE_DECLARE_REGISTRY_EX(BaseClass, IdClass, (Param1)) -// Declares a registry for types with a constructor that takes one parameter. -#define YAKE_DECLARE_REGISTRY_01(BaseClass, IdClass, Param1) \ +#define YAKE_DECLARE_REGISTRY_2(BaseClass, IdClass, Param1, Param2) \ public: \ - struct RegistryConfig \ - { \ - typedef BaseClass Base; \ - typedef IdClass Id; \ - struct ICreator \ - { \ - virtual yake::SharedPtr<Base> create() = 0; \ - virtual yake::SharedPtr<Base> create(Param1 p1) = 0; \ - }; \ - template <typename T> \ - struct ConcreteCreator : public ICreator \ - { \ - yake::SharedPtr<Base> create() \ - { return yake::SharedPtr<T>(new T()); } \ - \ - yake::SharedPtr<Base> create(Param1 p1) \ - { return yake::SharedPtr<T>(new T(p1)); } \ - }; \ - }; \ - YAKE_DECLARE_REGISTRY() + YAKE_DECLARE_REGISTRY_EX(BaseClass, IdClass, (Param1,Param2)) #endif // YAKE_BASE_TEMPLATES_REGISTRY_H Added: trunk/yake/yake/factory/config.h =================================================================== --- trunk/yake/yake/factory/config.h (rev 0) +++ trunk/yake/yake/factory/config.h 2008-03-24 21:30:20 UTC (rev 1909) @@ -0,0 +1,9 @@ +#ifndef YAKE_FACTORY_CONFIG_H +#define YAKE_FACTORY_CONFIG_H + +#define YAKE_FACTORY_EXCEPTION_BASE std::exception +#define YAKE_FACTORY_NS ::yake::factory +#define YAKE_FACTORY_NS_BEGIN() namespace yake { namespace factory { +#define YAKE_FACTORY_NS_END() }} + +#endif Added: trunk/yake/yake/factory/dynamic_factory.h =================================================================== --- trunk/yake/yake/factory/dynamic_factory.h (rev 0) +++ trunk/yake/yake/factory/dynamic_factory.h 2008-03-24 21:30:20 UTC (rev 1909) @@ -0,0 +1,216 @@ +#ifndef YAKE_FACTORY_DYNAMIC_FACTORY_H +#define YAKE_FACTORY_DYNAMIC_FACTORY_H + +#include "config.h" +#include "policies.h" + +YAKE_FACTORY_NS_BEGIN() + +namespace detail { + + template< + class X, + typename Kt, + typename Signature> + struct creator; + + template< + class X, + typename Kt, + typename R> + struct creator<X,Kt,R()> + { + typedef boost::function<R()> function_t; + typedef R return_t; + R create(const Kt& id) + { + std::cout << "attempt create '" << typeid(X::return_t).name() << "' id='" << id << "' sig='" << typeid(X::signature_t).name() << "'\n"; + typedef X::Id2Class::const_iterator it_t; + const X& x = static_cast<X&>(*this); + it_t it = x.id2class_.find(id); + if (it == x.id2class_.end()) + { + X::error_t::onError(NotFoundException("creator not registered for id '"+id+"'")); + return R(); + } + return (it->second)(); + } + R create_default() + { + std::cout << "attempt create default sig='" << typeid(X::signature_t).name() << "'\n"; + typedef X::Id2Class::const_iterator it_t; + const X& x = static_cast<X&>(*this); + it_t it = x.id2class_.begin(); + if (it == x.id2class_.end()) + { + X::error_t::onError(NotFoundException("default creator not registered")); + return R(); + } + return (it->second)(); + } + }; + + + template< + class X, + typename Kt, + typename R, typename A0> + struct creator<X,Kt,R(A0)> + { + typedef boost::function<R(A0)> function_t; + typedef R return_t; + R create(const Kt& id, const A0& a0 = A0()) + { + std::cout << "attempt create '" << typeid(X::return_t).name() << "' id='" << id << "' sig='" << typeid(X::signature_t).name() << "'\n"; + typedef X::Id2Class::const_iterator it_t; + const X& x = static_cast<X&>(*this); + it_t it = x.id2class_.find(id); + if (it == x.id2class_.end()) + { + X::error_t::onError(NotFoundException("creator not registered for id '"+id+"'")); + return R(); + } + return (it->second)(a0); + } + R create_default(const A0& a0 = A0()) + { + std::cout << "attempt create default sig='" << typeid(X::signature_t).name() << "'\n"; + typedef X::Id2Class::const_iterator it_t; + const X& x = static_cast<X&>(*this); + it_t it = x.id2class_.begin(); + if (it == x.id2class_.end()) + { + X::error_t::onError(NotFoundException("default creator not registered")); + return R(); + } + return (it->second)(a0); + } + }; + + template< + class T, + typename Signature> + struct new_fn; + + template< + class T, + typename R> + struct new_fn<T,R()> + { + R* operator()() + { + return Holder(new T()); + } + }; + + template< + class T, + typename R, + typename A0> + struct new_fn<T,R(A0)> + { + R* operator()(const A0& a0) + { + return Holder(new T(a0)); + } + }; + + + template< + class T, + typename Holder, + typename Signature> + struct new_fn_h; + + template< + class T, + typename Holder, + typename R> + struct new_fn_h<T,Holder,R()> + { + Holder operator()() + { + return Holder(new T()); + } + }; + + template< + class T, + typename Holder, + typename R, + typename A0> + struct new_fn_h<T,Holder,R(A0)> + { + Holder operator()(const A0& a0) + { + return Holder(new T(a0)); + } + }; +} // namespace detail + + +/** + @note No virtual destructors use, so do not delete via pointer-to-base! + @param Kt key type aka ids for registered creators/products + @param Interface product base interface/class + @param Signature Signature of the creator objects/functions (e.g. MyInterface*(int,const string&)) + @param ErrorPolicy Error handling can be configured (default: NoThrowErrorPolicy). + @param InstancePolicy Factory instance policy can be configured (default: NoInstancePolicy). +*/ +template< + typename Kt, + class Interface, + typename Signature, + class ErrorPolicy = NoThrowErrorPolicy, + template<class> class InstancePolicy = NoInstancePolicy + /*,template<class,typename,typename> class CreatorType = detail::creator*/> +struct factory : + public InstancePolicy<factory<Kt,Interface,Signature,ErrorPolicy,InstancePolicy> >, + public detail::creator<factory<Kt,Interface,Signature,ErrorPolicy,InstancePolicy>,Kt,Signature > +{ + typedef Kt key_type; + typedef Interface interface_t; + typedef ErrorPolicy error_t; + typedef Signature signature_t; + + typedef detail::creator<factory<Kt,Interface,Signature,ErrorPolicy,InstancePolicy>,Kt,Signature > creator_t; + friend struct creator_t; + typedef typename creator_t::function_t function_t; + typedef typename creator_t::return_t return_t; + //using creator_t::create; + + template<typename Handler0> + void reg(const key_type& id, Handler0 h0) + { + std::cout << "reg '" << id << "'\n"; + id2class_[ id ] = function_t(h0); + } + + template<typename ProductT> + void reg_ctor(const key_type& id) + { + detail::new_fn<ProductT,,Signature> c_t; + reg(id,c_t); + } + + template<typename ProductT> + void reg_ctor_smartptr(const key_type& id) + { + detail::new_fn_h<ProductT,return_t,Signature> c_t; + reg(id,c_t); + } + + void remove(const key_type& id) + { + Id2Class::iterator it = id2class_.find(id); + if (it != id2class_.end()) + id2class_.erase(it); + } +private: + typedef std::map<key_type,function_t> Id2Class; + Id2Class id2class_; +}; + +YAKE_FACTORY_NS_END() + +#endif Added: trunk/yake/yake/factory/global_dynamic_factory.h =================================================================== --- trunk/yake/yake/factory/global_dynamic_factory.h (rev 0) +++ trunk/yake/yake/factory/global_dynamic_factory.h 2008-03-24 21:30:20 UTC (rev 1909) @@ -0,0 +1,134 @@ +#ifndef YAKE_FACTORY_GLOBAL_DYNAMIC_FACTORY_H +#define YAKE_FACTORY_GLOBAL_DYNAMIC_FACTORY_H + +#include "config.h" +#include "policies.h" +#include "dynamic_factory.h" + +YAKE_FACTORY_NS_BEGIN() + + +template<typename Interface> +struct global_interface_traits +{ + typedef Interface*(signature_t)(); + typedef boost::shared_ptr<Interface> holder_t; +}; + +/** Do NOT directly use this interface... */ +template<class Interface> +struct global_factory +{ + typedef std::string key_type; + typedef typename global_interface_traits<Interface>::signature_t signature_t; + typedef yake::factory::factory<key_type,Interface,signature_t,NoThrowErrorPolicy,SingletonPolicy> factory_t; + + //typedef typename factory_t::holder_t holder_t; + typedef typename global_interface_traits<Interface>::holder_t holder_t; + + static factory_t& instance() + { + return factory_t::instance(); + } + template<class Interface, class ConcreteT, typename CreatorFn> + void reg_product(const key_type& id, CreatorFn fn) + { + instance().reg(id,fn); + } + + template<typename Interface, typename Kt> + holder_t create(const Kt& id) + { + return instance().create(id); + } + template<typename Interface, typename Kt, typename A0> + holder_t create(const Kt& id, const A0& a0) + { + return instance().create(id,a0); + } +}; + +template<class Interface, class Kt> +typename global_interface_traits<Interface>::holder_t create(const Kt& id) +{ + typedef typename global_interface_traits<Interface>::holder_t holder_t; + return holder_t(global_factory<Interface>::instance().create(id)); +} +template<class Interface, class Kt, typename A0> +typename global_interface_traits<Interface>::holder_t create(const Kt& id, const A0& a0) +{ + typedef typename global_interface_traits<Interface>::holder_t holder_t; + return holder_t(global_factory<Interface>::instance().create(id,a0)); +} + +//////////////////////////////////////////////////////////////// +// Found in Dr.Dobb's: http://www.ddj.com/cpp/184401206 // +// Modifications: // +// added YAKE_ prefix // +// // +// // +//////////////////// UtilityMacros.h ///////////////// rado //// +// // +// Copyright (c) 1999 Radoslav Getov // +// // +// Permission to use, copy, modify and distribute this // +// software is granted without fee, provided that the above // +// copyright notice and this permission notice appear in the // +// modified source and the source files that #include it. // +// // +//////////////////////////////////////////////////////////////// +// // +#define YAKE_UNIQUE_NAME_1(prefix, x) prefix##x +#define YAKE_UNIQUE_NAME_2(prefix, x) YAKE_UNIQUE_NAME_1 (prefix, x) +#define YAKE_UNIQUE_NAME_WP(prefix) YAKE_UNIQUE_NAME_2 (prefix, __LINE__) +#define YAKE_UNIQUE_NAME YAKE_UNIQUE_NAME_WP(uniqueNameOnLine_) +#define YAKE_UNIQUE_NAME2 YAKE_UNIQUE_NAME_WP(uniqueNameOnLine2_) +// // +//////////////////////////////////////////////////////////////// + +// Shortcuts for registering global products: +// YAKE_REGISTER_GLOBAL_PRODUCT +// YAKE_REGISTER_GLOBAL_PRODUCT1 + +#define YAKE_REGISTER_GLOBAL_PRODUCT(INTERFACE,PRODUCT,ID,CREATORFN) \ +namespace { \ +struct YAKE_UNIQUE_NAME \ +{ \ + YAKE_UNIQUE_NAME() \ + { \ + YAKE_FACTORY_NS::global_factory<INTERFACE>::instance().reg(ID,boost::bind(CREATORFN)); \ + } \ +} YAKE_UNIQUE_NAME2; \ +} +#define YAKE_REGISTER_GLOBAL_PRODUCT1(INTERFACE,PRODUCT,ID,CREATORFN) \ +namespace { \ +struct YAKE_UNIQUE_NAME \ +{ \ + YAKE_UNIQUE_NAME() \ + { \ + YAKE_FACTORY_NS::global_factory<INTERFACE>::instance().reg(ID,boost::bind(CREATORFN,_1)); \ + } \ +} YAKE_UNIQUE_NAME2; \ +} + +// Shortcuts for registering global factories: +// YAKE_REGISTER_GLOBAL_FACTORY_EX +// YAKE_REGISTER_GLOBAL_FACTORY + +#define YAKE_REGISTER_GLOBAL_FACTORY_EX(INTERFACE,RETURNTYPE,PARAMS,HOLDER) \ + YAKE_FACTORY_NS_BEGIN() \ + template<> \ + struct global_interface_traits<INTERFACE> \ + { \ + typedef RETURNTYPE(signature_t)PARAMS; \ + typedef HOLDER holder_t; \ + }; \ + YAKE_FACTORY_NS_END() + +#define YAKE_REGISTER_GLOBAL_FACTORY(INTERFACE,PARAMS) \ + YAKE_REGISTER_GLOBAL_FACTORY_EX(INTERFACE,INTERFACE *,PARAMS,boost::shared_ptr<INTERFACE>) + + +YAKE_FACTORY_NS_END() + +#endif Added: trunk/yake/yake/factory/policies.h =================================================================== --- trunk/yake/yake/factory/policies.h (rev 0) +++ trunk/yake/yake/factory/policies.h 2008-03-24 21:30:20 UTC (rev 1909) @@ -0,0 +1,70 @@ +#ifndef YAKE_FACTORY_POLICIES_H +#define YAKE_FACTORY_POLICIES_H + +#include "config.h" +#include <string> +#include <iostream> // for the std::cerr (used in error policies) +#include <map> +#include <exception> +#include <boost/shared_ptr.hpp> +#include <boost/function.hpp> +#include <boost/bind.hpp> + +YAKE_FACTORY_NS_BEGIN() + + +// Exceptions + +struct Exception : public std::exception +{ + Exception(const std::string& msg) : msg_(msg) + {} + virtual const char* what() const + { + return msg_.c_str(); + } +private: + std::string msg_; +}; +typedef Exception NotFoundException; + +// Error Policies + +struct NoThrowErrorPolicy +{ + template<typename Et> + static void onError(const Et& ex) + { + std::cerr << "ERROR: " << ex.what() << "\n"; + } +}; +struct ThrowErrorPolicy +{ + template<typename Et> + static void onError(const Et& ex) + { + std::cerr << "ERROR: " << ex.what() << "\n"; + throw ex; + } +}; + +// Instance Policies + +template<class X> +struct NoInstancePolicy +{ +}; + +template<class X> +struct SingletonPolicy +{ + static X& instance() + { + static X s_instance; + return s_instance; + } +}; + +YAKE_FACTORY_NS_END() + +#endif Modified: trunk/yake/yake/graphics/yakeGraphicalWorld.h =================================================================== --- trunk/yake/yake/graphics/yakeGraphicalWorld.h 2008-01-20 21:50:46 UTC (rev 1908) +++ trunk/yake/yake/graphics/yakeGraphicalWorld.h 2008-03-24 21:30:20 UTC (rev 1909) @@ -470,7 +470,6 @@ class YAKE_GRAPHICS_INTERFACE_API IFx { - YAKE_DECLARE_REGISTRY_01(IFx, String, IWorld&); public: virtual ~IFx() {} }; @@ -478,5 +477,7 @@ } // graphics } // yake +YAKE_REGISTER_GLOBAL_FACTORY( yake::graphics::IFx, (yake::graphics::IWorld&) ) + #endif // YAKE_GRAPHICALWORLD_H Modified: trunk/yake/yake/graphics/yakeGraphicsSystem.h =================================================================== --- trunk/yake/yake/graphics/yakeGraphicsSystem.h 2008-01-20 21:50:46 UTC (rev 1908) +++ trunk/yake/yake/graphics/yakeGraphicsSystem.h 2008-03-24 21:30:20 UTC (rev 1909) @@ -76,7 +76,7 @@ { typedef AssocVector<String, String> ParamMap; - YAKE_DECLARE_REGISTRY_01(IGraphicsSystem, String, ParamMap); + YAKE_DECLARE_REGISTRY_1(IGraphicsSystem, String, ParamMap); virtual ~IGraphicsSystem(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |