I am using PIMPL to hide implementation details of my library from the end user. Also want to capture all 3rd party dependencies of the library within itself; so that I would not need the end user to link them to use my library.
The Interface
//// core.h (the interface)
namespace N
{
enum class priority { ... };
enum class type { ... }
class event_base {
... // getting queued time, priority, name, type etc;
private:
priority m_priority;
type m_type;
};
typedef std::shared_ptr<event_base> p_evt;
class server_backend
{
public:
server_backend(const uint32_t &port = 10100);
~server_backend();
bool try_push(p_evt p);
size_t get_size_evt_bus();
void dump_evt_bus();
private:
struct impl;
std::unique_ptr<impl> p_impl;
}
}
Implementation details
//// core.cpp
#include "backend.h"
using namespace N;
class server_backend::impl
{
impl(const uint32_t& port)
:_bimpl(std::make_unique<backendimpl>(port))
{}
bool try_push(p_evt p)
{
return true;
}
size_t get_size_evt_bus()
{
return 0;
}
void dump_evt_bus()
{ }
private:
std::unique_ptr<backendimpl> _bimpl;
}
server_backend::server_backend()
:p_impl(std::make_unique<impl>(port))
{}
server_backend::~server_backend() = default;
/// call impl functions from server_backend public functions
My implementation creates an instance of a class deeper in the library. This class does contain datatypes from 3rd party libs.
//backend.h
class backendimpl final
{
backend(const uint32_t &port);
~backendimpl();
bool try_push(p_evt p);
size_t get_size_evt_bus();
void dump_evt_bus();
// other public functions
private:
// private members (some from 3rd party libs)
// private functions
}
I am trying to hide these third party libs from the end user. But I find that when I create a client app (basically just a CTest stub), I do need to include the 3rd party libs along with my library. Logically, I guess the problem comes up when I include the deeper class header into my interface implementation; but I do not see a way around it.
Can anyone help?