]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/generic/static.h
portability fixes
[xonotic/netradiant.git] / libs / generic / static.h
index 50fb3b711523ed2040ed849fb006124a9183dc4e..81691827736aca9e9122cf757b86e65969b6a28f 100644 (file)
@@ -27,14 +27,19 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include <cstddef>
 
+class Null
+{
+};
+
 /// \brief A singleton which is statically initialised.
 ///
 /// \param Type The singleton object type.
+/// \param Type The type distinguishing this instance from others of the same type.
 ///
 /// \dontinclude generic/static.cpp
 /// \skipline Static example
 /// \until end example
-template<typename Type>
+template<typename Type, typename Context = Null>
 class Static
 {
   static Type m_instance;
@@ -45,19 +50,20 @@ public:
   }
 };
 
-template<typename Type>
-Type Static<Type>::m_instance;
+template<typename Type, typename Context>
+Type Static<Type, Context>::m_instance;
 
 
 /// \brief A singleton which is lazily initialised.
 /// The instance is constructed the first time it is referenced, and is never destroyed.
 ///
 /// \param Type The singleton object type.
+/// \param Type The type distinguishing this instance from others of the same type.
 ///
 /// \dontinclude generic/static.cpp
 /// \skipline LazyStatic example
 /// \until end example
-template<typename Type>
+template<typename Type, typename Context = Null>
 class LazyStatic
 {
   static Type* m_instance; // this will be initialised to 0 by the CRT, according to the c++ standard
@@ -72,8 +78,8 @@ public:
   }
 };
 
-template<typename Type>
-Type* LazyStatic<Type>::m_instance;
+template<typename Type, typename Context>
+Type* LazyStatic<Type, Context>::m_instance;
 
 
 /// \brief A singleton which keeps a count of the number of times it is referenced.
@@ -82,7 +88,8 @@ Type* LazyStatic<Type>::m_instance;
 /// Use with SmartStatic.
 ///
 /// \param Type The singleton object type.
-template<typename Type>
+/// \param Type The type distinguishing this instance from others of the same type.
+template<typename Type, typename Context = Null>
 class CountedStatic
 {
   static std::size_t m_refcount; // this will be initialised to 0 by the CRT, according to the c++ standard
@@ -108,34 +115,35 @@ public:
   }
 };
 
-template<typename Type>
-std::size_t CountedStatic<Type>::m_refcount; // this will be initialised to 0 by the CRT, according to the c++ standard
-template<typename Type>
-Type* CountedStatic<Type>::m_instance;
+template<typename Type, typename Context>
+std::size_t CountedStatic<Type, Context>::m_refcount; // this will be initialised to 0 by the CRT, according to the c++ standard
+template<typename Type, typename Context>
+Type* CountedStatic<Type, Context>::m_instance;
 
 /// \brief A reference to a CountedStatic.
 /// Guarantees that CountedStatic<Type> will be constructed for the lifetime of this object.
 ///
 /// \param Type The type parameter of the CountedStatic to reference.
+/// \param Type The type distinguishing this instance from others of the same type.
 ///
 /// \dontinclude generic/static.cpp
 /// \skipline SmartStatic example
 /// \until end example
-template<typename Type>
+template<typename Type, typename Context = Null>
 class SmartStatic
 {
 public:
   SmartStatic()
   {
-    CountedStatic<Type>::capture();
+    CountedStatic<Type, Context>::capture();
   }
   ~SmartStatic()
   {
-    CountedStatic<Type>::release();
+    CountedStatic<Type, Context>::release();
   }
   Type& instance()
   {
-    return CountedStatic<Type>::instance();
+    return CountedStatic<Type, Context>::instance();
   }
 };