Debian Codegraph @

libs/generic/object.h

raw symbols SCIP
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 #include "globaldefs.h"
26
27 /// \file
28 /// \brief Convenience functions (syntactic sugar) to wrap explicit constructor (aka in-place 'new') and destructor calls.
29 ///
30 /// Use makeReference() to wrap non-const-reference constructor parameters.
31
32 #if GDEF_COMPILER_MSVC && _MSC_VER > 1000
33 #pragma warning(disable:4345) // behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized
34 #endif
35
36 #include <new>
37
38 template<typename Type>
39 inline void constructor( Type& object ){
40 new( &object )Type();
41 }
42
43 template<typename Type, typename T1>
44 inline void constructor( Type& object, const T1& t1 ){
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 new( &object )Type( t1, t2 );
51 }
52
53 template<typename Type, typename T1, typename T2, typename T3>
54 inline void constructor( Type& object, const T1& t1, const T2& t2, const T3& t3 ){
55 new( &object )Type( t1, t2, t3 );
56 }
57
58 template<typename Type, typename T1, typename T2, typename T3, typename T4>
59 inline void constructor( Type& object, const T1& t1, const T2& t2, const T3& t3, const T4& t4 ){
60 new( &object )Type( t1, t2, t3, t4 );
61 }
62
63 template<typename Type, typename T1, typename T2, typename T3, typename T4, typename T5>
64 inline void constructor( Type& object, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5 ){
65 new( &object )Type( t1, t2, t3, t4, t5 );
66 }
67
68 template<typename Type, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
69 inline void constructor( Type& object, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6 ){
70 new( &object )Type( t1, t2, t3, t4, t5, t6 );
71 }
72
73 template<typename Type, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
74 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 ){
75 new( &object )Type( t1, t2, t3, t4, t5, t6, t7 );
76 }
77
78 template<typename Type, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
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, const T8& t8 ){
80 new( &object )Type( t1, t2, t3, t4, t5, t6, t7, t8 );
81 }
82
83 template<typename Type>
84 inline void destructor( Type& object ){
85 object.~Type();
86 }
87
88
89
90 #endif