I'm trying to create a library which exposes one class to the outside with a pimpl idiom. This implementation works, meaning I can add functionality to the "idcomimpl" class without breaking ABI. But how do I add the data structure in this whole design that is provided by the application and required by this library. What I want to know is, is it even possible to implement it such that the data structure is exposed to the outside (application) but I can still add member variables to the structure without breaking the ABI. Currently the only header that has to be included by the application is idcom.h. Should I use the same pimpl approach for the data structs as I did for the idcom class?
idcom_global.h :
#if defined( IDCOM_LIBRARY )
#define IDCOMDLL_API __declspec( dllexport )
#else
#define IDCOMDLL_API __declspec( dllimport )
#endif
idcom.h :
class idcomImpl;
class idcom
{
public:
IDCOMDLL_API idcom();
IDCOMDLL_API ~idcom(){};
virtual void doSomething();
private:
std::unique_ptr< idcomImpl > m_impl;
};
idcom.cpp :
idcom::idcom() :
m_impl( new idcomImpl())
{}
void idcom::doSomething()
{
m_impl->doSomething();
}
idcomimpl.h :
class idcomImpl
{
public:
idcomImpl(){};
~idcomImpl(){};
virtual void doSomething();
};
idcomimpl.cpp :
void doSomething()
{
....//implementation here
}
idcom_connection.h ======> the data structure how to incorporate in design ???
struct IDCOMDLL_API idcomConnection
{
std::string id;
std::string name;
std::string type;
//expansion of members here in the future e.g. std::string fullServerName;
};