-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArray.hpp
101 lines (83 loc) · 1.91 KB
/
Array.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/******************************************************************************
** (C) Chris Oldwood
**
** MODULE: ARRAY.HPP
** COMPONENT: Windows C++ Library.
** DESCRIPTION: The CArray class declaration.
**
*******************************************************************************
*/
// Check for previous inclusion
#ifndef ARRAY_HPP
#define ARRAY_HPP
#if _MSC_VER > 1000
#pragma once
#endif
/******************************************************************************
**
** This is the base class for all array collections.
**
*******************************************************************************
*/
class CArray
{
public:
//
// Attributes.
//
size_t Size() const;
//
// Memory methods.
//
virtual void Reserve(size_t nSize);
protected:
// Sort callback function.
typedef int (*PFNQSCOMPARE)(const void* pItem1, const void* pItem2);
//
// Constructors/Destructor.
//
CArray(size_t nItemSize);
CArray(const CArray& rArray);
virtual ~CArray();
//
// Members.
//
byte* m_pData;
size_t m_nSize;
size_t m_nAllocSize;
size_t m_nItemSize;
//
// Internal Methods.
//
void* At(size_t nIndex) const;
void* operator[](size_t nIndex) const;
void Set(size_t nIndex, const void* pItem);
size_t Add(const void* pItem);
void Insert(size_t nIndex, const void* pItem);
void Remove(size_t nIndex);
void RemoveAll();
void Sort(PFNQSCOMPARE pfnCompare);
private:
// NotCopyable.
CArray& operator=(const CArray&);
};
/******************************************************************************
**
** Implementation of inline functions.
**
*******************************************************************************
*/
inline size_t CArray::Size() const
{
return m_nSize;
}
inline void* CArray::At(size_t nIndex) const
{
ASSERT(nIndex < m_nSize);
return (m_pData + (nIndex * m_nItemSize));
}
inline void* CArray::operator[](size_t nIndex) const
{
return At(nIndex);
}
#endif //ARRAY_HPP