00001
00002
00003
00004
00005
00006
00007 #ifndef CALC_BASE_H
00008 #define CALC_BASE_H
00009
00010
00011
00012
00013
00014 #include <cmath>
00015 #include <iostream>
00016
00017
00018
00019
00020
00021 namespace calc {
00022
00023
00024
00025
00133
00134
00142 class Err {
00143
00144 public:
00145
00146
00147
00154 int getIndex(void) const {return iErr;}
00161 const char *getClass(void) const {return sCls;}
00168 const char *getDescription(void) const {return sDsc;}
00175 const char *getLibrary(void) const {return LIB_NAME;}
00182 const char *getNamespace(void) const {return LIB_NSPACE;}
00183
00184
00185
00195 friend std::ostream& operator<<(std::ostream& ostr, const Err& er)
00196 {ostr<<er.LIB_NAME<<" Error ("<<er.LIB_NSPACE<<"::"<<er.sCls;
00197 ostr<<" - #"<<er.iErr<<") - "<<er.sDsc; return ostr;}
00198
00199
00200
00201 static const char *const LIB_NAME;
00202 static const char *const LIB_NSPACE;
00203 static const char *const DEF_MESSAGE;
00204 static const char *const DEF_CLASS;
00205
00206 protected:
00207
00208
00209
00218 Err(void) {iErr=0; sCls=DEF_CLASS; sDsc=DEF_MESSAGE;}
00227 Err(int indErr, const char *strCls, const char *strDsc)
00228 {iErr=indErr; sCls=strCls; sDsc=strDsc;}
00235 Err(const Err &er) {iErr=er.iErr; sCls=er.sCls; sDsc=er.sDsc;}
00239 ~Err(void) {}
00240
00241
00242
00253 bool setError(int indErr)
00254 {if(indErr<0) return true; iErr=indErr; return false;}
00268 bool setError(const char* strCls, const char* strDsc)
00269 {if((!strCls)||(!strDsc)) return true; sCls=strCls; sDsc=strDsc; return false;}
00282 bool setError(int indErr, const char *strCls, const char *strDsc)
00283 {if((indErr<0)||(!strCls)||(!strDsc)) return true;
00284 iErr=indErr; sCls=strCls; sDsc=strDsc; return false;}
00285
00286 private:
00287
00288
00289
00290 int iErr;
00291 const char *sCls;
00292 const char *sDsc;
00293 };
00294
00295
00296
00298 const char *const calc::Err::LIB_NAME="CalcLib";
00300 const char *const calc::Err::LIB_NSPACE="calc";
00302 const char *const calc::Err::DEF_MESSAGE="execution error";
00304 const char *const calc::Err::DEF_CLASS="????";
00305
00306
00307
00308
00310
00319 class Base {
00320
00321 public:
00322
00323
00324
00326 enum BOUND {
00327 LO=0 ,
00328 HI ,
00329 BOUND_CNT,
00330 };
00331
00332
00333
00341 bool isInit(void) const {return (!nogo);}
00342
00343 static const double PI;
00344
00345 protected:
00346
00347
00348
00357 Base(void) {nogo=true;}
00364 Base(const Base &ca) {nogo=ca.nogo;}
00369 ~Base(void) {}
00370
00371
00372
00377 virtual void varInit (void)=0;
00378
00387 template<typename T>
00388 static void swap(T &x1, T &x2)
00389 {const T sto=x1; x1=x2; x2=sto;}
00400 template<typename T>
00401 static T abs(const T &x)
00402 {return (x<(T)(0)?(-x):(x));}
00416 template<typename T>
00417 static T* memCopy(T* aDst, const T* aSrc, int nCnt)
00418 {if((aDst)&&(aSrc))
00419 for(int iCnt=0; iCnt<nCnt; iCnt++) aDst[iCnt]=aSrc[iCnt];
00420 return aDst;}
00436 template<typename T>
00437 static bool memComp(const T* arr1, const T* arr2, int nCnt)
00438 {if((!arr1)||(!arr2)||(nCnt<=0)) return true;
00439 for(int iCnt=0; iCnt<nCnt; iCnt++) if(arr1[iCnt]!=arr2[iCnt]) return true;
00440 return false;}
00453 template<typename T>
00454 static bool memSet(T* arr, int x, int nCnt)
00455 {if((arr)&&(nCnt>0)) {
00456 const T xSet=(T)(x);
00457 for(int iCnt=0; iCnt<nCnt; iCnt++) arr[iCnt]=xSet;
00458 }
00459 return arr;}
00460
00461
00462
00468 bool nogo;
00469 };}
00470
00471
00472
00474 const double calc::Base::PI=3.141592653589793238462643;
00475
00476
00477
00478
00479
00480 #endif
00481
00482