reflection library

A

alessio211734

Hello,

I have some class described as a template class...

template class Point3<T>
{
.....

}

I would like add some reflection informations to this class because I
need to do an editor and it should keep trace to every object in the
environment,
and the property of every object in my scene should be modified at
runtime.
Can someone suggest me a good reflection library to do it that work
with template?

Thanks in advance.
 
F

Francesco S. Carta

Hello,

I have some class described as a template class...

template class Point3<T>
{
....

}

I would like add some reflection informations to this class because I
need to do an editor and it should keep trace to every object in the
environment,
and the property of every object in my scene should be modified at
runtime.
Can someone suggest me a good reflection library to do it that work
with template?

If you're just interested in simple mirroring you could avoid including
and external library into your program. The math involved in such
operations is really basic, you could add them yourself in a couple of
minutes.

Besides, no, I don't know of any such library that works with templates,
only libraries that are limited to specifically tailored C structs.
 
V

Vladimir Jovic

alessio211734 said:
Hello,

I have some class described as a template class...

template class Point3<T>
{
....

}

I would like add some reflection informations to this class because I
need to do an editor and it should keep trace to every object in the
environment,
and the property of every object in my scene should be modified at
runtime.
Can someone suggest me a good reflection library to do it that work
with template?

Not sure if this works with templates :
http://code.google.com/p/pococapsule/
 
F

Francesco S. Carta

Did you find it on the fly with a web search? The following uses the
words "reflection" and "projection" but doesn't seem to have anything to
do with 3D stuff:

http://code.google.com/p/pococapsule/wiki/Reflection_from_Projection

I think that whole thing is all about different stuff WRT what the OP is
looking for.

OK, now I realize that I completely misunderstood the OP, while _you_
got it right.

Damn, that "Point3" completely mislead me. Sorry.
 
V

Vladimir Jovic

Francesco said:
Did you find it on the fly with a web search? The following uses the

No, I tried the library before. I know it is hard to find a reflection
library ;)
 
F

Francesco S. Carta

No, I tried the library before. I know it is hard to find a reflection
library ;)

I corrected myself in my self-follow-up: I completely misunderstood the
OP and hence your reply looked completely out-of-place to my eyes -
sorry, my fault.
 
A

alessio211734

Ok, I have some 3d math object class definined in a header and every
class is templated.
I would like know if someone know a c++ library to implement
reflection that works with class defined as template.

for example:

template <class T> Point3<T>
{

.... method
inline Point3<T> operator + ( Point3<T> const & num){...}

// vector x,y,z
T v[3];
}

I need to store several instance at runtime and every instance of
Point3<float> should be accessible at runtime. I would like for
example change the Point3<float> instance (v values) at runtime and
call operator + for two Point3<float> instance object at runtime.


what's the best solution to do it?
 
F

Francesco S. Carta

Ok, I have some 3d math object class definined in a header and every
class is templated.
I would like know if someone know a c++ library to implement
reflection that works with class defined as template.

for example:

template<class T> Point3<T>
{

... method
inline Point3<T> operator + ( Point3<T> const& num){...}

// vector x,y,z
T v[3];
}

I need to store several instance at runtime and every instance of
Point3<float> should be accessible at runtime. I would like for
example change the Point3<float> instance (v values) at runtime and
call operator + for two Point3<float> instance object at runtime.


what's the best solution to do it?


With the premise that I'm far away from fully understanding what this
"reflection" thingie is all about, I wonder if you couldn't simply store
pointers to those instances - in the editor you could then have a lot of
different "collections" which indirectly refer to the actual instances.

I must admit that I'm not so sure I fully understand your paragraph
above - everything a program does is done at runtime, I don't understand
why you're specifying it.

Maybe you can post a practical example of the code you want to use,
pseudo code could be fine too. That could help you getting more replies,
and since this is something I've done without using any external
library, I could eventually expose the approach I used.
 
J

Jonathan Lee

I need to store several instance at runtime and every instance of
Point3<float> should be accessible at runtime. I would like for
example change the Point3<float> instance (v values) at runtime and
call operator + for two Point3<float> instance object at runtime.

what's the best solution to do it?


What's insufficient about overloading operator+() ? I don't see
where reflection comes into it unless you're doing something that
causes the type information to be lost at runtime.

--Jonathan
 
A

alessio211734

Ok I try show you an example what's I would like do.

Maybe reflection is not needed.

class Env
{
enum typeObj{ POINT, MATRIX};

Point3<float> & getPoint(string name){ return vpoint[name]; };
Point3<float> & getMatrix(string name){ return vmatrix[name]; };

// add in enviroment the point
void AddNewPoint(const Point3<float> & point,string name)
{
vpoint[name]=point;
}
Point3<float> & FindPoint(string name) { return vpoint[name]; };
...
map< string, typeObj> vtype;
map< string, Point3<float> > vpoint;
map< string, Matrix3<float> vmatrix;
}


user can create via gui a points and add it to enviroment
(AddNewPoint) or select a point (FindPoint).
I should show in the graphics widget the coordinate of the point for
examples.

I get the point was created but how retrive the points attribute?
I need to implement a method into class point that display in the gui
the point attribute.
To avoid it with reflection I could have for every general object the
list of attribute and I not need create a method for every class
to display in the gui in a different way.
What's I would like is something as the debugger do. I watch a
variable open it and view the field information and modified them.
 
J

Jonathan Lee

user can create via gui a points and add it to enviroment
(AddNewPoint) or select a point (FindPoint).
I should show in the graphics widget the coordinate of the point for
examples.

I get the point was created but how retrive the points attribute?
I need to implement a method into class point that display in the gui
the point attribute.
To avoid it with reflection I could have for every general object the
list of attribute and I not need create a method for every class
to display in the gui in a different way.

