C
cppnow
Hello. I have a strange conceptual problem I'm trying to think about.
I would like to build a library that allows the user to do the
following:
1) User defined types:
The user defines their own types as needed for their particular
application and registers them with the library.
class ClassA {};
class ClassB : public ClassA {};
class ClassC: public ClassB{};
REGISTERTYPE(ClassA);
REGISTERTYPE(ClassB);
REGISTERTYPE(ClassC);
2) User defined functions:
The user defines a set of functions as needed for their particular
application and registers them with the library.
ClassA Function1(ClassB);
ClassB Function2(ClassB);
ClassC Function3(ClassC, ClassB);
ClassC Function4(ClassC);
REGISTERFUNCTION(Function1);
REGISTERFUNCTION(Function2);
REGISTERFUNCTION(Function3);
REGISTERFUNCTION(Function4);
3) The user can then query the library for functions that return the
type it requires and call those functions and get an object of the
desired type OR a type that can be implicitly converted to the desired
type:
// User needs a ClassA object
vector<ClassA> results;
vector<something?> functions = GetFunctions(some way to indicate
ClassA);
// GetFunctions should return [pointers/function objs/something else?]
for Functions 1, 2, 3 and 4
// (since a ClassA object can be obtained from them or implicitly
converted from their return types)
for(functions::const_itr itr = functions.begin(); itr !=
functions.end(); itr++)
results.push_back(CALLFUNCTION(itr));
I'm trying to develop an architecture that would permit this... I'm
thinking the registration functions would need some kind of template
metaprogramming code... could this maybe be done simply with
polymorphism and virtual functions? Boost::any was another idea I
considered.
I think I am getting stuck in two areas: trying to query for the
return type of a function and then trying to determine if that return
type can be implicitly converted to some other type (either because
the return type is a derived class of the desired type or because the
return type has an implicit conversion operator to the desired type).
Any info appreciated. Obviously not looking for code, more just tips
on how to think about this kind of a problem.
Cheers
I would like to build a library that allows the user to do the
following:
1) User defined types:
The user defines their own types as needed for their particular
application and registers them with the library.
class ClassA {};
class ClassB : public ClassA {};
class ClassC: public ClassB{};
REGISTERTYPE(ClassA);
REGISTERTYPE(ClassB);
REGISTERTYPE(ClassC);
2) User defined functions:
The user defines a set of functions as needed for their particular
application and registers them with the library.
ClassA Function1(ClassB);
ClassB Function2(ClassB);
ClassC Function3(ClassC, ClassB);
ClassC Function4(ClassC);
REGISTERFUNCTION(Function1);
REGISTERFUNCTION(Function2);
REGISTERFUNCTION(Function3);
REGISTERFUNCTION(Function4);
3) The user can then query the library for functions that return the
type it requires and call those functions and get an object of the
desired type OR a type that can be implicitly converted to the desired
type:
// User needs a ClassA object
vector<ClassA> results;
vector<something?> functions = GetFunctions(some way to indicate
ClassA);
// GetFunctions should return [pointers/function objs/something else?]
for Functions 1, 2, 3 and 4
// (since a ClassA object can be obtained from them or implicitly
converted from their return types)
for(functions::const_itr itr = functions.begin(); itr !=
functions.end(); itr++)
results.push_back(CALLFUNCTION(itr));
I'm trying to develop an architecture that would permit this... I'm
thinking the registration functions would need some kind of template
metaprogramming code... could this maybe be done simply with
polymorphism and virtual functions? Boost::any was another idea I
considered.
I think I am getting stuck in two areas: trying to query for the
return type of a function and then trying to determine if that return
type can be implicitly converted to some other type (either because
the return type is a derived class of the desired type or because the
return type has an implicit conversion operator to the desired type).
Any info appreciated. Obviously not looking for code, more just tips
on how to think about this kind of a problem.
Cheers