From 6a1ab6787e87b6859bd93436f2ef99b08d7d6efb Mon Sep 17 00:00:00 2001 From: kohait Date: Wed, 31 Aug 2011 08:45:34 +0000 Subject: [PATCH] bazaar: Gen: Instancer simplification, Misc.h not included by default git-svn-id: svn://ultimatepp.org/upp/trunk@3804 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/Dispatcher/Dispatcher.h | 1 + bazaar/Gen/Gen.cpp | 6 +++--- bazaar/Gen/Gen.h | 39 +++++++++------------------------- bazaar/Gen/Misc.h | 22 +++++++++++++++++++ bazaar/ValueCtrl/ValueCtrl.cpp | 2 +- 5 files changed, 37 insertions(+), 33 deletions(-) diff --git a/bazaar/Dispatcher/Dispatcher.h b/bazaar/Dispatcher/Dispatcher.h index c3b7312c8..073c67dfc 100644 --- a/bazaar/Dispatcher/Dispatcher.h +++ b/bazaar/Dispatcher/Dispatcher.h @@ -5,6 +5,7 @@ using namespace Upp; #include +#include template class Dispatcher; diff --git a/bazaar/Gen/Gen.cpp b/bazaar/Gen/Gen.cpp index e1e21b902..416bc8f7b 100644 --- a/bazaar/Gen/Gen.cpp +++ b/bazaar/Gen/Gen.cpp @@ -2,10 +2,10 @@ NAMESPACE_UPP -VectorMap& GetGlobalInstancerMap() +GlobalInstancerMapType& GetGlobalInstancerMap() { - static VectorMap map; - return map; + static GlobalInstancerMapType _; + return _; } END_UPP_NAMESPACE \ No newline at end of file diff --git a/bazaar/Gen/Gen.h b/bazaar/Gen/Gen.h index f4ef71ec8..0e0e3ad6d 100644 --- a/bazaar/Gen/Gen.h +++ b/bazaar/Gen/Gen.h @@ -3,8 +3,6 @@ #include -#include "Misc.h" - NAMESPACE_UPP //copyable interface, implementing the Copy function, used i.e. by PolyDeepCopyNew @@ -101,7 +99,8 @@ public: }; typedef void*(*GlobalInstancerType)(); -VectorMap& GetGlobalInstancerMap(); +typedef VectorMap GlobalInstancerMapType; +GlobalInstancerMapType& GetGlobalInstancerMap(); //Instancer help class, for maps of Instancers. the static Map should //somewhere be ONCELOCK initialized with the elements @@ -111,16 +110,20 @@ template class Instancer { public: - typedef B*(*InstancerType)(); + typedef B*(*Type)(); + typedef VectorMap MapType; + template class Typed { public: static B* GetInstance() { return new T(); } - static InstancerType GetInstancer() { return &GetInstance; } + static Type GetInstancer() { return &GetInstance; } static GlobalInstancerType GetGlobalInstancer() { return (GlobalInstancerType)&GetInstance; } }; - static VectorMap& Map() { static VectorMap map; return map; } + + static B* GetInstance() { return Typed::GetInstance(); } + static MapType& Map() { static MapType _; return _; } }; template inline String TypeOfS(T* = 0) { return String(typeid(T).name()); } @@ -156,7 +159,7 @@ protected: //to declare a class beeing partaker in Instanciating. //T is the interface / class that should be acessible at base template -class Instancing : public TypeHook {}; +class Instance : public TypeHook {}; template class Shared : Moveable< Shared > { @@ -219,28 +222,6 @@ public: } }; -//a visiting interface -template -class Visiting : public B -{ -public: - typedef Visiting CLASSNAME; - Visiting() : pt(NULL) {} - virtual ~Visiting() {} - - virtual void Visit(T& t) { pt = &t; Reload(); } - virtual void Reload() { } - virtual void Clear() { pt = NULL; } - - bool IsVisiting() const { return pt; } - bool IsEmpty() const { return !IsVisiting(); } - - T& Get() const { return *pt; } - -protected: - T* pt; -}; - template class Scaler { diff --git a/bazaar/Gen/Misc.h b/bazaar/Gen/Misc.h index 480fb55a0..3c5326c9d 100644 --- a/bazaar/Gen/Misc.h +++ b/bazaar/Gen/Misc.h @@ -80,6 +80,28 @@ protected: bool nn; }; +//a visiting interface +template +class Visiting : public B +{ +public: + typedef Visiting CLASSNAME; + Visiting() : pt(NULL) {} + virtual ~Visiting() {} + + virtual void Visit(T& t) { pt = &t; Reload(); } + virtual void Reload() { } + virtual void Clear() { pt = NULL; } + + bool IsVisiting() const { return pt; } + bool IsEmpty() const { return !IsVisiting(); } + + T& Get() const { return *pt; } + +protected: + T* pt; +}; + END_UPP_NAMESPACE #endif diff --git a/bazaar/ValueCtrl/ValueCtrl.cpp b/bazaar/ValueCtrl/ValueCtrl.cpp index c8d678aec..29903d162 100644 --- a/bazaar/ValueCtrl/ValueCtrl.cpp +++ b/bazaar/ValueCtrl/ValueCtrl.cpp @@ -7,7 +7,7 @@ Ctrl* OptionInstancer() INITBLOCK { - VectorMap::InstancerType>& map = Instancer::Map(); + Instancer::MapType& map = Instancer::Map(); map.Add(int(INT_V), Instancer::Typed >::GetInstancer()); map.Add(int(DOUBLE_V), Instancer::Typed >::GetInstancer());