Storing position of member variable

Started by
12 comments, last by Juliean 9 years, 9 months ago
Actually, if you're using any of the latest Visual Studio versions, there should be a local database file with your project that contains metadata about your project. Usually, this database is used for intellisense, but you can connect to the database externally and perform SQL queries against it. With this, you can query information about your project, classes, and its members. Extending this, you could write a PowerShell script to automatically generate reflection information from all of your classes. Then you could add this to your build process, and... well, I'm getting ahead of myself, here. smile.png
Advertisement

Check out my binding system if you like, here: https://code.google.com/p/eight/source/browse/include/eight/core/bind.h
It does a bit more than you need, but does calculate the sizes/offsets of the member variables.


const ComponentDeclaration::AttributeVector vAttributes =
{
{ AttributeType::FLOAT, "x" },
{ AttributeType::FLOAT, "y" },
{ AttributeType::FLOAT, "z" },
}


I came on here to mention offsetof, though I see that you've found that. Instead of trying to get fancier, I would start out by implementing your original idea. Maybe it'll be a little annoying to type class names over and over, but it'll get something working that you can refactor:


const ComponentDeclaration::AttributeVector vAttributes =
{
{ AttributeType::FLOAT, "x", offsetof(Component, vPosition) + offsetof(Vector2f, x) },
{ AttributeType::FLOAT, "y", offsetof(Component, vPosition) + offsetof(Vector2f, y) },
{ AttributeType::FLOAT, "z", offsetof(Component, vPosition) + offsetof(Vector2f, z) },
}


I came on here to mention offsetof, though I see that you've found that. Instead of trying to get fancier, I would start out by implementing your original idea. Maybe it'll be a little annoying to type class names over and over, but it'll get something working that you can refactor:

Thats what I'm doing at the moment. Refactoring is quite a pain since the amount of components for my 2D + 3D stuff is quite high, though I think I'll even merge some components here and there... anyway, it works out quite well that way for now, and got me rid of ~1500 LOC, mostly in gui/editor-related stuff, which is about 10% of my 2D-plugins. I'm glad I have a 2D project to test first & refactor based on that though, because there is just way more stuff going on in the 3D departement, so it would take way longer to get things even to work, not talking about refactoring...

I also wanted to mention, for anyone who might stumble up to this, that you don't have to perform offsetof twice for nested classes, you can just say


{ AttributeType::FLOAT, "x", offsetof(Component, vPosition.x) },

which is actually quite nice.

@SeanMiddleditch:

Thats actually interesting, I'm not sure if its not even a bit complicated for what I'm trying to do, since I'll never have such things as multiple interheritance etc... Everything that I expose via those "interfaces" is going to be POD, too, at least for the moment. I'll keep it in mind though, I might even want to use this to improve the type system of my visual scripting system, while I'm at it, I think it would fit there quite well.


Actually, if you're using any of the latest Visual Studio versions, there should be a local database file with your project that contains metadata about your project. Usually, this database is used for intellisense, but you can connect to the database externally and perform SQL queries against it. With this, you can query information about your project, classes, and its members. Extending this, you could write a PowerShell script to automatically generate reflection information from all of your classes. Then you could add this to your build process, and... well, I'm getting ahead of myself, here. smile.png

Uh, I really wouldn't want to rely too heavily on Visual Studio for stuff like that. The plugins should work independately, which could be achieved by generating this reflection information to a personal file format... but I quess thats a bit overkill, though its neat to see whats possible :D I also kind of like the idea that it would work fully automatically, without having to write a single line of code for each component.


Check out my binding system if you like, here: https://code.google.com/p/eight/source/browse/include/eight/core/bind.h
It does a bit more than you need, but does calculate the sizes/offsets of the member variables.

I had a look, seems you are also using offsetof, which makes me a little more secure that this is at least a viable choice.

Thanks again for all the input, much appreciated.

This topic is closed to new replies.

Advertisement