00001 #include "range.h"
00002 #include "mvaexit.h"
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 CAMrange::CAMrange()
00031 {
00032 base = 0;
00033 bound = 0;
00034 stride = 0;
00035 singleArgumentFlag = 0;
00036 underscoreFlag = 0;
00037 nullFlag = 1;
00038 }
00039
00040 CAMrange::CAMrange( const CAMrange& A)
00041 {
00042 base = A.base;
00043 bound = A.bound;
00044 stride = A.stride;
00045 singleArgumentFlag = A.singleArgumentFlag;
00046 underscoreFlag = A.underscoreFlag;
00047 nullFlag = A.nullFlag;
00048 }
00049
00050 CAMrange::CAMrange(long inputSize)
00051 {
00052 base = 1;
00053 bound = inputSize;
00054 stride = 1;
00055 singleArgumentFlag = 1;
00056 underscoreFlag = 0;
00057 nullFlag = 0;
00058 CAMrange::CAMrangeError(*this);
00059 }
00060 CAMrange::CAMrange(long inputBase, long inputBound)
00061 {
00062 base = inputBase;
00063 bound = inputBound;
00064 stride = 1;
00065 singleArgumentFlag = 0;
00066 underscoreFlag = 0;
00067 nullFlag = 0;
00068 CAMrange::CAMrangeError(*this);
00069 }
00070 CAMrange::CAMrange(long inputBase, long inputBound, long inputStride)
00071 {
00072 base = inputBase;
00073 bound = inputBound;
00074 stride = inputStride;
00075 singleArgumentFlag = 0;
00076 underscoreFlag = 0;
00077 nullFlag = 0;
00078 CAMrange::CAMrangeError(*this);
00079 }
00080 CAMrange::CAMrange(const CAMunderscore&)
00081 {
00082 base = 0;
00083 bound = 0;
00084 stride = 0;
00085 singleArgumentFlag = 0;
00086 underscoreFlag = 1;
00087 nullFlag = 0;
00088 }
00089
00090
00091
00092
00093
00094 CAMrange::~CAMrange()
00095 {
00096 }
00097
00098
00099
00100
00101
00102 CAMrange& CAMrange::operator =( const CAMrange& A)
00103 {
00104 base = A.base;
00105 bound = A.bound;
00106 stride = A.stride;
00107 singleArgumentFlag = A.singleArgumentFlag;
00108 underscoreFlag = A.underscoreFlag;
00109 nullFlag = A.nullFlag;
00110 return *this;
00111 }
00112
00113
00114
00115
00116
00117
00118 ostream& operator <<(ostream& out_stream, const CAMrange& A)
00119 {
00120
00121
00122
00123 out_stream << "base = " << A.base
00124 << " bound = " << A.bound
00125 << " stride = " << A.stride << '\n';
00126 return(out_stream);
00127 }
00128
00129
00130
00131
00132
00133
00134 void CAMrange::initialize()
00135 {
00136 base = 0;
00137 bound = 0;
00138 stride = 0;
00139 singleArgumentFlag = 0;
00140 underscoreFlag = 0;
00141 nullFlag = 1;
00142 }
00143
00144 void CAMrange::initialize(const CAMrange& R)
00145 {
00146 base = R.base;
00147 bound = R.bound;
00148 stride = R.stride;
00149 singleArgumentFlag = R.singleArgumentFlag;
00150 underscoreFlag = R.underscoreFlag;
00151 nullFlag = R.nullFlag;
00152 }
00153
00154 void CAMrange::initialize(long inputSize)
00155 {
00156 base = 1;
00157 bound = inputSize;
00158 stride = 1;
00159 singleArgumentFlag = 1;
00160 underscoreFlag = 0;
00161 nullFlag = 0;
00162 CAMrange::CAMrangeError(*this);
00163 }
00164
00165 void CAMrange::initialize(long inputBase, long inputBound)
00166 {
00167 base = inputBase;
00168 bound = inputBound;
00169 stride = 1;
00170 singleArgumentFlag = 0;
00171 underscoreFlag = 0;
00172 nullFlag = 0;
00173 CAMrange::CAMrangeError(*this);
00174 }
00175
00176 void CAMrange::initialize(long inputBase, long inputBound, long inputStride)
00177 {
00178 base = inputBase;
00179 bound = inputBound;
00180 stride = inputStride;
00181 singleArgumentFlag = 0;
00182 underscoreFlag = 0;
00183 nullFlag = 0;
00184 CAMrange::CAMrangeError(*this);
00185 }
00186 CAMrange CAMrange::operator ++ (int)
00187 {
00188 if(nullFlag != 1)
00189 {
00190 base = base + 1;
00191 bound = bound + 1;
00192 }
00193 return *this;
00194 }
00195
00196 CAMrange CAMrange::operator -- (int)
00197 {
00198 if(nullFlag != 1)
00199 {
00200 base = base - 1;
00201 bound = bound - 1;
00202 }
00203 return *this;
00204 }
00205
00206 CAMrange CAMrange::operator + (long i)
00207 {
00208 CAMrange R;
00209 if(nullFlag != 1)
00210 {R.initialize(base + i, bound + i, stride);}
00211
00212 return R;
00213 }
00214
00215 CAMrange CAMrange::operator - (long i)
00216 {
00217 CAMrange R;
00218 if(nullFlag != 1)
00219 {R.initialize(base - i, bound - i, stride);}
00220
00221 return R;
00222 }
00223
00224 CAMrange operator + (long i, CAMrange& A)
00225 {
00226 CAMrange R;
00227 if(A.nullFlag != 1)
00228 {R.initialize(A.base + i, A.bound + i, A.stride);}
00229
00230 return R;
00231 }
00232
00233 void CAMrange::CAMrangeError(const CAMrange& A)
00234 {
00235 if(((A.bound - A.base) + 1) < 0 )
00236 {
00237 cerr <<"Error : Negative Number of Elements In Index Range " << endl;
00238 CAMmvaExit();
00239 }
00240 if(A.stride <= 0 )
00241 {
00242 cerr <<"Error : Non Positive Stride in Index Range " << endl;
00243 CAMmvaExit();
00244 }
00245 }
00246
00247
00248
00249
00250
00251
00252
00253