This is the mail archive of the cygwin-talk mailing list for the cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: how come #include "*.cpp" works?


Dave Korn wrote:
On 18 May 2006 15:45, mwoehlke wrote:

Anyway... what I do is have an "OBJ" ABC and subclass it for each type
of structure I want this program to be able to understand. What I want
to do is have some system that entails the fewest *lines* of code
(macros to turn one line into lots of *actual* code are OK) that can a:
construct an object by name, and b: provide me a list of names of
classes which can be created (i.e. if you enter an invalid one, it will
tell you valid ones). Any thoughts? (Maybe dropping a hippo on the code
will make it as small as I want it to be? ;-))

Something like this?
(moved below)

Hey, that's pretty slick... thanks!

Upon further thought, I may actually do something with my Makefile and auto-generation of some file, but I think I'm still going to use part of this. (Having an entire class declaration inside of a macro kind-of rubs me wrong ;-). Also, I want to keep each class in its own header.)

--
Matthew
Hey, buddy, if it's OT, TITTTL!

--
subclasses.def:
---------------

SUBCLASS (class1_name,
	void class1_func1 (int args, ... ); \
	int class1_func2 (int args, ... ); \
           .... \
       private: \
       int m_foo; \
)

SUBCLASS (class2_name,
	void class2_func1 (int args, ... ); \
	int class2_func2 (int args, ... ); \
           .... \
       private: \
       void *m_foo; \
)

subclass_list.cpp
-----------------

#define SUBCLASS (A, B) { ## A , gen_ # A }

struct subclassdata {
	const char *name;
	ABC * (*gen_func)();
};

const struct subclassdata subclasslist[] = {
#include "subclasses.def"
};

#undef SUBCLASS
#define SUBCLASS (A, B) \
ABC *gen_ # A () \
{ \
	return new A; \
};

#include "subclasses.def"


subclass_defns.h ----------------

#undef SUBCLASS
#define SUBCLASS (A, B) \
class A : public ABC { \
B \
};


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]