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

meta pre-processor 23
Code sharing 2
Picture Comparison Code Not Working Properly 1
How to fix this code? 1
help me with my code 1
Problem with code 6
Code help please 4
Help with code 0

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top