vendredi 24 février 2017

std::shared_ptr

Good afternoon,

So I made a library that needs to be used as an APi for different applications under linux and windows both as a command line tool and a gui.

Inside of that library I have an std::map of structures, and it represent physical objects that the program is made to control.

I want to be able to pass it some special class only from the windows GUI app, but not from any other apps. And this special class is a direct3D class called 3DModel

So I believe I cannot reference this class anywhere in the library without using a bunch of #define _WIN64 and so on. Maybe if I use forward declarations?

The library is also not doing anything at all with the object, the object is created in the Windows GUI app and passed to the library entirely for organization purposes (to prevent creating a duplicated std::map structure just to store these objects. And then it's called on by the windows GUI app to render and so on.

The other apps are not creating this object, as they would just pass a nullptr to it instead and never use it.

So my question is, Inside the library, can I have function parameters, std::map structure, etc use std::shared_ptr.

Then in the Windows GUI, I would create an std::shared_ptr, cast it to std::shared_ptr retrieve it when necessary, cast it to std::shared_ptr again, then render with it?

Is this ethical? Are there better alternatives? I heard recommendations of boost::any, but haven't used it yet. I don't have boost anywhere in the code yet, are there any standard alternatives?

Or is this a situation where I would forward declare the 3DModel class in the library, but never #include "3DModel.h" ?

Thanks, -D

Aucun commentaire:

Enregistrer un commentaire