1 |
bearsoft |
1.1 |
#ifndef __ObjectMatrisList_H__
|
2 |
|
|
#define __ObjectMatrisList_H__
|
3 |
|
|
|
4 |
|
|
#include "../String/String.h"
|
5 |
|
|
#include "../LinkedList/StringLinkedList.h"
|
6 |
|
|
#include "../LinkedList/ObjectLinkedList.h"
|
7 |
|
|
#include "../Element/ObjectElement.h"
|
8 |
|
|
#include "../Element/ObjectMatrisElement.h"
|
9 |
|
|
#include "../System/System.h"
|
10 |
|
|
#include "../Array/ObjectArray.h"
|
11 |
|
|
#include "../System/SystemDefine.h"
|
12 |
|
|
|
13 |
|
|
template <class ClassName>
|
14 |
|
|
|
15 |
|
|
class ObjectMatrisList
|
16 |
|
|
{
|
17 |
|
|
|
18 |
|
|
public:
|
19 |
|
|
|
20 |
|
|
ObjectMatrisList(int iColumnSize)
|
21 |
|
|
{
|
22 |
|
|
howfar=0;
|
23 |
|
|
columnLength=iColumnSize;
|
24 |
|
|
objectArray = new ObjectArray<ClassName>(columnLength);
|
25 |
|
|
|
26 |
|
|
for ( int i=0; i<columnLength ; i++ )
|
27 |
|
|
{
|
28 |
|
|
addColumn(1,"test");
|
29 |
|
|
}
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
~ObjectMatrisList()
|
33 |
|
|
{
|
34 |
|
|
removeAllElement();
|
35 |
|
|
|
36 |
|
|
if (objectArray != null)
|
37 |
|
|
{
|
38 |
|
|
objectArray->resetArray();
|
39 |
|
|
|
40 |
|
|
delete objectArray;
|
41 |
|
|
}
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
void removeAllElement()
|
45 |
|
|
{
|
46 |
|
|
if ( howfar != 0 )
|
47 |
|
|
{
|
48 |
|
|
ObjectMatrisElement<ClassName> *element=first;
|
49 |
|
|
|
50 |
|
|
for ( int s=0; s<howfar ; s++ )
|
51 |
|
|
{
|
52 |
|
|
ObjectMatrisElement<ClassName> *tempElement=element->next;
|
53 |
|
|
delete element;
|
54 |
|
|
element=tempElement;
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
int columnSize()
|
60 |
|
|
{
|
61 |
|
|
return howfar;
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
int rowSize()
|
65 |
|
|
{
|
66 |
|
|
if (howfar!=0)
|
67 |
|
|
{
|
68 |
|
|
ObjectLinkedList<ClassName> *objectList = getColumn(0);
|
69 |
|
|
return objectList->size();
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
return 0;
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
void addColumnInRow(ClassName *object, String &iName ,int index)
|
76 |
|
|
{
|
77 |
|
|
if ( index >= 0 && index < columnLength )
|
78 |
|
|
{
|
79 |
|
|
objectArray->setObject(object, iName.buffer, index);
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
void addColumnInRow(ClassName *object, String *iName ,int index)
|
84 |
|
|
{
|
85 |
|
|
if ( index >= 0 && index < columnLength )
|
86 |
|
|
{
|
87 |
|
|
objectArray->setObject(object, iName->buffer, index);
|
88 |
|
|
}
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
void addColumnInRow(ClassName *object, char *iName ,int index)
|
92 |
|
|
{
|
93 |
|
|
if ( index >= 0 && index < columnLength )
|
94 |
|
|
{
|
95 |
|
|
objectArray->setObject(object, iName, index);
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
void addColumn(int type, char *iName)
|
101 |
|
|
{
|
102 |
|
|
addColumnMain(type, iName);
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
void addColumnMain(int type, char *iName)
|
106 |
|
|
{
|
107 |
|
|
if (howfar == 0)
|
108 |
|
|
{
|
109 |
|
|
first = new ObjectMatrisElement<ClassName>(iName);
|
110 |
|
|
last=first;
|
111 |
|
|
}
|
112 |
|
|
else
|
113 |
|
|
{
|
114 |
|
|
last->next = new ObjectMatrisElement<ClassName>(iName);
|
115 |
|
|
last->next->previos=last;
|
116 |
|
|
last=last->next;
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
howfar++;
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
void addRow()
|
123 |
|
|
{
|
124 |
|
|
ObjectLinkedList<ClassName> *objectList=null;
|
125 |
|
|
|
126 |
|
|
for ( int i=0; i<howfar ; i++ )
|
127 |
|
|
{
|
128 |
|
|
objectList = getColumn(i);
|
129 |
|
|
ObjectElement<ClassName> *object=objectArray->getObjectElement(i);
|
130 |
|
|
objectList->addLast(object->classNameElement,object->name);
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
int size=objectList->size()-1;
|
134 |
|
|
|
135 |
|
|
for ( int r=0; r<howfar ; r++ )
|
136 |
|
|
{
|
137 |
|
|
ObjectLinkedList<ClassName> *objectList = getColumn(r);
|
138 |
|
|
ObjectLinkedList<ClassName> *objectListPrevios = getColumn(r-1);
|
139 |
|
|
ObjectLinkedList<ClassName> *objectListNext = getColumn(r+1);
|
140 |
|
|
|
141 |
|
|
ObjectElement<ClassName> *object=objectList->getObjectElement(size);
|
142 |
|
|
|
143 |
|
|
ObjectElement<ClassName> *objectPrevios=null;
|
144 |
|
|
|
145 |
|
|
if (objectListPrevios!=null)
|
146 |
|
|
{
|
147 |
|
|
objectPrevios=objectListPrevios->getObjectElement(size);
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
ObjectElement<ClassName> *objectNext=null;
|
151 |
|
|
|
152 |
|
|
if (objectListNext!=null)
|
153 |
|
|
{
|
154 |
|
|
objectNext=objectListNext->getObjectElement(size);
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
object->sideNext=objectNext;
|
158 |
|
|
object->sidePrevios=objectPrevios;
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
objectArray->resetArray();
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
ObjectArray<ClassName> *getRow(int columnIndex, int rowIndex)
|
165 |
|
|
{
|
166 |
|
|
objectArray->resetArray();
|
167 |
|
|
|
168 |
|
|
ObjectLinkedList<ClassName> *objectList = getColumn(columnIndex);
|
169 |
|
|
ObjectElement<ClassName> *objectElementIndex = objectList->getObjectElement(rowIndex);
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
ObjectElement<ClassName> *objectElement=objectElementIndex;
|
173 |
|
|
|
174 |
|
|
int indexBack=columnIndex;
|
175 |
|
|
|
176 |
|
|
for (int i=0; i<columnIndex ; i++)
|
177 |
|
|
{
|
178 |
|
|
--indexBack;
|
179 |
|
|
objectElement=objectElement->sidePrevios;
|
180 |
|
|
objectArray->setObject(objectElement->classNameElement, indexBack);
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
objectElement=objectElementIndex;
|
184 |
|
|
|
185 |
|
|
for (int r=0; r<(columnLength-columnIndex) ; r++)
|
186 |
|
|
{
|
187 |
|
|
objectArray->setObject(objectElement->classNameElement, r+columnIndex);
|
188 |
|
|
objectElement=objectElement->sideNext;
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
return objectArray;
|
192 |
|
|
}
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
void sortColumnInSmallestOrder(int index)
|
197 |
|
|
{
|
198 |
|
|
ObjectLinkedList<ClassName> *objectList = getColumn(index);
|
199 |
|
|
|
200 |
|
|
if (objectList!=null)
|
201 |
|
|
{
|
202 |
|
|
objectList->sortSmallestOrder();
|
203 |
|
|
}
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
void sortColumnInLargestOrder(int index)
|
207 |
|
|
{
|
208 |
|
|
ObjectLinkedList<ClassName> *objectList = getColumn(index);
|
209 |
|
|
|
210 |
|
|
if (objectList!=null)
|
211 |
|
|
{
|
212 |
|
|
objectList->sortLargestOrder();
|
213 |
|
|
}
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
ObjectLinkedList<ClassName> *getColumn(int index)
|
217 |
|
|
{
|
218 |
|
|
if ( index >= 0 && index < howfar)
|
219 |
|
|
{
|
220 |
|
|
ObjectMatrisElement<ClassName> *element=first;
|
221 |
|
|
|
222 |
|
|
for ( int s=0; s<index ; s++ )
|
223 |
|
|
{
|
224 |
|
|
element=element->next;
|
225 |
|
|
}
|
226 |
|
|
|
227 |
|
|
// stringLength=element->length;
|
228 |
|
|
|
229 |
|
|
return element->classNameElement;
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
return null;
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
|
236 |
|
|
ObjectMatrisElement<ClassName> *first;
|
237 |
|
|
ObjectMatrisElement<ClassName> *last;
|
238 |
|
|
|
239 |
|
|
int howfar;
|
240 |
|
|
int columnLength;
|
241 |
|
|
ObjectArray<ClassName> *objectArray;
|
242 |
|
|
|
243 |
|
|
};
|
244 |
|
|
|
245 |
|
|
#endif |