00001
00050 #ifndef ABA_GLOBAL_H
00051 #define ABA_GLOBAL_H
00052
00053 #include "abacus/abacusroot.h"
00054 #include "abacus/ostream.h"
00055 #include "abacus/hash.h"
00056 #include "abacus/string.h"
00057
00058 class ABA_GLOBAL : public ABA_ABACUSROOT {
00059 public:
00060
00081 ABA_GLOBAL(double eps = 1.0e-4, double machineEps = 1.0e-7,
00082 double infinity = 1.0e32);
00083
00085 virtual ~ABA_GLOBAL();
00086
00094 friend ostream &operator<<(ostream &out, const ABA_GLOBAL &rhs);
00095
00106 virtual ABA_OSTREAM& out(int nTab = 0);
00107
00116 virtual ABA_OSTREAM& err(int nTab = 0);
00117
00120 double eps() const;
00121
00127 void eps(double e);
00128
00138 double machineEps() const;
00139
00145 void machineEps(double e);
00146
00155 double infinity() const;
00156
00166 void infinity(double x);
00167
00173 bool isInfinity(double x) const;
00174
00180 bool isMinusInfinity(double x) const;
00181
00189 bool equal(double x, double y) const;
00190
00195 bool isInteger(double x) const;
00196
00201 bool isInteger(double x, double eps) const;
00202
00211 virtual char enter(istream &in);
00212
00220 void readParameters(const char *fileName);
00221
00229 void insertParameter(const char *name, const char *value);
00230
00246 int getParameter(const char *name, int ¶m);
00247 int getParameter(const char *name, unsigned int ¶m);
00248 int getParameter(const char *name, double ¶m);
00249 int getParameter(const char *name, ABA_STRING ¶m);
00250 int getParameter(const char *name, bool ¶m);
00251 int getParameter(const char *name, char ¶m);
00252
00278 void assignParameter(int ¶m, const char *name,
00279 int minVal, int maxVal);
00280
00282 void assignParameter(unsigned ¶m, const char *name,
00283 unsigned minVal,unsigned maxVal);
00284
00286 void assignParameter(double ¶m, const char *name,
00287 double minVal, double maxVal);
00288
00290 void assignParameter(bool ¶m, const char *name);
00291
00304 void assignParameter(ABA_STRING ¶m, const char *name,
00305 unsigned nFeasible=0, const char *feasible[]=0);
00314 void assignParameter(char ¶m, const char *name,
00315 const char *feasible=0);
00316
00329 void assignParameter(int ¶m, const char *name,
00330 int minVal, int maxVal, int defVal);
00331
00333 void assignParameter(unsigned ¶m, const char *name,
00334 unsigned minVal,unsigned maxVal, unsigned defVal);
00335
00337 void assignParameter(double ¶m, const char *name,
00338 double minVal, double maxVal, double defVal);
00339
00341 void assignParameter(bool ¶m, const char *name, bool defVal);
00342
00355 void assignParameter(ABA_STRING ¶m, const char *name,
00356 unsigned nFeasible, const char *feasible[],
00357 const char *defVal);
00358
00369 void assignParameter(char ¶m, const char *name,
00370 const char *feasible, char defVal);
00371
00389 int findParameter(const char *name,
00390 unsigned nFeasible, const int *feasible);
00391
00393 int findParameter(const char *name,
00394 unsigned nFeasible, const char *feasible[]);
00395
00397 int findParameter(const char *name,const char *feasible);
00398
00399 private:
00400
00403 ABA_OSTREAM out_;
00404
00407 ABA_OSTREAM err_;
00408
00411 double eps_;
00412
00419 double machineEps_;
00420
00423 double infinity_;
00424
00427 char *tab_;
00428 ABA_HASH<ABA_STRING, ABA_STRING> paramTable_;
00429 ABA_GLOBAL(const ABA_GLOBAL &rhs);
00430 const ABA_GLOBAL &operator=(const ABA_GLOBAL &rhs);
00431 };
00432
00433
00434 inline double ABA_GLOBAL::eps() const
00435 {
00436 return eps_;
00437 }
00438
00439 inline void ABA_GLOBAL::eps(double e)
00440 {
00441 eps_ = e;
00442 }
00443
00444 inline double ABA_GLOBAL::machineEps() const
00445 {
00446 return machineEps_;
00447 }
00448
00449 inline void ABA_GLOBAL::machineEps(double e)
00450 {
00451 machineEps_ = e;
00452 }
00453
00454 inline double ABA_GLOBAL::infinity() const
00455 {
00456 return infinity_;
00457 }
00458
00459 inline void ABA_GLOBAL::infinity(double x)
00460 {
00461 infinity_ = x;
00462 }
00463
00464 inline bool ABA_GLOBAL::isInfinity(double x) const
00465 {
00466 #ifdef ABACUS_NO_BOOL
00467 if (x >= infinity_) return true;
00468 else return false;
00469 #else
00470 return x >= infinity_;
00471 #endif
00472 }
00473
00474 inline bool ABA_GLOBAL::isMinusInfinity(double x) const
00475 {
00476 #ifdef ABACUS_NO_BOOL
00477 if (x <= -infinity_) return true;
00478 else return false;
00479 #else
00480 return x <= -infinity_;
00481 #endif
00482 }
00483
00484 inline bool ABA_GLOBAL::equal(double x, double y) const
00485 {
00486 if (fabs(x-y) < machineEps_) return true;
00487 else return false;
00488 }
00489
00490 inline bool ABA_GLOBAL::isInteger(double x) const
00491 {
00492 return isInteger(x, machineEps_);
00493 }
00494
00495
00496 #endif // ABA_GLOBAL_H
00497
00498