1 #ifndef _CONSTRUCTOR_H_ 2 #define _CONSTRUCTOR_H_ 3 4 #include <util/kernel_cpp.h> 5 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; 13 14 /*! Constructs the object pointed to by \a object via a 15 zero-parameter constructor. 16 */ 17 inline 18 void Construct(Pointer object) { 19 if (object) 20 new(reinterpret_cast<void*>(object)) DataType(); 21 } 22 23 /*! Constructs the object pointed to by \a object via a 24 one-parameter constructor using the given argument. 25 */ 26 template <typename ArgType1> 27 inline 28 void Construct(Pointer object, ArgType1 arg1) { 29 if (object) 30 new(reinterpret_cast<void*>(object)) DataType(arg1); 31 } 32 33 /*! Constructs the object pointed to by \a object via a 34 two-parameter constructor using the given arguments. 35 */ 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); 41 } 42 43 /*! Constructs the object pointed to by \a object via a 44 three-parameter constructor using the given arguments. 45 */ 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); 51 } 52 53 /*! Constructs the object pointed to by \a object via a 54 four-parameter constructor using the given arguments. 55 */ 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); 63 } 64 65 /*! Calls the destructor for the object pointed to be \a object. 66 */ 67 inline 68 void Destruct(Pointer object) { 69 if (object) 70 object->~DataType(); 71 } 72 73 74 }; 75 76 #endif // _CONSTRUCTOR_H_ 77