pimplapi.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Copyright 2015 Autodesk, Inc. All rights reserved.
  5. //
  6. // Use of this software is subject to the terms of the Autodesk license
  7. // agreement provided at the time of installation or download, or which
  8. // otherwise accompanies this software in either electronic or hard copy form.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. namespace Pimpl
  13. {
  14. class ImpBase;
  15. //Simple helper template to implement to help implement the Pimpl Idiom.
  16. template <typename Base, class ImpPart>
  17. class ApiPart : public Base
  18. {
  19. protected:
  20. ApiPart(ImpPart* pImp) throw()
  21. :m_pImp(pImp)
  22. {
  23. }
  24. //Must be defined by user code to delete m_pImp.
  25. //The template cannot do this since ImpPart is not known here.
  26. ~ApiPart();
  27. private:
  28. friend class ImpBase;
  29. ImpPart* m_pImp;
  30. };
  31. //partial specialization for no base class
  32. template <class ImpPart>
  33. class ApiPart<void, ImpPart>
  34. {
  35. protected:
  36. ApiPart(ImpPart* pImp) throw()
  37. :m_pImp(pImp)
  38. {
  39. }
  40. ~ApiPart(); //must be defined by user code
  41. private:
  42. friend class ImpBase;
  43. ImpPart* m_pImp;
  44. };
  45. }