Pre-Processor code generation

J

Jon Slaughter

I previously posted a msg about how to do create "properties" for classes
and after thinking a bit it seems that one has to have the pre-processor
create some code to do it.

Say I wanted to "extend" C++ classes so that I have something like

class A
{
blah...

properties:
private int prop1 = enum.list {A = 1, ... Z = 26, Off = 0}[default
value]
private int prop2 = enum.range {1, 15, 1}[1] // 1..15 by steps of 1

for example.

This would translate internally into something like

class A
{
private:
int prop1;
int prop2;
blah...

public:
static list<property> properties; // the reason it is static is that all
objects would have the same property specifiers and names so there is no
need to duplicate it for each object.

A()
{
set_Prop1(default value)
...
}

void set_Prop1(int value)
{
// translates lits and checks ranges and such (all the necessary info is
in the properties list)
prop1 = value;
}

}



is there any way to do something like this? (I'm not saying what I have is
the best or will work, just suppose to give an idea)

I was thinking I could use some macro's to possibly define some stuff... but
I would have to "insert" code into several locations and not just the
location that the macro is called at.

I'm not really looking for a hack to do this, but some way that already
exists in the language... would be nice is there is a way to do some
extensive "meta-programming" to get this done(like set it up so the
pre-processor understands what a "properties clause" is in a class.)

Any ideas?

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top