This is the mail archive of the
cygwin-talk
mailing list for the cygwin project.
RE: how come #include "*.cpp" works?
- From: "Dave Korn" <dave dot korn at artimi dot com>
- To: "'The Disgracefully On-Topic Cygwin-Talk Maiming List'" <cygwin-talk at cygwin dot com>
- Date: Thu, 18 May 2006 18:23:18 +0100
- Subject: RE: how come #include "*.cpp" works?
- Reply-to: The Cygwin-Talk Maiming List <cygwin-talk at cygwin dot com>
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?
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 \
};
cheers,
DaveK
--
Can't think of a witty .sigline today....