1 // Copyright (c) 2011 Tel-Aviv University (Israel), INRIA Sophia-Antipolis (France). 2 // All rights reserved. 3 // 4 // This file is part of CGAL (www.cgal.org). 5 // 6 // $URL: https://github.com/CGAL/cgal/blob/v5.3/Arrangement_on_surface_2/include/CGAL/Arr_rat_arc/Singleton.h $ 7 // $Id: Singleton.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot 8 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial 9 // 10 // Author(s) : Oren Salzman <orenzalz@post.tau.ac.il > 11 // Michael Hemmer <Michael.Hemmer@sophia.inria.fr> 12 13 14 15 #ifndef CGAL_SINGLETON_H_ 16 #define SINGLETON_H_ 17 18 #include <CGAL/license/Arrangement_on_surface_2.h> 19 20 21 #include <CGAL/assertions.h> 22 23 namespace CGAL { 24 namespace Arr_rational_arc { 25 template <class T> 26 class Singleton 27 { 28 public: instance()29 static T* instance() 30 { 31 if(!m_pInstance) 32 m_pInstance = new T; 33 CGAL_assertion(m_pInstance !=nullptr); 34 return m_pInstance; 35 } 36 DestroyInstance()37 static void DestroyInstance() 38 { 39 delete m_pInstance; 40 m_pInstance = nullptr; 41 }; 42 private: 43 Singleton(); // ctor hidden 44 ~Singleton(); // dtor hidden 45 private: 46 static T* m_pInstance; 47 }; 48 49 template <class T> T* Singleton<T>::m_pInstance=nullptr; 50 51 } // namespace Arr_rational_arc 52 } //namespace CGAL { 53 #endif // CGAL_SINGLETON_H_ 54