btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / kernel / util / Constructor.h
blob4c46cbe3b3163e1587c89d2c956a2dd5beb9a3d6
1 #ifndef _CONSTRUCTOR_H_
2 #define _CONSTRUCTOR_H_
4 #include <util/kernel_cpp.h>
6 template <class DataType>
7 class Constructor {
8 public:
9 typedef DataType* Pointer;
10 typedef const DataType* ConstPointer;
11 typedef DataType& Reference;
12 typedef const DataType& ConstReference;
14 /*! Constructs the object pointed to by \a object via a
15 zero-parameter constructor.
17 inline
18 void Construct(Pointer object) {
19 if (object)
20 new(reinterpret_cast<void*>(object)) DataType();
23 /*! Constructs the object pointed to by \a object via a
24 one-parameter constructor using the given argument.
26 template <typename ArgType1>
27 inline
28 void Construct(Pointer object, ArgType1 arg1) {
29 if (object)
30 new(reinterpret_cast<void*>(object)) DataType(arg1);
33 /*! Constructs the object pointed to by \a object via a
34 two-parameter constructor using the given arguments.
36 template <typename ArgType1, typename ArgType2>
37 inline
38 void Construct(Pointer object, ArgType1 arg1, ArgType2 arg2) {
39 if (object)
40 new(reinterpret_cast<void*>(object)) DataType(arg1, arg2);
43 /*! Constructs the object pointed to by \a object via a
44 three-parameter constructor using the given arguments.
46 template <typename ArgType1, typename ArgType2, typename ArgType3>
47 inline
48 void Construct(Pointer object, ArgType1 arg1, ArgType2 arg2, ArgType3 arg3) {
49 if (object)
50 new(reinterpret_cast<void*>(object)) DataType(arg1, arg2, arg3);
53 /*! Constructs the object pointed to by \a object via a
54 four-parameter constructor using the given arguments.
56 template <typename ArgType1, typename ArgType2, typename ArgType3,
57 typename ArgType4>
58 inline
59 void Construct(Pointer object, ArgType1 arg1, ArgType2 arg2, ArgType3 arg3,
60 ArgType4 arg4) {
61 if (object)
62 new(reinterpret_cast<void*>(object)) DataType(arg1, arg2, arg3, arg4);
65 /*! Calls the destructor for the object pointed to be \a object.
67 inline
68 void Destruct(Pointer object) {
69 if (object)
70 object->~DataType();
76 #endif // _CONSTRUCTOR_H_