generic properties from objects

J

Jon Slaughter

Lets assume I want to write a whole host of classes having "property"
elements in them and create a bunch of objects from the different classes.
Lets suppose that they are circles, lines, etc... and I display them on the
screen for the user. Now I want to have a window that allows the user to
modify all the "properties" of the object.

It is very similar in how VS.net has a window pane that lets you modify the
different default values of data types in a class.


Is there an easy way of doing this?

example:

class A
{
public:
Set_Prop1(int val)
{
prop1 = val;
};
properties:
private int prop1<'A'=1, 'B'=3>
};

the properties clause basicaly says that prop1 is a property of that class
and can take on the value 'A' or 'B' each translating in the 1 or 3.

Then say I want to display all the properties of A I could do something like

int i = A.num_properties;
while(i > 0)
{
i--;

cout << A.properties.name;
for(int j = 0; j < A.properties.num_elements; j++)
{
cout << A.properties.element_name[j];
cout << A.properties.element_val[j];
}
}

[the display would be something like this]

prop1
A B
1 3



or something like that(I know its not valid C++ code but just to give an
idea of what I want to do). If you can't do it in C++ easily can you do it
in C#? I'm looking for a way to do this with the least amount of hassle. (I
could do this, say, by writing out all the properties in an XML file and
having a class load that and use that for the information.. but then if I
change the properties of the class I have to go modify the xml, etc....)

Thanks
Jon

(I figure that it might be possible with templates, but I'm just relearning
the basics of those and I can't think about how to use them to do it)
 
P

Panjandrum

Jon said:
Lets assume I want to write a whole host of classes having "property"
elements in them and create a bunch of objects from the different classes.
Lets suppose that they are circles, lines, etc... and I display them on the
screen for the user. Now I want to have a window that allows the user to
modify all the "properties" of the object.

It is very similar in how VS.net has a window pane that lets you modify the
different default values of data types in a class.

Is there an easy way of doing this?

You find many 'Properties in C++' approaches on the internet, e.g.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1615.pdf
 

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

Members online

Forum statistics

Threads
473,780
Messages
2,569,610
Members
45,254
Latest member
Top Crypto TwitterChannel

Latest Threads

Top