Hi everyone,
I have implemented a templated buffer class like this:
template <class T, class Impl>
class base_hardware_buffer : Impl
{
public:
typedef const T& const_reference;
typedef T* pointer;
void push_back(reference r)
{
// Do some generic operation, call impl when needed
// ...
}
pointer map()
{
static_cast<Impl*> (this)->map();
}
// ... etc
};
Then I defined two implementations, one for OpenGL and one for DirectX each instantiated in their own dynamic library. For OpenGL:
template <class T>
class glBuffer : base_hardware_buffer<T, glBuffer<T> >
{
public:
typedef T* pointer;
pointer map()
{
// Actual implementation of map
}
// Other implementation specific operation and members go here
};
This is all very nice, and works quite well. Now my problem is that my team mate who is working on the layer above my subsystems wants to implement an algorithm that requires access to the buffers.
How can I give him a uniform access to the buffer without exposing / hard-coding the specific implementations into his code, nor compromising type safety ?