bazaar: Gen: Instancer simplification, Misc.h not included by default

git-svn-id: svn://ultimatepp.org/upp/trunk@3804 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
kohait 2011-08-31 08:45:34 +00:00
parent c3d35782a9
commit 6a1ab6787e
5 changed files with 37 additions and 33 deletions

View file

@ -5,6 +5,7 @@
using namespace Upp;
#include <Gen/Gen.h>
#include <Gen/Misc.h>
template<class T> class Dispatcher;

View file

@ -2,10 +2,10 @@
NAMESPACE_UPP
VectorMap<Value, GlobalInstancerType>& GetGlobalInstancerMap()
GlobalInstancerMapType& GetGlobalInstancerMap()
{
static VectorMap<Value, GlobalInstancerType> map;
return map;
static GlobalInstancerMapType _;
return _;
}
END_UPP_NAMESPACE

View file

@ -3,8 +3,6 @@
#include <Core/Core.h>
#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<Value, GlobalInstancerType>& GetGlobalInstancerMap();
typedef VectorMap<Value, GlobalInstancerType> 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 B>
class Instancer
{
public:
typedef B*(*InstancerType)();
typedef B*(*Type)();
typedef VectorMap<Value, Type> MapType;
template<class T = B>
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<Value, InstancerType>& Map() { static VectorMap<Value, InstancerType> map; return map; }
static B* GetInstance() { return Typed<B>::GetInstance(); }
static MapType& Map() { static MapType _; return _; }
};
template<class T> 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 T>
class Instancing : public TypeHook<T, Typer> {};
class Instance : public TypeHook<T, Typer> {};
template <class T>
class Shared : Moveable< Shared<T> > {
@ -219,28 +222,6 @@ public:
}
};
//a visiting interface
template<class T, class B = EmptyClass>
class Visiting : public B
{
public:
typedef Visiting<T,B> 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 T = double>
class Scaler
{

View file

@ -80,6 +80,28 @@ protected:
bool nn;
};
//a visiting interface
template<class T, class B = EmptyClass>
class Visiting : public B
{
public:
typedef Visiting<T,B> 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

View file

@ -7,7 +7,7 @@ Ctrl* OptionInstancer()
INITBLOCK
{
VectorMap<Value, Instancer<Ctrl>::InstancerType>& map = Instancer<Ctrl>::Map();
Instancer<Ctrl>::MapType& map = Instancer<Ctrl>::Map();
map.Add(int(INT_V), Instancer<Ctrl>::Typed<WithEnterAction<EditInt> >::GetInstancer());
map.Add(int(DOUBLE_V), Instancer<Ctrl>::Typed<WithEnterAction<EditDouble> >::GetInstancer());