S
Simon Elliott
I want to design a class which will encapsulate some system specific
representation, in this case time structs:
#if unix_implementation
#include <time.h>
class Cfoo
{
private:
timespec someTime_;
public:
// various public methods
};
#endif
#if w32_implementation
#include <windows.h>
class Cfoo
{
private:
SYSTEMTIME someTime_;
public:
// various public methods
};
#endif
I'd like to have a single header with no #if/#ifdef and with no system
specific headers being included (eg windows.h).
The obvious way of doing this is with a pimpl, keeping all the system
specific things in the implementation class. However, in some
implementations, someTime_ will be an unsigned long. I don't want the
overhead of a pimpl (dynamic allocations and forwarding functions) for
the sake of managing 4 bytes of data. Nor do I want to get involved
with fixed-sized allocators.
Is there a better way of doing this? It occurs to me that there ought
to be a way of doing this with templates, since template code is only
compiled as needed.
representation, in this case time structs:
#if unix_implementation
#include <time.h>
class Cfoo
{
private:
timespec someTime_;
public:
// various public methods
};
#endif
#if w32_implementation
#include <windows.h>
class Cfoo
{
private:
SYSTEMTIME someTime_;
public:
// various public methods
};
#endif
I'd like to have a single header with no #if/#ifdef and with no system
specific headers being included (eg windows.h).
The obvious way of doing this is with a pimpl, keeping all the system
specific things in the implementation class. However, in some
implementations, someTime_ will be an unsigned long. I don't want the
overhead of a pimpl (dynamic allocations and forwarding functions) for
the sake of managing 4 bytes of data. Nor do I want to get involved
with fixed-sized allocators.
Is there a better way of doing this? It occurs to me that there ought
to be a way of doing this with templates, since template code is only
compiled as needed.