Skip to content

Commit 9c16d68

Browse files
author
U-i7\gimy
committed
change indent rule to hard tab with width 4 to adjust to default setting of VC++. and incidentally change coding style to K&R(linux) style. by command "astyle --style=linux -T4"
1 parent b44c0cb commit 9c16d68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+13648
-14272
lines changed

array.h

+193-160
Original file line numberDiff line numberDiff line change
@@ -13,174 +13,207 @@ template <class T, class Allocator = std::allocator<T> >
1313
class Array
1414
{
1515
public:
16-
typedef typename Allocator::reference reference; ///
17-
typedef typename Allocator::const_reference const_reference; ///
18-
typedef typename Allocator::pointer iterator; ///
19-
typedef typename Allocator::const_pointer const_iterator; ///
20-
typedef typename Allocator::size_type size_type; ///
21-
typedef typename Allocator::difference_type difference_type; ///
22-
typedef T value_type; ///
23-
typedef Allocator allocator_type; ///
24-
typedef typename Allocator::pointer pointer; ///
25-
typedef typename Allocator::const_pointer const_pointer; ///
16+
typedef typename Allocator::reference reference; ///
17+
typedef typename Allocator::const_reference const_reference; ///
18+
typedef typename Allocator::pointer iterator; ///
19+
typedef typename Allocator::const_pointer const_iterator; ///
20+
typedef typename Allocator::size_type size_type; ///
21+
typedef typename Allocator::difference_type difference_type; ///
22+
typedef T value_type; ///
23+
typedef Allocator allocator_type; ///
24+
typedef typename Allocator::pointer pointer; ///
25+
typedef typename Allocator::const_pointer const_pointer; ///
2626
#if 0
27-
typedef std::reverse_iterator<iterator> reverse_iterator; ///
28-
typedef std::reverse_iterator<const_iterator> const_reverse_iterator; ///
29-
#endif
27+
typedef std::reverse_iterator<iterator> reverse_iterator; ///
28+
typedef std::reverse_iterator<const_iterator> const_reverse_iterator; ///
29+
#endif
3030
private:
31-
Allocator m_allocator; ///
32-
size_type m_size; ///
33-
pointer m_buf; /// array buffer
31+
Allocator m_allocator; ///
32+
size_type m_size; ///
33+
pointer m_buf; /// array buffer
3434

3535
public:
36-
/// constructor
37-
explicit Array(const Allocator& i_allocator = Allocator())
38-
: m_allocator(i_allocator), m_size(0), m_buf(NULL) { }
39-
40-
/// constructor
41-
explicit Array(size_type i_size, const T& i_value = T(),
42-
const Allocator& i_allocator = Allocator())
43-
: m_allocator(i_allocator), m_size(i_size),
44-
m_buf(m_allocator.allocate(m_size, 0))
45-
{
46-
std::uninitialized_fill_n(m_buf, i_size, i_value);
47-
}
48-
49-
/// constructor
50-
template <class InputIterator>
51-
Array(InputIterator i_begin, InputIterator i_end,
52-
const Allocator& i_allocator = Allocator())
53-
: m_allocator(i_allocator), m_size(distance(i_begin, i_end)),
54-
m_buf(Allocator::allocate(m_size, 0))
55-
{
56-
std::uninitialized_copy(i_begin, i_end, m_buf);
57-
}
58-
59-
/// copy constructor
60-
Array(const Array& i_o) : m_size(0), m_buf(NULL) { operator=(i_o); }
36+
/// constructor
37+
explicit Array(const Allocator& i_allocator = Allocator())
38+
: m_allocator(i_allocator), m_size(0), m_buf(NULL) { }
39+
40+
/// constructor
41+
explicit Array(size_type i_size, const T& i_value = T(),
42+
const Allocator& i_allocator = Allocator())
43+
: m_allocator(i_allocator), m_size(i_size),
44+
m_buf(m_allocator.allocate(m_size, 0)) {
45+
std::uninitialized_fill_n(m_buf, i_size, i_value);
46+
}
47+
48+
/// constructor
49+
template <class InputIterator>
50+
Array(InputIterator i_begin, InputIterator i_end,
51+
const Allocator& i_allocator = Allocator())
52+
: m_allocator(i_allocator), m_size(distance(i_begin, i_end)),
53+
m_buf(Allocator::allocate(m_size, 0)) {
54+
std::uninitialized_copy(i_begin, i_end, m_buf);
55+
}
56+
57+
/// copy constructor
58+
Array(const Array& i_o) : m_size(0), m_buf(NULL) {
59+
operator=(i_o);
60+
}
6161

62-
/// destractor
63-
~Array() { clear(); }
62+
/// destractor
63+
~Array() {
64+
clear();
65+
}
6466

65-
///
66-
Array& operator=(const Array& i_o)
67-
{
68-
if (&i_o != this)
69-
{
70-
clear();
71-
m_size = i_o.m_size;
72-
m_buf = m_allocator.allocate(m_size, 0);
73-
std::uninitialized_copy(i_o.m_buf, i_o.m_buf + m_size, m_buf);
74-
}
75-
return *this;
76-
}
77-
///
78-
allocator_type get_allocator() const { return Allocator(); }
79-
/// return pointer to the array buffer
80-
typename allocator_type::pointer get() { return m_buf; }
81-
/// return pointer to the array buffer
82-
typename allocator_type::const_pointer get() const { return m_buf; }
83-
///
84-
iterator begin() { return m_buf; }
85-
///
86-
const_iterator begin() const { return m_buf; }
87-
///
88-
iterator end() { return m_buf + m_size; }
89-
///
90-
const_iterator end() const { return m_buf + m_size; }
67+
///
68+
Array& operator=(const Array& i_o) {
69+
if (&i_o != this) {
70+
clear();
71+
m_size = i_o.m_size;
72+
m_buf = m_allocator.allocate(m_size, 0);
73+
std::uninitialized_copy(i_o.m_buf, i_o.m_buf + m_size, m_buf);
74+
}
75+
return *this;
76+
}
77+
///
78+
allocator_type get_allocator() const {
79+
return Allocator();
80+
}
81+
/// return pointer to the array buffer
82+
typename allocator_type::pointer get() {
83+
return m_buf;
84+
}
85+
/// return pointer to the array buffer
86+
typename allocator_type::const_pointer get() const {
87+
return m_buf;
88+
}
89+
///
90+
iterator begin() {
91+
return m_buf;
92+
}
93+
///
94+
const_iterator begin() const {
95+
return m_buf;
96+
}
97+
///
98+
iterator end() {
99+
return m_buf + m_size;
100+
}
101+
///
102+
const_iterator end() const {
103+
return m_buf + m_size;
104+
}
91105
#if 0
92-
///
93-
reverse_iterator rbegin() { reverse_iterator(end()); }
94-
///
95-
const_reverse_iterator rbegin() const { const_reverse_iterator(end()); }
96-
///
97-
reverse_iterator rend() { reverse_iterator(begin()); }
98-
///
99-
const_reverse_iterator rend() const { const_reverse_iterator(begin()); }
106+
///
107+
reverse_iterator rbegin() {
108+
reverse_iterator(end());
109+
}
110+
///
111+
const_reverse_iterator rbegin() const {
112+
const_reverse_iterator(end());
113+
}
114+
///
115+
reverse_iterator rend() {
116+
reverse_iterator(begin());
117+
}
118+
///
119+
const_reverse_iterator rend() const {
120+
const_reverse_iterator(begin());
121+
}
100122
#endif
101-
///
102-
size_type size() const { return m_size; }
103-
///
104-
size_type max_size() const { return -1; }
105-
/// resize the array buffer. NOTE: the original contents are cleared.
106-
void resize(size_type i_size, const T& i_value = T())
107-
{
108-
clear();
109-
m_size = i_size;
110-
m_buf = m_allocator.allocate(m_size, 0);
111-
std::uninitialized_fill_n(m_buf, i_size, i_value);
112-
}
113-
/// resize the array buffer.
114-
template <class InputIterator>
115-
void resize(InputIterator i_begin, InputIterator i_end)
116-
{
117-
clear();
118-
m_size = distance(i_begin, i_end);
119-
m_buf = m_allocator.allocate(m_size, 0);
120-
std::uninitialized_copy(i_begin, i_end, m_buf);
121-
}
122-
/// expand the array buffer. the contents of it are copied to the new one
123-
void expand(size_type i_size, const T& i_value = T())
124-
{
125-
ASSERT( m_size <= i_size );
126-
if (!m_buf)
127-
resize(i_size, i_value);
128-
else
129-
{
130-
pointer buf = m_allocator.allocate(i_size, 0);
131-
std::uninitialized_copy(m_buf, m_buf + m_size, buf);
132-
std::uninitialized_fill_n(buf + m_size, i_size - m_size, i_value);
133-
clear();
134-
m_size = i_size;
135-
m_buf = buf;
136-
}
137-
}
138-
///
139-
bool empty() const { return !m_buf; }
140-
///
141-
reference operator[](size_type i_n) { return *(m_buf + i_n); }
142-
///
143-
const_reference operator[](size_type i_n) const
144-
{ return *(m_buf + i_n); }
145-
///
146-
const_reference at(size_type i_n) const
147-
{ return *(m_buf + i_n); }
148-
///
149-
reference at(size_type i_n)
150-
{ return *(m_buf + i_n); }
151-
///
152-
reference front() { return *m_buf; }
153-
///
154-
const_reference front() const { return *m_buf; }
155-
///
156-
reference back() { return *(m_buf + m_size - 1); }
157-
///
158-
const_reference back() const { return *(m_buf + m_size - 1); }
159-
///
160-
void swap(Array &i_o)
161-
{
162-
if (&i_o != this)
163-
{
164-
pointer buf = m_buf;
165-
size_type size = m_size;
166-
m_buf = i_o.m_buf;
167-
m_size = i_o.m_size;
168-
i_o.m_buf = buf;
169-
i_o.m_size = size;
170-
}
171-
}
172-
///
173-
void clear()
174-
{
175-
if (m_buf)
176-
{
177-
for (size_type i = 0; i < m_size; i ++)
178-
m_allocator.destroy(&m_buf[i]);
179-
m_allocator.deallocate(m_buf, m_size);
180-
m_buf = 0;
181-
m_size = 0;
182-
}
183-
}
123+
///
124+
size_type size() const {
125+
return m_size;
126+
}
127+
///
128+
size_type max_size() const {
129+
return -1;
130+
}
131+
/// resize the array buffer. NOTE: the original contents are cleared.
132+
void resize(size_type i_size, const T& i_value = T()) {
133+
clear();
134+
m_size = i_size;
135+
m_buf = m_allocator.allocate(m_size, 0);
136+
std::uninitialized_fill_n(m_buf, i_size, i_value);
137+
}
138+
/// resize the array buffer.
139+
template <class InputIterator>
140+
void resize(InputIterator i_begin, InputIterator i_end) {
141+
clear();
142+
m_size = distance(i_begin, i_end);
143+
m_buf = m_allocator.allocate(m_size, 0);
144+
std::uninitialized_copy(i_begin, i_end, m_buf);
145+
}
146+
/// expand the array buffer. the contents of it are copied to the new one
147+
void expand(size_type i_size, const T& i_value = T()) {
148+
ASSERT( m_size <= i_size );
149+
if (!m_buf)
150+
resize(i_size, i_value);
151+
else {
152+
pointer buf = m_allocator.allocate(i_size, 0);
153+
std::uninitialized_copy(m_buf, m_buf + m_size, buf);
154+
std::uninitialized_fill_n(buf + m_size, i_size - m_size, i_value);
155+
clear();
156+
m_size = i_size;
157+
m_buf = buf;
158+
}
159+
}
160+
///
161+
bool empty() const {
162+
return !m_buf;
163+
}
164+
///
165+
reference operator[](size_type i_n) {
166+
return *(m_buf + i_n);
167+
}
168+
///
169+
const_reference operator[](size_type i_n) const {
170+
return *(m_buf + i_n);
171+
}
172+
///
173+
const_reference at(size_type i_n) const {
174+
return *(m_buf + i_n);
175+
}
176+
///
177+
reference at(size_type i_n) {
178+
return *(m_buf + i_n);
179+
}
180+
///
181+
reference front() {
182+
return *m_buf;
183+
}
184+
///
185+
const_reference front() const {
186+
return *m_buf;
187+
}
188+
///
189+
reference back() {
190+
return *(m_buf + m_size - 1);
191+
}
192+
///
193+
const_reference back() const {
194+
return *(m_buf + m_size - 1);
195+
}
196+
///
197+
void swap(Array &i_o) {
198+
if (&i_o != this) {
199+
pointer buf = m_buf;
200+
size_type size = m_size;
201+
m_buf = i_o.m_buf;
202+
m_size = i_o.m_size;
203+
i_o.m_buf = buf;
204+
i_o.m_size = size;
205+
}
206+
}
207+
///
208+
void clear() {
209+
if (m_buf) {
210+
for (size_type i = 0; i < m_size; i ++)
211+
m_allocator.destroy(&m_buf[i]);
212+
m_allocator.deallocate(m_buf, m_size);
213+
m_buf = 0;
214+
m_size = 0;
215+
}
216+
}
184217
};
185218

186219
#endif // _ARRAY_H

compiler_specific.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ extern wchar_t **_wargv;
6060

6161
extern "C"
6262
{
63-
int WINAPI _tWinMain(HINSTANCE i_hInstance, HINSTANCE i_hPrevInstance,
64-
LPTSTR i_lpszCmdLine, int i_nCmdShow);
63+
int WINAPI _tWinMain(HINSTANCE i_hInstance, HINSTANCE i_hPrevInstance,
64+
LPTSTR i_lpszCmdLine, int i_nCmdShow);
6565
}
6666

6767
# define stati64_t stati64

0 commit comments

Comments
 (0)