From: ThorstenB Date: Sun, 18 Dec 2011 13:06:27 +0000 (+0100) Subject: #512: fix compatibility issue with boost 1.48.0 X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b261836f7182b5442b464907c8b084bde0bfded3;p=simgear.git #512: fix compatibility issue with boost 1.48.0 Thanks to handigehansje. --- diff --git a/simgear/structure/CMakeLists.txt b/simgear/structure/CMakeLists.txt index e5ff687a..ebe6be5d 100644 --- a/simgear/structure/CMakeLists.txt +++ b/simgear/structure/CMakeLists.txt @@ -1,7 +1,7 @@ include (SimGearComponent) -set(HEADERS +set(HEADERS OSGUtils.hxx OSGVersion.hxx SGAtomic.hxx @@ -14,6 +14,7 @@ set(HEADERS SGWeakPtr.hxx SGWeakReferenced.hxx SGPerfMon.hxx + singleton.hpp Singleton.hxx StringTable.hxx callback.hxx @@ -23,8 +24,8 @@ set(HEADERS intern.hxx subsystem_mgr.hxx ) - -set(SOURCES + +set(SOURCES SGAtomic.cxx SGBinding.cxx SGExpression.cxx @@ -38,4 +39,4 @@ set(SOURCES subsystem_mgr.cxx ) -simgear_component(structure structure "${SOURCES}" "${HEADERS}") \ No newline at end of file +simgear_component(structure structure "${SOURCES}" "${HEADERS}") diff --git a/simgear/structure/Singleton.hxx b/simgear/structure/Singleton.hxx index cc98c497..35c712a2 100644 --- a/simgear/structure/Singleton.hxx +++ b/simgear/structure/Singleton.hxx @@ -1,12 +1,12 @@ #ifndef SIMGEAR_SINGLETON_HXX #define SIMGEAR_SINGLETON_HXX 1 -#include +#include "singleton.hpp" #ifndef NO_OPENSCENEGRAPH_INTERFACE #include #include -#endif +#endif namespace simgear { diff --git a/simgear/structure/singleton.hpp b/simgear/structure/singleton.hpp new file mode 100644 index 00000000..9f6109d6 --- /dev/null +++ b/simgear/structure/singleton.hpp @@ -0,0 +1,128 @@ +// Copyright (C) 2000 Stephen Cleary +// +// Distributed under the Boost Software License, Version 1.0. +// Boost Software License - Version 1.0 - August 17th, 2003 + +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: + +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// +// See http://www.boost.org for updates, documentation, and revision history. + +#ifndef BOOST_POOL_SINGLETON_HPP +#define BOOST_POOL_SINGLETON_HPP + +// The following code might be put into some Boost.Config header in a later revision +#ifdef __BORLANDC__ +# pragma option push -w-inl +#endif + +// +// The following helper classes are placeholders for a generic "singleton" +// class. The classes below support usage of singletons, including use in +// program startup/shutdown code, AS LONG AS there is only one thread +// running before main() begins, and only one thread running after main() +// exits. +// +// This class is also limited in that it can only provide singleton usage for +// classes with default constructors. +// + +// The design of this class is somewhat twisted, but can be followed by the +// calling inheritance. Let us assume that there is some user code that +// calls "singleton_default::instance()". The following (convoluted) +// sequence ensures that the same function will be called before main(): +// instance() contains a call to create_object.do_nothing() +// Thus, object_creator is implicitly instantiated, and create_object +// must exist. +// Since create_object is a static member, its constructor must be +// called before main(). +// The constructor contains a call to instance(), thus ensuring that +// instance() will be called before main(). +// The first time instance() is called (i.e., before main()) is the +// latest point in program execution where the object of type T +// can be created. +// Thus, any call to instance() will auto-magically result in a call to +// instance() before main(), unless already present. +// Furthermore, since the instance() function contains the object, instead +// of the singleton_default class containing a static instance of the +// object, that object is guaranteed to be constructed (at the latest) in +// the first call to instance(). This permits calls to instance() from +// static code, even if that code is called before the file-scope objects +// in this file have been initialized. + +namespace boost { + +namespace details { +namespace pool { + +// T must be: no-throw default constructible and no-throw destructible +template +struct singleton_default +{ + private: + struct object_creator + { + // This constructor does nothing more than ensure that instance() + // is called before main() begins, thus creating the static + // T object before multithreading race issues can come up. + object_creator() { singleton_default::instance(); } + inline void do_nothing() const { } + }; + static object_creator create_object; + + singleton_default(); + + public: + typedef T object_type; + + // If, at any point (in user code), singleton_default::instance() + // is called, then the following function is instantiated. + static object_type & instance() + { + // This is the object that we return a reference to. + // It is guaranteed to be created before main() begins because of + // the next line. + static object_type obj; + + // The following line does nothing else than force the instantiation + // of singleton_default::create_object, whose constructor is + // called before main() begins. + create_object.do_nothing(); + + return obj; + } +}; +template +typename singleton_default::object_creator +singleton_default::create_object; + +} // namespace pool +} // namespace details + +} // namespace boost + +// The following code might be put into some Boost.Config header in a later revision +#ifdef __BORLANDC__ +# pragma option pop +#endif + +#endif