/[cvs]/api/Classes/Array/StringArray.cpp
ViewVC logotype

Contents of /api/Classes/Array/StringArray.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Sun Jul 1 20:47:58 2001 UTC (23 years, 4 months ago) by bearsoft
Branch: lazy, MAIN
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
First import

1 #include "../Sort/ArrayQuickSort.h"
2 #include "StringArray.h"
3 #include "../System/SystemDefine.h"
4
5 StringArray::StringArray()
6 {
7 buffer=0;
8 size=0;
9 }
10
11 StringArray::StringArray(int iSize)
12 {
13 if (iSize > 0 )
14 {
15 buffer=(String**)malloc(sizeof(String*)*iSize);
16 size=iSize;
17
18 for ( int r=0; r<size ; r++ )
19 {
20 buffer[r]=new String("");
21 }
22 }
23 }
24
25 StringArray::~StringArray()
26 {
27 for ( int r=0 ; r<size ; r++ )
28 {
29 String *string=buffer[r];
30 delete string;
31 }
32
33 if (buffer!=0)
34 {
35 free(buffer);
36 }
37 }
38
39 void StringArray::setString(char *iBuffer,int index)
40 {
41 if (index >= 0 && index < size )
42 {
43 String *string=buffer[index];
44 string->setString(iBuffer);
45 }
46 }
47
48 void StringArray::removeString(int index)
49 {
50 if (index >= 0 && index < size && buffer != 0 )
51 {
52 --size;
53
54 String *string=buffer[index];
55 delete string;
56
57 if (size > 0)
58 {
59 for ( int i=0; i<size ; i++ )
60 {
61 if ( i >= index )
62 {
63 buffer[i]=buffer[i+1];
64 }
65 }
66 }
67 }
68 }
69
70 char *StringArray::getString(int index)
71 {
72 if (index >= 0 && index < size )
73 {
74 String *string=buffer[index];
75 return string->buffer;
76 }
77 return 0;
78 }
79
80 void StringArray::sortLargestOrder()
81 {
82 ArrayQuickSort::setStatement(1);
83 ArrayQuickSort::sortLargestStringOrder(buffer,0,size-1);
84 }
85
86 void StringArray::sortSmallestOrder()
87 {
88 ArrayQuickSort::setStatement(0);
89 ArrayQuickSort::sortSmallestStringOrder(buffer,0,size-1);
90 }
91
92
93 void StringArray::addLast(String &iString)
94 {
95 addLast(iString.buffer);
96 }
97
98 void StringArray::addLast(String *iString)
99 {
100 addLast(iString->buffer);
101 }
102
103 void StringArray::addLast(char *iBuffer)
104 {
105 if (buffer==null)
106 {
107 buffer=(String**)malloc(sizeof(String*)*1);
108 buffer[0]=new String(iBuffer);
109 size=1;
110 }
111 else
112 {
113 String **tempBuffer=addStringToArray(buffer,size,new String(iBuffer));
114 free(buffer);
115 buffer=tempBuffer;
116 size++;
117 }
118 }
119
120 //////////////////////////////////////////////////////////////////////////////////////
121 //add two Strings together and returns a new String
122 //////////////////////////////////////////////////////////////////////////////////////
123
124 String **StringArray::addStringToArray(String **source, int sourceSize, String *stringPointer)
125 {
126 int forward=0;
127
128 String **buffer=(String**)malloc((sourceSize*sizeof(String*))+sizeof(String*));
129
130 for ( int s=0 ; s<sourceSize ; s++ )
131 {
132 buffer[forward]=source[s];
133 forward++;
134 }
135
136 buffer[forward]=stringPointer;
137
138
139 return buffer;
140 }

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26