I am working on a multiplatform rendering API with implementations for DirectX 9 and DirectX 11.
Requirements:
- efficiency : no virtual calls
- minimal code duplication : declare the public API once only
- compile-time selection of the implementation
Nice to have:
- exposing to client code only the public API and not private methods and member variables of the actual implementation.
I have been exploring different approaches (e.g. http://www.altdevblogaday.com/2011/06/27/platform-abstraction-with-cpp-templates/ , http://www.altdevblogaday.com/2011/02/01/the-virtual-and-no-virtual/) and then stumbled upon this solution which seems to fit my requirements pretty well:
http://www.crickettechnology.com/blog/?p=116
I quite like this solution and I am considering using it for other systems. I strongly suspect FMOD uses it too, as the FMOD API classes contain only public methods. This solution puts some constraints on the class usage (it seals it and allows manipulation through pointers only). Moreover, the actual .cpp implementation file feels a little hacky and less pretty with all the additional downcasts. I kinda wish C++ supported partial class declarations as part of the language, for cases like mine.
What is your opinion about this approach ?
Thanks