Trouble is that I am making an API. Not sure if it will ever be released but at this point i'm trying to treat every thing as if it will.
If the API is eventually going to be released, you could just use handles to prevent addon-breaking API changes.
You could still use the framework already set up to use pointers, just cast them to void * before returning them to other addons, like so:
Code:
[COLOR="Red"]typedef void* FOO_HANDLE;[/COLOR]
FOO_HANDLE MyClass::CreateFoo (double x, double y, double z)
{
FOO foo;
foo.x_value = x;
foo.y_value = y;
foo.z_value = z;
foo_list.push_back (foo);
return ((FOO_HANDLE) &foo_list.back ());
}
However, this could cause issues with:
I suppose my biggest question is how do I get other functions to accept FOO_HANDLE as an argument in place of FOO.
For instance...
Code:
void MyClass::SetFooXvalue (FOO_HANDLE fh, double x)
{
//*Something mysterious happens*
Foo.x_value = x;
}
In a handle-based API, the "users" of the handles (the classes that can access the API, but not the classes that are accessed by the handles), can never directly access the classes used. If you use handles, you have to define your own API functions that take the handle, convert it to the correct class and operate on the object.
For example:
Code:
static void API::SetFooXvalue (FOO_HANDLE fh, double x)
{
((foo*)fh)->x_value = x;
}
Then, in a consumer class:
Code:
void MyClass::doCoolStuff(FOO_HANDLE fh)
{
//let's set the x value to pi, for fun
API::SetFooXValue(fh,3.14159);
}
Users of the API never touch the objects, they always use API "helper" functions.
Although this means that you do have to write all the API object mutator functions, it does allow you to fully change the implementation of said functions without breaking any addons that depend on it.