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

Contents of /api/Classes/Array/FloatArray.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, 5 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 "../Binary/BinaryTools.h"
3 #include "FloatArray.h"
4 #include "../System/SystemDefine.h"
5
6 FloatArray::FloatArray()
7 {
8 buffer=0;
9 size=0;
10 internIndex=0;
11 clearBuffer(0);
12 }
13
14 FloatArray::FloatArray(int iSize)
15 {
16 buffer=(float*)malloc(sizeof(float)*iSize);
17 size=iSize;
18 internIndex=0;
19 clearBuffer(0);
20 }
21
22 FloatArray::~FloatArray()
23 {
24 free(buffer);
25 }
26
27 void FloatArray::clearBuffer(float clearValue)
28 {
29 for ( int i=0; i<size ; i++ )
30 {
31 buffer[i]=clearValue;
32 }
33 }
34
35 void FloatArray::resetInternIndex()
36 {
37 internIndex=0;
38 }
39
40 void FloatArray::internIndexForward()
41 {
42 if (internIndex >= 0 && (internIndex+1) < size )
43 {
44 internIndex++;
45 }
46 }
47
48 int FloatArray::getInternIndex()
49 {
50 return internIndex;
51 }
52
53 void FloatArray::sortLargestOrder()
54 {
55 ArrayQuickSort::setStatement(0);
56 ArrayQuickSort::sortLargestOrder((int*)buffer,0,size-1);
57 }
58
59 void FloatArray::sortSmallestOrder()
60 {
61 ArrayQuickSort::setStatement(1);
62 ArrayQuickSort::sortSmallestOrder((int*)buffer,0,size-1);
63 }
64
65 void FloatArray::setFloat(float value)
66 {
67 if (internIndex >= 0 && internIndex < size )
68 {
69 buffer[internIndex]=value;
70 }
71 }
72
73 void FloatArray::setFloat(float value,int index)
74 {
75 if (index >= 0 && index < size )
76 {
77 buffer[index]=value;
78 }
79 }
80
81 float FloatArray::getFloat()
82 {
83 if (internIndex >= 0 && internIndex < size )
84 {
85 return buffer[internIndex];
86 }
87
88 return 0;
89 }
90
91 float FloatArray::getFloat(int index)
92 {
93 if (index >= 0 && index < size )
94 {
95 return buffer[index];
96 }
97
98 return 0;
99 }
100
101
102 void FloatArray::removeFloat(int index)
103 {
104 if (index >= 0 && index < size )
105 {
106 --size;
107
108 if ( size > 0 )
109 {
110 for ( int i=0; i<size ; i++ )
111 {
112 if ( i >= index )
113 {
114 buffer[i]=buffer[i+1];
115 }
116 }
117 }
118 }
119 }
120
121 void FloatArray::addLast(float value)
122 {
123 BinaryTools binaryTools;
124
125 if (buffer==0)
126 {
127 buffer=(float*)malloc(sizeof(float)*1);
128 buffer[0]=value;
129 size=1;
130 }
131 else
132 {
133 float *tempBuffer=binaryTools.addFloatValueToArray(buffer,size,value);
134 free(buffer);
135 buffer=tempBuffer;
136 size++;
137 }
138 }

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26