Back to index

salome-med  6.5.0
InterpKernelUnit.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #ifndef __INTERPKERNELUNIT_HXX__
00021 #define __INTERPKERNELUNIT_HXX__
00022 
00023 #include "INTERPKERNELDefines.hxx"
00024 #include "InterpKernelException.hxx"
00025 
00026 #include <map>
00027 #include <sstream>
00028 
00029 namespace INTERP_KERNEL
00030 {
00031   class INTERPKERNEL_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 INTERPKERNEL_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 INTERPKERNEL_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