remove \r
[extl.git] / extl / memory / initialiser_base.h
blob2750d5415b662b54bb662ed8be1dd70786876228
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: initialiser_base.h
4 * Created: 08.07.30
5 * Updated: 08.07.30
7 * Brief: initialiser_base class
9 * [<Home>]
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
19 #ifndef __cplusplus
20 # error initialiser_base.h need be supported by c++.
21 #endif
23 /* ///////////////////////////////////////////////////////////////////////
24 * Includes
26 #include "prefix.h"
28 /* ///////////////////////////////////////////////////////////////////////
29 * ::extl namespace
31 EXTL_BEGIN_NAMESPACE
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
41 , typename_param_k T
43 class initialiser_base
45 /// \name Types
46 /// @{
47 public:
48 typedef D derived_type;
49 typedef initialiser_base class_type;
50 typedef T value_type;
51 typedef T* pointer;
52 typedef T const* const_pointer;
53 typedef T& reference;
54 typedef T const& const_reference;
55 typedef e_size_t size_type;
56 /// @}
58 /// \name Construct and Destruct
59 /// @{
60 public:
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
92 struct object1
94 object1()
96 new object2;
99 new object1;
101 * construct: object1 => object2
102 * destruct: object2 => object1
104 for (T* pv = p + n - 1; pv != p - 1; --pv)
105 derive().destruct(pv);
107 /// @}
109 private:
110 derived_type const& derive() const { return static_cast<derived_type const&>(*this); }
111 derived_type& derive() { return static_cast<derived_type&>(*this); }
114 /* ///////////////////////////////////////////////////////////////////////
115 * ::extl namespace
117 EXTL_END_NAMESPACE
119 /* //////////////////////////////////////////////////////////////////// */
120 #endif /* EXTL_MEMORY_INITIALISER_BASE_H */
121 /* //////////////////////////////////////////////////////////////////// */