1 |
bearsoft |
1.1 |
#include "../String/String.h"
|
2 |
|
|
#include "../String/StringInput.h"
|
3 |
|
|
#include "../System/System.h"
|
4 |
|
|
#include "ExtProperties.h"
|
5 |
|
|
#include "../System/SystemDefine.h"
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
ExtProperties::ExtProperties()
|
9 |
|
|
{
|
10 |
|
|
objectLinkedList=null;
|
11 |
|
|
stringInput=null;
|
12 |
|
|
}
|
13 |
|
|
|
14 |
|
|
ExtProperties::~ExtProperties()
|
15 |
|
|
{
|
16 |
|
|
if (objectLinkedList!=null)
|
17 |
|
|
{
|
18 |
|
|
delete objectLinkedList;
|
19 |
|
|
}
|
20 |
|
|
if (stringInput!=null)
|
21 |
|
|
{
|
22 |
|
|
delete stringInput;
|
23 |
|
|
}
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
char *ExtProperties::newRowOrNot()
|
27 |
|
|
{
|
28 |
|
|
char *word=stringInput->scanWord();
|
29 |
|
|
|
30 |
|
|
if(stringInput->getScanWordStatus())
|
31 |
|
|
{
|
32 |
|
|
if (stringInput->getScanRowStatus())
|
33 |
|
|
{
|
34 |
|
|
newRow=true;
|
35 |
|
|
}
|
36 |
|
|
}
|
37 |
|
|
else
|
38 |
|
|
{
|
39 |
|
|
word=null;
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
return word;
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
void ExtProperties::readFile(char *fileName)
|
46 |
|
|
{
|
47 |
|
|
objectLinkedList=new ObjectLinkedList<ExtPropertiesElement>();
|
48 |
|
|
|
49 |
|
|
stringInput=new StringInput();
|
50 |
|
|
|
51 |
|
|
stringInput->readFile(fileName);
|
52 |
|
|
|
53 |
|
|
//stringInput->dontDefragMemory(1000); // select this if you want to have intern word buffer == less malloc, free
|
54 |
|
|
|
55 |
|
|
int rowCounter=0;
|
56 |
|
|
newRow=true;
|
57 |
|
|
ExtPropertiesElement *extPropertiesElement=null;
|
58 |
|
|
char *key=null;
|
59 |
|
|
char *data=null;
|
60 |
|
|
|
61 |
|
|
while (stringInput->getScanWordStatus())
|
62 |
|
|
{
|
63 |
|
|
if (newRow)
|
64 |
|
|
{
|
65 |
|
|
extPropertiesElement=objectLinkedList->addLast(new ExtPropertiesElement(stringInput->scanWord(),"info"));
|
66 |
|
|
newRow=false;
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
String key=newRowOrNot();
|
70 |
|
|
|
71 |
|
|
if (!newRow)
|
72 |
|
|
{
|
73 |
|
|
String data=newRowOrNot();
|
74 |
|
|
|
75 |
|
|
if ( key.buffer != null && data.buffer != null )
|
76 |
|
|
{
|
77 |
|
|
extPropertiesElement->addLast(key.buffer,data.buffer);
|
78 |
|
|
// System::println(key.buffer);
|
79 |
|
|
// System::println(data.buffer);
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
/* int size=objectLinkedList->sizeOf();
|
86 |
|
|
|
87 |
|
|
for ( int r=0; r<2 ; r++ )
|
88 |
|
|
{
|
89 |
|
|
ExtPropertiesElement *extPropertiesElement=(ExtPropertiesElement*)objectLinkedList->getElement(r);
|
90 |
|
|
System::println(extPropertiesElement->key->buffer);
|
91 |
|
|
|
92 |
|
|
System::println(extPropertiesElement->getKeyData(r,"xpos"));
|
93 |
|
|
|
94 |
|
|
int size2=extPropertiesElement->getSize();
|
95 |
|
|
|
96 |
|
|
for ( int r2=0; r2<size2 ; r2++ )
|
97 |
|
|
{
|
98 |
|
|
System::println(extPropertiesElement->getKey(r2));
|
99 |
|
|
System::println(extPropertiesElement->getData(r2));
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
|
|
*/
|
103 |
|
|
stringInput->resetScanWord(); //moves the pointer to the begining of the string buffer again
|
104 |
|
|
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
char *ExtProperties::getData(int index, int iKey)
|
108 |
|
|
{
|
109 |
|
|
if (index>=0 && index<objectLinkedList->size())
|
110 |
|
|
{
|
111 |
|
|
ExtPropertiesElement *extPropertiesElement=objectLinkedList->getElement(index);
|
112 |
|
|
return extPropertiesElement->getData(iKey);
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
return null;
|
116 |
|
|
}
|