@Zhalman - Hmm... that works. I was hoping to avoid needing to use macros for every member variable, but there are some advantages to that. I like the idea of being able to just do a mapping of names to types like that, so I'll keep a note. In terms of usefulness, I'll explain below.
@Julian90 - That's super awesome... I think that's pretty close to exactly what I need.
Filling in the extra information - my templated MemVarInstace classes all derive from a common base class that serves as an interface to the MemVarInstance, plus it allows them to all autolist by type. I have an AutoLister Mixin class which the base class derives from which adds the MemVarInstance to a list in its constructor. I also have similar macros for registering full on classes, which the MemVars may wind up accessing later. The ultimate goal for all this is to use it for auto-generating serialization code, network replication, and binding to scripting languages.
It looks kind of like this -
class IMemVar{public: virtual size_t SizeOf()=0; virtual size_t OffsetOf()=0; //this breaks the "pure virtualness", but leads to less templated code const char* name; };//This class creates a Type for the Memvars to AutoList to// - wish I could get rid of the MI, but it isn't really harmful heretemplate < class MemberOf >class BaseMemVar : public IMemVar, public AutoLister< BaseMemVar< MemberOf > >{public: BaseMemVar() {}};//This is the same as the "MemVarInstance" thing I was talking about abovetemplate < class MemberOf, class MemberType >class MemVarImpl : public BaseMemVar< MemberOf >{public: MemVarImpl(const char* _name, size_t Offset):name(_name), offset(Offset) {} size_t SizeOf() { return sizeof(MemberType); } //offsetof is used as part of the registration macro size_t OffsetOf() { return offset; } size_t offset;};
I also have some external functions which search through the (auto)lists and can generate pointers, etc, based on string names, hence the serialization, scripting, etc... as an optimization later on, I was planning on generating TypeID's after startup by iterating through the lists (after sorting to get around uncertainties based on compiler, etc... )
The idea is that other people will simply create client classes, then expose them to this system by using the Macros in the .cpp file. This will give them all the functionality of the autosystem. I'm also trying to leave some hooks for people to overload the autogeneration system (probably through explicit template specialization of their class) to write their own optimized or specialized versions of serialization or whatever.
Thanks a bunch for the suggestion! I'll have to try it out after work tonight!