ccSingleton.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435
  1. //##########################################################################
  2. //# #
  3. //# CLOUDCOMPARE #
  4. //# #
  5. //# This program is free software; you can redistribute it and/or modify #
  6. //# it under the terms of the GNU General Public License as published by #
  7. //# the Free Software Foundation; version 2 or later of the License. #
  8. //# #
  9. //# This program is distributed in the hope that it will be useful, #
  10. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  11. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  12. //# GNU General Public License for more details. #
  13. //# #
  14. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  15. //# #
  16. //##########################################################################
  17. #ifndef CC_SINGLETON_HEADER
  18. #define CC_SINGLETON_HEADER
  19. //! Generic singleton encapsulation structure
  20. template<class T> struct ccSingleton
  21. {
  22. //! Default constructor
  23. ccSingleton() : instance(nullptr) {}
  24. //! Destructor
  25. ~ccSingleton() { release(); }
  26. //! Releases the current instance
  27. inline void release() { if (instance) { delete instance; instance = nullptr; } }
  28. //! Current instance
  29. T* instance;
  30. };
  31. #endif //CC_SINGLETON_HEADER