]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/generic/object.h
ok
[xonotic/netradiant.git] / libs / generic / object.h
1 /*
2 Copyright (C) 2001-2006, William Joseph.
3 All Rights Reserved.
4
5 This file is part of GtkRadiant.
6
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.
11
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.
16
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
20 */
21
22 #if !defined(INCLUDED_GENERIC_OBJECT_H)
23 #define INCLUDED_GENERIC_OBJECT_H
24
25 /// \file
26 /// \brief Convenience functions (syntactic sugar) to wrap explicit constructor (aka in-place 'new') and destructor calls. 
27 ///
28 /// Use makeReference() to wrap non-const-reference constructor parameters.
29
30 #if _MSC_VER > 1000 && defined(WIN32)
31 #pragma warning(disable:4345) // behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized
32 #endif
33
34 #include <new>
35
36 template<typename Type>
37 inline void constructor(Type& object)
38 {
39   new(&object) Type();
40 }
41
42 template<typename Type, typename T1>
43 inline void constructor(Type& object, const T1& t1)
44 {
45   new(&object) Type(t1);
46 }
47
48 template<typename Type, typename T1, typename T2>
49 inline void constructor(Type& object, const T1& t1, const T2& t2)
50 {
51   new(&object) Type(t1, t2); 
52 }
53
54 template<typename Type, typename T1, typename T2, typename T3>
55 inline void constructor(Type& object, const T1& t1, const T2& t2, const T3& t3)
56 {
57   new(&object) Type(t1, t2, t3); 
58 }
59
60 template<typename Type, typename T1, typename T2, typename T3, typename T4>
61 inline void constructor(Type& object, const T1& t1, const T2& t2, const T3& t3, const T4& t4)
62 {
63   new(&object) Type(t1, t2, t3, t4); 
64 }
65
66 template<typename Type, typename T1, typename T2, typename T3, typename T4, typename T5>
67 inline void constructor(Type& object, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5)
68 {
69   new(&object) Type(t1, t2, t3, t4, t5); 
70 }
71
72 template<typename Type, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
73 inline void constructor(Type& object, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6)
74 {
75   new(&object) Type(t1, t2, t3, t4, t5, t6); 
76 }
77
78 template<typename Type, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
79 inline void constructor(Type& object, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7)
80 {
81   new(&object) Type(t1, t2, t3, t4, t5, t6, t7); 
82 }
83
84 template<typename Type, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
85 inline void constructor(Type& object, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8)
86 {
87   new(&object) Type(t1, t2, t3, t4, t5, t6, t7, t8); 
88 }
89
90 template<typename Type>
91 inline void destructor(Type& object)
92 {
93   object.~Type();
94 }
95
96
97
98 #endif