Ah, I see now. I think in people often use the visitor pattern
for that kind of thing:

http://sourcemaking.com/design_patterns/visitor

I haven't. Inheritence or overloading different draw() methods for
each type has always done the job for me.

--Jonathan
 
F

Francesco S. Carta

Ok I try show you an example what's I would like do.

Maybe reflection is not needed.

class Env
{
enum typeObj{ POINT, MATRIX};

Point3<float> & getPoint(string name){ return vpoint[name]; };
Point3<float> & getMatrix(string name){ return vmatrix[name]; };

// add in enviroment the point
void AddNewPoint(const Point3<float> & point,string name)
{
vpoint[name]=point;
}
Point3<float> & FindPoint(string name) { return vpoint[name]; };
...
map< string, typeObj> vtype;
map< string, Point3<float> > vpoint;
map< string, Matrix3<float> vmatrix;
}


user can create via gui a points and add it to enviroment
(AddNewPoint) or select a point (FindPoint).
I should show in the graphics widget the coordinate of the point for
examples.

I get the point was created but how retrive the points attribute?
I need to implement a method into class point that display in the gui
the point attribute.
To avoid it with reflection I could have for every general object the
list of attribute and I not need create a method for every class
to display in the gui in a different way.
What's I would like is something as the debugger do. I watch a
variable open it and view the field information and modified them.

Jonathan pointed out the visitor pattern, and that could well solve your
problem - although, just like him, I prefer more direct ways of solving
such issues.

Besides, there is something wrong in the code you posted.

How can it be that GetMatrix() returns a Point3?

When AddNewPoint() is fed with an existing string, it overwrites the old
point, and also, when calling FindPoint() with a non-existing string, a
new point gets added (hopefully created with default values)... is all
of that expected to behave in this way?
 
A

alessio211734

When AddNewPoint() is fed with an existing string, it overwrites the old
point, and also, when calling FindPoint() with a non-existing string, a
new point gets added (hopefully created with default values)... is all
of that expected to behave in this way?

Sorry, I write trash code in five minutes only for this post to
explain what would like do.
Yes I think it's a correct behavior, I can't define two points with
the same name.
No the user create with gui a new point or a new matrix (or delete it)
and then through the gui can select a
alrealdy defined object as a matrix or point and at this point came
into the findPoint (after user click on the object name)
I call FindPoint or FindMatrix to get the object instance. The problem
matrix or point could have the same name with this implementation.

I need a class operation to add a type information to object.
I need to do some things as M1*M2*M3*p where M1,M2,M3 are matrix and p
is a point3d and defined new type as line, plane and so on.

I need to check some control on the operation I will do, because user
should not select a matrix and a line and call the operation
LinePlaneIntersection.
 
F

Francesco S. Carta

Sorry, I write trash code in five minutes only for this post to
explain what would like do.
Yes I think it's a correct behavior, I can't define two points with
the same name.
No the user create with gui a new point or a new matrix (or delete it)
and then through the gui can select a
alrealdy defined object as a matrix or point and at this point came
into the findPoint (after user click on the object name)
I call FindPoint or FindMatrix to get the object instance. The problem
matrix or point could have the same name with this implementation.

Then be sure to enforce such things in your code, intercept the special
cases and prompt the user for decision, instead of directly overwriting
existing names or creating objects by default in a "find" function.
I need a class operation to add a type information to object.

I think you should simply add the appropriate information to each
appropriate object, but if you prefer decoupling such things it's up to you.
I need to do some things as M1*M2*M3*p where M1,M2,M3 are matrix and p
is a point3d and defined new type as line, plane and so on.

I need to check some control on the operation I will do, because user
should not select a matrix and a line and call the operation
LinePlaneIntersection.

As I see it, users should not be able to select a matrix at all. I
wonder what you're using them for.

An expectable structure could be:

- point3: three scalars
- edge: references or pointers to two point3
- face: references or pointers to three edges
- mesh: references or pointers to many faces
- group/object: references or pointers to many meshes

Any of the above can be implemented as a separate class and can have
additional properties, for example, faces can have different textures
and edges can have different creasing angles.

Matrices come into play when you have to store positions and
orientations of one or more of the above, but I'm not able to see them
as separate objects that the user can select.

As for what concerns the expression "M1*M2*M3*p", you can take advantage
of closure objects in order to avoid copying lot of data around. The C++
Programming Language by B. Stroustrup gives an example of such a closure
object, you can also look up that technique on a search engine and find
some examples.

Hope that helps improve your design.
 
A

alessio211734

As for what concerns the expression "M1*M2*M3*p", you can take advantage
of closure objects in order to avoid copying lot of data around. The C++
Programming Language by B. Stroustrup gives an example of such a closure
object, you can also look up that technique on a search engine and find
some examples.

I think my editor 3d as a very simplified matlab tool with a 3d viewer
in opengl.
Maybe I need to cancatenate some matrix transformation and apply it to
a triangle or a mesh and I want view the final 3d position and
orientation.
This should give me the possibility to make calculations in fast way
without I need sketch on a paper and use calculator.
 
F

Francesco S. Carta

I think my editor 3d as a very simplified matlab tool with a 3d viewer
in opengl.
Maybe I need to cancatenate some matrix transformation and apply it to
a triangle or a mesh and I want view the final 3d position and
orientation.
This should give me the possibility to make calculations in fast way
without I need sketch on a paper and use calculator.

I see, now the usage of those named matrices makes more sense.

You completely snipped out all the parts relative to the main subject of
this thread, I suppose you've already decided how to handle it.

By the way, please avoid snipping out attribution lines.

Good luck with your program, have fun.
 

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
474,269
Messages
2,571,097
Members
48,773
Latest member
Kaybee

Latest Threads

Top