1 /* ///////////////////////////////////////////////////////////////////////
2 * File: initialiser_base.h
7 * Brief: initialiser_base class
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
13 #ifndef EXTL_MEMORY_INITIALISER_BASE_H
14 #define EXTL_MEMORY_INITIALISER_BASE_H
16 /*!\file initialiser_base.h
17 * \brief initialiser_base class
20 # error initialiser_base.h need be supported by c++.
23 /* ///////////////////////////////////////////////////////////////////////
28 /* ///////////////////////////////////////////////////////////////////////
33 /*!\brief initialiser_base class
35 * \param D The derived type
36 * \param T The value type
38 * \ingroup extl_group_memory
40 template< typename_param_k D
43 class initialiser_base
48 typedef D derived_type
;
49 typedef initialiser_base class_type
;
52 typedef T
const* const_pointer
;
54 typedef T
const& const_reference
;
55 typedef e_size_t size_type
;
58 /// \name Construct and Destruct
61 void construct(pointer p
)
63 EXTL_ASSERT(NULL
!= p
);
64 derive().do_construct(p
);
66 void construct(pointer p
, const_reference value
)
68 EXTL_ASSERT(NULL
!= p
);
69 derive().do_construct(p
, value
);
71 void construct_n(pointer p
, size_type n
)
73 EXTL_ASSERT(NULL
!= p
);
74 for (pointer pv
= p
; pv
!= p
+ n
; ++pv
)
75 derive().construct(pv
);
77 void construct_n(pointer p
, size_type n
, const_reference value
)
79 EXTL_ASSERT(NULL
!= p
);
80 for (pointer pv
= p
; pv
!= p
+ n
; ++pv
)
81 derive().construct(pv
, value
);
83 void destruct(pointer p
)
85 EXTL_ASSERT(NULL
!= p
);
86 derive().do_destruct(p
);
88 void destruct_n(pointer p
, size_type n
)
90 /* note: reversely destruct
101 * construct: object1 => object2
102 * destruct: object2 => object1
104 for (T
* pv
= p
+ n
- 1; pv
!= p
- 1; --pv
)
105 derive().destruct(pv
);
110 derived_type
const& derive() const { return static_cast<derived_type
const&>(*this); }
111 derived_type
& derive() { return static_cast<derived_type
&>(*this); }
114 /* ///////////////////////////////////////////////////////////////////////
119 /* //////////////////////////////////////////////////////////////////// */
120 #endif /* EXTL_MEMORY_INITIALISER_BASE_H */
121 /* //////////////////////////////////////////////////////////////////// */