1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
class SharedVarRepo
{
typedef SharedVarBase VarBaseType; // All SharedVar<T>'s are derived from this.
...
};
template <class PlRepo = SharedVarRepo> // Default repository is SharedVarRepo
class Engine : public PlRepo
{
protected:
// For any type that is derived from PlRepo::VarBaseType, IsRepoVar = true
// all the other types get IsRepoVar = false
struct EmptyType {};
template <class T, bool IsRepoVar = std::tr1::is_base_of<typename PlRepo::VarBaseType, T>::value> struct Assist;
// Specialisation for Assist<int>, Assist<MyClass>, ...
template <class T> struct Assist<T, false>
{
typedef EmptyType SubType;
};
// Specialisation for Assist<SharedVar<int> >, Assist<SharedVar<float> >, Assist<SharedVarBase *>, ...
template <class T> struct Assist<T, true>
{
typedef typename T::Type SubType;
};
public:
template <class T>
int GetVar(const std::string &Name, T &Var)
{ return GetVar(Name, Var, typename Assist<T>::SubType() ); }
protected:
// GetVar calls with the SharedVarBase derivatives go here
template <class T, class U>
int GetVar(const std::string &Name, T &Var, U const &Dummy);
// GetVar calls with any other type go here
template <class T>
int GetVar(const std::string &Name, T &Var, EmptyType const &Dummy);
|