Line data Source code
1 : // Author(s): Jeroen van der Wulp 2 : // Copyright: see the accompanying file COPYING or copy at 3 : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING 4 : // 5 : // Distributed under the Boost Software License, Version 1.0. 6 : // (See accompanying file LICENSE_1_0.txt or copy at 7 : // http://www.boost.org/LICENSE_1_0.txt) 8 : // 9 : /// \file mcrl2/core/construction_utility.h 10 : /// \brief construction utility 11 : 12 : #ifndef MCRL2_CORE_DETAIL_CONSTRUCTION_UTILITY_H 13 : #define MCRL2_CORE_DETAIL_CONSTRUCTION_UTILITY_H 14 : 15 : #include "mcrl2/core/identifier_string.h" 16 : 17 : namespace mcrl2 18 : { 19 : namespace core 20 : { 21 : namespace detail 22 : { 23 : 24 : // Component that helps applying the Singleton design pattern 25 : template < typename Derived, typename Expression = atermpp::aterm_appl > 26 : class singleton_expression 27 : { 28 : public: 29 3546216 : static const Expression& instance() 30 : { 31 3546216 : static Expression single_instance = Expression(Derived::initialise()); 32 3546216 : return single_instance; 33 : } 34 : 35 : singleton_expression(const singleton_expression&) = delete; 36 : singleton_expression& operator=(const singleton_expression &) = delete; 37 : singleton_expression(singleton_expression &&) = delete; 38 : singleton_expression & operator=(singleton_expression &&) = delete; 39 : 40 : protected: 41 : singleton_expression() {} 42 : }; 43 : 44 : template < typename Derived > 45 : struct singleton_identifier : public singleton_expression< Derived, core::identifier_string > 46 : {}; 47 : 48 : } // namespace detail 49 : } // namespace core 50 : } // namespace mcrl2 51 : 52 : 53 : #endif 54 :