PCL_interface_lazyobj.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (C) =USTC= Fu Li
  3. *
  4. * Author : Fu Li
  5. * Create : 2005-4-3
  6. * Home : http://www.crazy-bit.com/
  7. * Mail : crazybit@263.net
  8. * History :
  9. */
  10. #ifndef __PCL_LAZY_OBJECT__2005_04_03__H__
  11. #define __PCL_LAZY_OBJECT__2005_04_03__H__
  12. template<class T> class PCL_Interface_Lazy_Object ;
  13. //=============================================================================
  14. /**
  15. * Lazy object, initialize object until get .
  16. */
  17. template<class T>
  18. class PCL_Interface_Lazy_Object
  19. {
  20. public:
  21. PCL_Interface_Lazy_Object() : m_pObj(0) {}
  22. virtual ~PCL_Interface_Lazy_Object() {if(m_pObj) delete m_pObj;}
  23. /// Get lazy object (object will be created at first call).
  24. T* PCL_GetLazyObject()
  25. {
  26. if (!m_pObj)
  27. {
  28. m_pObj = new T ;
  29. PCL_Initialize_Lazy_Object (m_pObj) ;
  30. }
  31. return m_pObj ;
  32. }
  33. protected:
  34. /// Initialize lazy object.
  35. virtual void PCL_Initialize_Lazy_Object (T* pObj) {}
  36. private:
  37. T * m_pObj ;
  38. };
  39. //=============================================================================
  40. // inline implement
  41. //=============================================================================
  42. #endif