00001
00002
00003
00004
00005
00006
00007 #ifndef CALC_PRTC_H
00008 #define CALC_PRTC_H
00009
00010
00011
00012
00013
00014 #include <cstdio>
00015 #include <iostream>
00016 #include <iomanip>
00017
00018 #include "Cheb.h"
00019 #include "Intp.h"
00020 #include "NIntp.h"
00021 #include "Mtx.h"
00022
00023
00024
00025
00026
00027 namespace calc {
00028
00029
00030
00031
00037
00038
00048 class PrtC {
00049
00050 public:
00051
00052
00053
00055 enum FTYPE {
00056 LABEL=0 ,
00057 MARGIN ,
00058 INDENT ,
00059 TYPE ,
00060 XTYPE ,
00061 YTYPE ,
00062 PRECISION,
00063 WIDTH ,
00064 FTYPE_CNT,
00065 };
00067 enum PDATA {
00068 CHAR=0 ,
00069 CHAR_UNSIGNED ,
00070 SHORT ,
00071 SHORT_UNSIGNED,
00072 INT ,
00073 INT_UNSIGNED ,
00074 LONG ,
00075 LONG_UNSIGNED ,
00076 FLOAT ,
00077 DOUBLE ,
00078 DOUBLE_LONG ,
00079 PDATA_CNT ,
00080 };
00082 static const int INTP_CNT=5;
00084 static const int BUF_STR=256;
00086 static const int BUF_CNT=10;
00087
00088
00089
00101 PrtC(void)
00102 {cTypG=cTypX=cTypY=DEF_TYP; cLbl=DEF_LBL;
00103 cMgn=cInd=DEF_SPC3; iPrc=DEF_PRC; iWdt=DEF_WDT;}
00126 PrtC(const char *cType, const char *cLabel=DEF_LBL, const char *cMargin=DEF_SPC3,
00127 const char *cIndent=DEF_SPC3, int iWidth=DEF_WDT, int iPrecision=DEF_PRC)
00128 {cTypG=
00129 cTypX=
00130 cTypY=((cType !=(char*)(0))?cType :DEF_TYP );
00131 cLbl =((cLabel !=(char*)(0))?cLabel :DEF_LBL );
00132 cMgn =((cMargin !=(char*)(0))?cMargin :DEF_SPC3);
00133 cInd =((cIndent !=(char*)(0))?cIndent :DEF_SPC3);
00134 iPrc =((iPrecision> -1)?iPrecision:DEF_PRC );
00135 iWdt =((iWidth > -1)?iWidth :DEF_WDT );}
00159 PrtC(enum PrtC::PDATA eType, const char *cLabel=DEF_LBL, const char *cMargin=DEF_SPC3,
00160 const char *cIndent=DEF_SPC3, int iWidth=DEF_WDT, int iPrecision=DEF_PRC)
00161 {cTypG=
00162 cTypX=
00163 cTypY=((eType > -1)&&(eType<PDATA_CNT)?PNAME[eType]:DEF_TYP );
00164 cLbl =((cLabel !=(char*)(0)) ?cLabel :DEF_LBL );
00165 cMgn =((cMargin !=(char*)(0)) ?cMargin :DEF_SPC3);
00166 cInd =((cIndent !=(char*)(0)) ?cIndent :DEF_SPC3);
00167 iPrc =((iPrecision> -1) ?iPrecision :DEF_PRC );
00168 iWdt =((iWidth > -1) ?iWidth :DEF_WDT );}
00175 PrtC(const PrtC &pr)
00176 {cMgn =pr.cMgn ; cInd =pr.cInd ;
00177 cLbl =pr.cLbl ; cTypG=pr.cTypG;
00178 cTypX=pr.cTypX; cTypY=pr.cTypY;
00179 iPrc =pr.iPrc ; iWdt =pr.iWdt ;}
00184 virtual ~PrtC(void) {}
00185
00186
00187
00188 const char* getChar (enum PrtC::FTYPE fType) const;
00189 int getInt (enum PrtC::FTYPE fType) const;
00190 bool setFormat (enum PrtC::FTYPE fType, const char* str);
00191 bool setFormat (enum PrtC::FTYPE fType, int num);
00192
00193 template <typename xType, typename yType>
00194 bool stream(std::ostream &ostr, const Cheb<xType,yType> &ch) const;
00195 template <typename bType>
00196 bool stream(std::ostream &ostr, const Mtx<bType> &mt) const;
00197 template <typename xType, typename yType>
00198 bool stream(std::ostream &ostr, const Intp<xType,yType> &in) const;
00199 template <typename xType, typename yType>
00200 bool stream(std::ostream &ostr, const Cube<xType,yType> &cu);
00201 template <typename xType, typename yType>
00202 bool stream(std::ostream &ostr, const Nurb<xType,yType> &nu) const;
00203 template <typename xType, typename yType>
00204 bool stream(std::ostream &ostr, const EndCube<xType,yType> &ec);
00205 template <typename xType, typename yType>
00206 bool stream(std::ostream &ostr, const EndCube<xType,yType> *ep, int n);
00207 template <typename xType, typename yType>
00208 bool stream(std::ostream &ostr, const NIntp<xType,yType> &ni);
00209 template <typename xType, typename yType>
00210 bool stream(std::ostream &ostr, const NCube<xType,yType> &cu);
00211 template <typename xType, typename yType>
00212 bool stream(std::ostream &ostr, const NNurb<xType,yType> &nu);
00213
00230 bool setFormat (enum PrtC::PDATA index)
00231 {const bool tst=((index>=CHAR)&&(index<PDATA_CNT));
00232 if(tst) cTypG=cTypX=cTypY=PNAME[index]; return (!tst);}
00248 bool setFormat (const char *str)
00249 {if(str) cTypG=cTypX=cTypY=str; return (!str);}
00267 bool setFormat (enum PrtC::PDATA indX, enum PrtC::PDATA indY)
00268 {const bool tst=((indX>=CHAR)&&(indX<PDATA_CNT)&&(indY>=CHAR)&&(indY<PDATA_CNT));
00269 if(tst) cTypX=PNAME[indX],cTypY=PNAME[indY]; return (!tst);}
00286 bool setFormat (const char *strX, const char *strY)
00287 {const bool tst=((strX)&&(strY));
00288 if(tst) cTypX=strX,cTypY=strY; return (!tst);}
00289
00290
00291
00292 static const char* const TNAME[INTP_CNT];
00293 static const char* const VNAME[INTP_CNT];
00294
00295 static const int DEF_PRC;
00296 static const int DEF_WDT;
00297 static const char* const DEF_SPC3;
00298 static const char* const DEF_LBL;
00299 static const char* const DEF_TYP;
00300
00301 static const char* const SYM_COMMENT;
00302 static const char* const SYM_CONSTANT;
00303 static const char* const SYM_BLANK;
00304 static const char* const SYM_POINTER;
00305 static const char* const SYM_NULL;
00306
00307 static const char* const PNAME[PDATA_CNT];
00308 static const char* const PNAME_ENDCUBE;
00309
00310 static const char* const VNAME_CHEB;
00311 static const char* const VNAME_MTX;
00312 static const char* const VNAME_OCNT;
00313 static const char* const VNAME_NCNT;
00314 static const char* const VNAME_CNT;
00315 static const char* const VNAME_NDIM;
00316 static const char* const VNAME_ENDCUBE;
00317
00318 static const char* const TNAME_CHEB;
00319 static const char* const TNAME_NCNT;
00320 static const char* const TNAME_OCNT;
00321 static const char* const TNAME_CNT;
00322 static const char* const TNAME_END;
00323
00324 static const char* const SNAME_CHEB;
00325 static const char* const SNAME_INTP;
00326 static const char* const SNAME_NINTP;
00327 static const char* const SNAME_ENDCUBE;
00328 static const char* const SNAME_END;
00329
00330 private:
00331
00332
00333
00334 template <typename bType>
00335 void valueC(std::ostream &ostr, const char* cTyp, const char* cNam, bType vDat) const;
00336
00337 template <typename xType, typename yType>
00338 void valEndCube(std::ostream &ostr, const char* cName,
00339 const EndCube<xType,yType> &ec) const;
00340
00341 template <typename bType>
00342 void array1DC(std::ostream &ostr, const char* cTyp,
00343 const char* cNam, const bType* aDat, int nDat) const;
00344
00345 template <typename bType>
00346 void array2DC(std::ostream &ostr, const char* cTyp, const char* cNam,
00347 const bType* const* aDat, int nRow, int nCol) const;
00348 template <typename bType>
00349 void array2DC(std::ostream &ostr, const char* cTyp, const char* cNam,
00350 const bType* const* aDat, const int* aRow, int nCol);
00351
00352 template <typename bType>
00353 void arrayNVC(std::ostream &ostr, const char* cTyp, const char* cNam,
00354 const bType* aDat, const int* aDim, int nDim);
00355 template <typename xType, typename yType>
00356 void arrayNVC(std::ostream &ostr, const char* cTyp, const char* cNam,
00357 const Intp<xType,yType>* const* aIn, const int *aDim, int nDim,
00358 enum Intp<xType,yType>::VTYPE vTyp);
00359
00360 template <typename bType>
00361 void arrayIVC(std::ostream &ostr, const char* cTyp, const bType* aDat,
00362 const int* aDim, int nDim, int iDim) const;
00363 template <typename xType, typename yType>
00364 void arrayIVC(std::ostream &ostr, const char* cTyp,
00365 const Intp<xType,yType>* const* aIi, const int* aDim,
00366 int nDim, int iDim, enum Intp<xType,yType>::VTYPE vTyp) const;
00367
00385 const char* appendC(int ind, const char* s1, const char* s2)
00386 {return (((ind>=0)&&(ind<BUF_CNT))?
00387 strncat(strncpy(cBuf[ind],s1,BUF_STR-1),s2,(BUF_STR-1)-strlen(s1)):SYM_NULL);}
00406 const char* appendC(int ind, const char* str, int num)
00407 {return (((ind>=0)&&(ind<BUF_CNT)&&(sprintf(cBuf[ind],"%s%d",str,num)))?
00408 cBuf[ind]:SYM_NULL);}
00418 void titleC(std::ostream &ostr, const char* cTle, const char *cEnd=SYM_NULL) const
00419 {ostr<<cMgn<<SYM_COMMENT<<cLbl<<SYM_BLANK<<cTle<<cEnd<<std::endl;}
00420
00421
00422
00423 char cBuf[BUF_CNT][BUF_STR];
00424 int iPrc;
00425 int iWdt;
00426 const char *cTypG;
00427 const char *cTypX;
00428 const char *cTypY;
00429 const char *cLbl;
00430 const char *cMgn;
00431 const char *cInd;
00432 };}
00433
00434
00435
00436
00437
00439 const char* const calc::PrtC::TNAME[PrtC::INTP_CNT]={
00440 "Independent" ,
00441 "Knot Vector" ,
00442 "Dependent" ,
00443 "2nd Derivative" ,
00444 "Control Polygon",
00445 };
00447 const char* const calc::PrtC::VNAME[PrtC::INTP_CNT]={
00448 "arX",
00449 "arK",
00450 "arY",
00451 "arD",
00452 "arP",
00453 };
00455 const char* const calc::PrtC::PNAME[PrtC::PDATA_CNT]={
00456 "char" ,
00457 "char unsigned" ,
00458 "short" ,
00459 "short unsigned",
00460 "int" ,
00461 "int unsigned" ,
00462 "long" ,
00463 "long unsigned" ,
00464 "float" ,
00465 "double" ,
00466 "double long" ,
00467 };
00468
00469
00470
00472 const char* const calc::PrtC::PNAME_ENDCUBE="EndCube";
00474 const char* const calc::PrtC::VNAME_CHEB="arC";
00476 const char* const calc::PrtC::VNAME_MTX="arM";
00478 const char* const calc::PrtC::VNAME_OCNT="arOn";
00480 const char* const calc::PrtC::VNAME_NCNT="arNn";
00482 const char* const calc::PrtC::VNAME_CNT="nPoints";
00484 const char* const calc::PrtC::VNAME_ENDCUBE="endCube";
00486 const char* const calc::PrtC::VNAME_NDIM="n";
00487
00488
00489
00491 const char* const calc::PrtC::TNAME_CHEB="Polynomial Coefficient";
00493 const char* const calc::PrtC::TNAME_CNT="Characteristic Data Point Count";
00495 const char* const calc::PrtC::TNAME_OCNT="Polynomial Data Point Count";
00497 const char* const calc::PrtC::TNAME_NCNT="Data Count by Dimension";
00499 const char *const calc::PrtC::TNAME_END=" Data Array";
00500
00501
00502
00504 const char *const calc::PrtC::SNAME_CHEB="Cheb Function Interpolation";
00506 const char *const calc::PrtC::SNAME_INTP="Intp Tabular Interpolation";
00508 const char *const calc::PrtC::SNAME_NINTP="NIntp Multi-Dimensional Tabular Interpolation";
00510 const char *const calc::PrtC::SNAME_ENDCUBE="EndCube Derivative Identifier";
00512 const char *const calc::PrtC::SNAME_END=" Parameters";
00513
00514
00515
00517 const char* const calc::PrtC::SYM_CONSTANT="const ";
00519 const char* const calc::PrtC::SYM_COMMENT="// ";
00521 const char* const calc::PrtC::SYM_BLANK=" ";
00523 const char* const calc::PrtC::SYM_POINTER="*";
00525 const char* const calc::PrtC::SYM_NULL="";
00526
00527
00528
00530 const int calc::PrtC::DEF_PRC=5;
00532 const int calc::PrtC::DEF_WDT=13;
00534 const char *const calc::PrtC::DEF_SPC3=" ";
00536 const char *const calc::PrtC::DEF_LBL="CalcLib";
00538 const char *const calc::PrtC::DEF_TYP=PNAME[DOUBLE];
00539
00540
00541
00542
00543
00544 #endif
00545
00546
00547
00548
00549
00550 #include "PrtC.cpp"
00551
00552