I have an a simple Registry pattern:
class Object
{
//some secondary simple methods
};
#define OBJECT_DEF(Name) \
public: \
static const char* Name() { return Name; } \
private:
class Registry
{
struct string_less {
bool operator() (const std::string& str1, const std::string& str2) {
for(int i = 0; i < str1.size() && i < str2.size(); ++i) {
if(str1[i] != str2[i])
return str1[i] < str2[i];
}
return str1.size() < str2.size();
}
};
typedef boost::shared_ptr < Object> ptrInterface;
typedef std::map < std::string, ptrInterface, string_less > container;
container registry;
static Registry _instance;
ptrInterface find(std::string name);
protected:
Registry () {}
~Registry () {}
public:
template < class T >
static T* Get(); // I want to write so !!!
template < class T >
static bool Set(T* instance, bool reSet = false);
};
And if i have a class that exteds Object:
class Foo : public Object {
OBJECT_DEF("foo");
//smth
};
I want to use Registry such way:
Registry::Set(new Foo());
or
Registry::Get<Foo>();
How can I emulate static templates with external implementation?