Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __INTERPKERNELUNIT_HXX__
00021 #define __INTERPKERNELUNIT_HXX__
00022
00023 #include "INTERPKERNELEXPREVALDefines.hxx"
00024 #include "InterpKernelException.hxx"
00025
00026 #include <map>
00027 #include <sstream>
00028
00029 namespace INTERP_KERNEL
00030 {
00031 class INTERPKERNELEXPREVAL_EXPORT UnitDataBase
00032 {
00033 public:
00034 UnitDataBase();
00035 const short *getInfoForUnit(const std::string& unit,
00036 double& addFact, double& mFact) const throw(INTERP_KERNEL::Exception);
00037 static UnitDataBase _uniqueMapForExpr;
00038 static const int SIZE_OF_UNIT_BASE=5;
00039 private:
00040 std::map<std::string,double> _prefix_pow_10;
00041 std::map<std::string,const short *> _units_semantic;
00042 std::map<std::string,double> _units_mul;
00043 std::map<std::string,double> _units_add;
00044 private:
00045 static const int NB_OF_PREF_POW10=22;
00046 static const char *PREF_POW10[NB_OF_PREF_POW10];
00047 static const double POW10[NB_OF_PREF_POW10];
00048 static const int NB_OF_UNITS_RECOGN=29;
00049 static const char *UNITS_RECOGN[NB_OF_UNITS_RECOGN];
00050 static const short PROJ_IN_BASE[NB_OF_UNITS_RECOGN][SIZE_OF_UNIT_BASE];
00051 static const double MUL_COEFF[NB_OF_UNITS_RECOGN];
00052 static const double ADD_COEFF[NB_OF_UNITS_RECOGN];
00053 };
00054
00055 class INTERPKERNELEXPREVAL_EXPORT DecompositionInUnitBase
00056 {
00057 public:
00058 DecompositionInUnitBase();
00059 void setInfo(const short *vals, double addFact, double mFact);
00060 short operator[](int i) const { return _value[i]; }
00061 bool operator==(const DecompositionInUnitBase& other) const;
00062 void getTranslationParams(const DecompositionInUnitBase& other, double& mul, double& add) const;
00063 bool isEqual(short mass, short lgth, short time, short intensity, short temp,
00064 double add, double mult);
00065 bool isUnitary() const;
00067 void negate();
00068 bool isAdimensional() const;
00069 void tryToConvertInUnit(double val) throw(INTERP_KERNEL::Exception);
00070 DecompositionInUnitBase &operator*(const DecompositionInUnitBase& other);
00071 DecompositionInUnitBase &operator/(const DecompositionInUnitBase& other);
00072 DecompositionInUnitBase &operator^(const DecompositionInUnitBase& other) throw(INTERP_KERNEL::Exception);
00073 private:
00074 void dealWithAddFactor(const DecompositionInUnitBase& other);
00075 static int couldItBeConsideredAsInt(double val) throw(INTERP_KERNEL::Exception);
00076 static bool areDoubleEquals(double a, double b);
00077 static double powInt(double val, int exp);
00078 private:
00079 short _value[UnitDataBase::SIZE_OF_UNIT_BASE];
00080 double _add_to_base;
00081 double _mult_fact_to_base;
00082 };
00083
00099 class INTERPKERNELEXPREVAL_EXPORT Unit
00100 {
00101 public:
00102 Unit(const char *reprC, bool tryToInterp=true);
00103 Unit(const char *reprFortran, int sizeOfRepr, bool tryToInterp=true);
00104 void tryToInterprate() const;
00105 bool isInterpretationOK() const;
00106 bool isCompatibleWith(const Unit& other) const;
00107 double convert(const Unit& target, double sourceVal) const;
00108 std::string getCoarseRepr() const;
00109 private:
00110 std::string _coarse_repr;
00111 mutable bool _is_interpreted;
00112 mutable bool _is_interpretation_ok;
00113 mutable DecompositionInUnitBase _decomp_in_base;
00114 };
00115 }
00116
00117 #endif