2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "globaldefs.h"
25 #if GDEF_DEBUG || defined( DOXYGEN )
27 namespace ExampleStatic
35 MyClass() : value( 3 ){
39 typedef Static<MyClass> StaticMyClass;
42 class DynamicInitialisation
45 DynamicInitialisation(){
46 // StaticMyClass::instance() may be invalid here because construction order is undefined
50 DynamicInitialisation g_dynamicInitialisation;
53 int bar = StaticMyClass::instance().value;
58 namespace ExampleLazyStatic
66 MyClass() : value( 3 ){
68 // destructor will never be called
71 typedef LazyStatic<MyClass> StaticMyClass;
74 class DynamicInitialisation
77 DynamicInitialisation(){
78 int bar = StaticMyClass::instance().value;
82 DynamicInitialisation g_dynamicInitialisation;
85 int bar = StaticMyClass::instance().value;
90 namespace ExampleSmartStatic
92 // SmartStatic example
98 MyClass() : value( 3 ){
102 typedef CountedStatic<MyClass> StaticMyClass;
105 class DynamicInitialisation
108 DynamicInitialisation(){
109 // StaticMyClass::instance() is invalid before the ref is constructed
110 SmartStatic<MyClass> ref;
111 int bar = ref.instance().value;
113 SmartStatic<MyClass> ref2; // any number of instances are allowed.
117 DynamicInitialisation g_dynamicInitialisation;
120 int bar = SmartStatic<MyClass>().instance().value; // an instance can be a temporary