Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Macros for defining branching singletons.
  4. //
  5. // A branching singleton defines a singleton class within another class, and subclasses
  6. // of the outer class can automatically expand on that singleton at their node in the
  7. // class branching tree with the confidence that changes will be reflected in all
  8. // subclasses.
  9. //
  10. // The primary reason to have a branching singleton is to centralize management code
  11. // without being tied explicitly to one interface. The interface can possibly change
  12. // vastly as it gets passed down the tree to the point where all the original functions
  13. // are stubs and the interface uses an entirely different set of functions.
  14. //
  15. // $NoKeywords: $
  16. //=============================================================================//
  17. #ifndef BRANCHINGSINGLETON_H
  18. #define BRANCHINGSINGLETON_H
  19. #ifdef _WIN32
  20. #pragma once
  21. #endif
  22. #define START_BRANCHING_SINGLETON_DEFINITION_NOBASE( classname ) class classname
  23. #define START_BRANCHING_SINGLETON_DEFINITION( classname ) class classname : public Base##classname
  24. #define _END_BRANCHING_SINGLETON_DEFINITION( classname );\
  25. static classname *Get_##classname##_Static( void )\
  26. {\
  27. static classname s_Singleton;\
  28. return &s_Singleton;\
  29. }\
  30. \
  31. virtual Root##classname *Get_##classname##( void )\
  32. {\
  33. return Get_##classname##_Static();\
  34. }\
  35. typedef classname Base##classname;
  36. #define END_BRANCHING_SINGLETON_DEFINITION( classname ) _END_BRANCHING_SINGLETON_DEFINITION( classname )
  37. #define END_BRANCHING_SINGLETON_DEFINITION_NOBASE( classname );\
  38. typedef classname Root##classname;\
  39. _END_BRANCHING_SINGLETON_DEFINITION( classname );
  40. #endif //#ifndef BRANCHINGSINGLETON_H