Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
XStringArray.h
Go to the documentation of this file.
1//! @file XStringArray.h
2//! @brief CXStringArray class which is an array of CXString
3//
4//////////////////////////////////////////////////////////////////////
5
6#if !defined(CEXSTRINGARRAY_INCLUDE_H)
7#define CEXSTRINGARRAY_INCLUDE_H
8
9#ifdef _MSC_VER
10#pragma once
11#endif // _MSC_VER
12
13BEGIN_MOOTOOLS_NAMESPACE
14
15/////////////////////////////////////////////////////////////
16//! @class CXStringArray
17//! @brief CXStringArray implement an array of CXString.
18//!
19//! @note Implementation consideration.\nThe array is not based CElementArray, because it stores CXString in m_pData but most of the calling methods uses LPCTSTR.\n
20//! SetAt beneficiate of the implicit conversion from LPCTSTR to CXString (m_pData[i] = (LPCTSTR)string;\n
21//! CElementArray::SetAt assumes that the element provide is based on the class store in m_pData, but cannot perform conversion from raw data to a given class.\n
22//! Using CElementArray would involves to convert any LPCTSTR to CXString which causes overhead.
23//!
24class DLL_TOOLSFUNCTION CXStringArray : public CXObject
25{
26 DECLARE_SERIAL_XOBJECT(CXStringArray)
27public:
28
29 // Construction
31
32 // Attributes
33 int GetSize() const;
34 bool IsEmpty() const;
35 int GetUpperBound() const;
36 void SetSize(int nNewSize, int nGrowBy = -1);
37
38 // Operations
39 // Clean up
40 void FreeExtra();
41 void RemoveAll();
42
43 // Accessing elements
44 const CXString& GetAt(int nIndex) const;
45 void SetAt(int nIndex, LPCTSTR newElement);
46
47 void SetAt(int nIndex, const CXString& newElement);
48
49 CXString& ElementAt(int nIndex);
50
51 // Direct Access to the element data (may return NULL)
52 const CXString* GetData() const;
53 CXString* GetData();
54
55 // Potentially growing the array
56 void SetAtGrow(int nIndex, LPCTSTR newElement);
57
58 void SetAtGrow(int nIndex, const CXString& newElement);
59
60 int Add(LPCTSTR newElement);
61
62 int Add(const CXString& newElement);
63
64 int Append(const CXStringArray& src);
65 void Copy(const CXStringArray& src);
66
67 // overloaded operator helpers
68 const CXString& operator[](int nIndex) const;
69 CXString& operator[](int nIndex);
70
71 // Operations that move elements around
72 void InsertAt(int nIndex, LPCTSTR newElement, int nCount = 1);
73
74 void InsertAt(int nIndex, const CXString& newElement, int nCount = 1);
75
76 void RemoveAt(int nIndex, int nCount = 1);
77 void InsertAt(int nStartIndex, const CXStringArray* pNewArray);
78
79 // Implementation
80protected:
81 CXString* m_pData; // the actual array of data
82 int m_nSize; // # of elements (upperBound - 1)
83 int m_nMaxSize; // max allocated
84 int m_nGrowBy; // grow amount
85
86 void InsertEmpty(int nIndex, int nCount);
87
88
89public:
90 virtual ~CXStringArray();
91
92 void Serialize(CXArchive&);
93#ifdef _DEBUG
94 void Dump() const;
95#endif
96
97protected:
98 // local typedefs for class templates
99 typedef CXString BASE_TYPE;
100 typedef LPCTSTR BASE_ARG_TYPE;
101};
102
103
104inline int CXStringArray::GetSize() const
105{
106 return m_nSize;
107}
108
109inline bool CXStringArray::IsEmpty() const
110{
111 return m_nSize == 0;
112}
113
114inline int CXStringArray::GetUpperBound() const
115{
116 return m_nSize - 1;
117}
118
119inline void CXStringArray::RemoveAll()
120{
121 SetSize(0);
122}
123
124inline const CXString& CXStringArray::GetAt(int nIndex) const
125{
126 XASSERT(nIndex >= 0 && nIndex < m_nSize);
127 if (nIndex < 0 || nIndex >= m_nSize)
129 return m_pData[nIndex];
130}
131inline void CXStringArray::SetAt(int nIndex, LPCTSTR newElement)
132{
133 XASSERT(nIndex >= 0 && nIndex < m_nSize);
134 if (nIndex < 0 || nIndex >= m_nSize)
136 m_pData[nIndex] = newElement;
137}
138
139inline void CXStringArray::SetAt(int nIndex, const CXString& newElement)
140{
141 XASSERT(nIndex >= 0 && nIndex < m_nSize);
142 if (nIndex < 0 || nIndex >= m_nSize)
144 m_pData[nIndex] = newElement;
145}
146
147inline CXString& CXStringArray::ElementAt(int nIndex)
148{
149 XASSERT(nIndex >= 0 && nIndex < m_nSize);
150 if (nIndex < 0 || nIndex >= m_nSize)
152 return m_pData[nIndex];
153}
154
155inline const CXString* CXStringArray::GetData() const
156{
157 return (const CXString*)m_pData;
158}
159
160inline CXString* CXStringArray::GetData()
161{
162 return (CXString*)m_pData;
163}
164
165inline int CXStringArray::Add(LPCTSTR newElement)
166{
167 int nIndex = m_nSize;
168 SetAtGrow(nIndex, newElement);
169 return nIndex;
170}
171
172inline int CXStringArray::Add(const CXString& newElement)
173{
174 int nIndex = m_nSize;
175 SetAtGrow(nIndex, newElement);
176 return nIndex;
177}
178
179inline const CXString& CXStringArray::operator[](int nIndex) const
180{
181 return GetAt(nIndex);
182}
183
184inline CXString& CXStringArray::operator[](int nIndex)
185{
186 return ElementAt(nIndex);
187}
188
189END_MOOTOOLS_NAMESPACE
190
191#endif // !defined(CEXSTRINGARRAY_INCLUDE_H)
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
Definition XArchive.h:17
CXStringArray implement an array of CXString.
Definition XStringArray.h:25