//////////////////////////////////////////////////////////////////////////////// /*! @file PhysValue.h Физвеличина. - Part of RANet - Research Assistant Net Library (based on ANSI C++). - Copyright(C) 2010, Viktor E. Bursian, St.Petersburg, Russia. Viktor.Bursian@mail.ioffe.ru */////////////////////////////////////////////////////////////////////////////// #ifndef PhysValue_H #define PhysValue_H #include "BasicMath.h" #include "Units.h" namespace RA { //------------------------------------------------------------------------------ ANNOUNCE_CLASS(sPhysValue) ANNOUNCE_CLASS(xRAlgebra) //--------------------------------------------------------------- sPhysValue --- /*! Физвеличина - вещественное число с погрешностью и единицами измерения. @todo{Fucking_Qt!} Q_DECLARE_METATYPE not in a right place (requered for my templates AddTransition,..) */ class RANet_EXPORT sPhysValue : public virtual sMathValue /*! @todo{PhysValues} virtual?*/ { STORABLE(sPhysValue) public://static static const unsigned short int MaxDigits = 7; static unsigned short int DraftNormalization; //always static unsigned short int BriefNormalization; //for Text() static unsigned short int SmartNormalization; //for editing public: sPhysValue (); explicit sPhysValue (rcsUnits units); sPhysValue (real value ,rcsUnits units); sPhysValue (real value ,real error ,rcsUnits units); explicit sPhysValue (real value); sPhysValue (real value ,real error); explicit sPhysValue (sString UnitsStr); sPhysValue (real value ,sString UnitsStr); sPhysValue (real value ,real error ,sString UnitsStr); sPhysValue (rcsPhysValue R); virtual psMathValue Replica () const { return new sPhysValue(*this); } public: bool UnitsAreFixed () const { return UnitsAreFixedFlag; } void FixTheUnits () { UnitsAreFixedFlag = true; } sUnits Units () const { return TheUnits; } sPhysValue Error () const { return sPhysValue(TheErrorMantissa *power10(TheOrder) ,TheUnits ); } rsPhysValue SetError (rcsPhysValue error); rsPhysValue SetRelativeError (real error); bool IsInf () const { return isinf(TheValueMantissa); } bool IsNaN () const { return isnan(TheValueMantissa); } bool IsPowerOfTen () const { return ThePowerOfTenFlag; } bool IsUnitsless () const; //!< Tests for being in fact unitless real ToReal () const; //!< Converts a unitless expression to real //note: a type conversion operator to real //would bring ambiguosity to math operators // sString Text (eTextFormat format=Plain // ,eTextDetalization detalization=Casual); // //!< Visual representation for user // sString Text (eTextFormat format=Plain // ,eTextDetalization detalization=Casual) // const; // //!< Visual representation for user virtual sString Text (eTextFormat format=Plain ,eTextDetalization detalization=Casual); //!< Visual representation for user virtual sString Text (eTextFormat format=Plain ,eTextDetalization detalization=Casual) const; //!< Visual representation for user void Normalize () { Normalize(SmartNormalization); } public://operators rsPhysValue operator = (rcsPhysValue); // bool operator == (rcsPhysValue) const; bool operator < (rcsPhysValue) const; sPhysValue operator + () const; sPhysValue operator - () const; sPhysValue operator + (rcsPhysValue) const; sPhysValue operator - (rcsPhysValue) const; sPhysValue operator * (rcsPhysValue) const; sPhysValue operator / (rcsPhysValue) const; sPhysValue operator * (real r) const { return (*this) * sPhysValue(r); } sPhysValue operator / (real r) const { return (*this) / sPhysValue(r); } rsPhysValue operator += (rcsPhysValue); rsPhysValue operator -= (rcsPhysValue); rsPhysValue operator *= (real); rsPhysValue operator /= (real); rsPhysValue operator << (int order_shift); public://but for internal needs in RANet and RAGUI real ValueMantissa () const { return TheValueMantissa; } real ErrorMantissa () const { return TheErrorMantissa; } int Order () const { return TheOrder; } unsigned short int Digits () const { return TheDigits; } //!< число цифр после запятой при выводе, //! актуальное с учётом погрешности private: void Normalize (unsigned short int level); sString Txt (eTextFormat format=Plain ,eTextDetalization detalization=Casual) const; private: //fields sUnits TheUnits; bool UnitsAreFixedFlag; int TheOrder; real TheValueMantissa; real TheErrorMantissa; bool PreciseFlag; bool ThePowerOfTenFlag; unsigned short int TheDigits; unsigned short int NormalizationLevel; //!< 0 - possibly not normalized; //!< 1 - units - untouched, //!< mantissa&order - OK; //!< 2 - units - within permissions; //!< n - units are looking better, //!< time consuming limited by c*exp(n) friend class sUnits; friend class sPhysRange; }; inline sPhysValue operator * (real r ,sPhysValue v) { return sPhysValue(r) * v; } inline sPhysValue operator / (real r ,sPhysValue v) { return sPhysValue(r) / v; } inline sPhysValue Abs (rcsPhysValue V) { return ( V.ValueMantissa() < 0.0 ? -V : V ); } //---------------------------------------------------------------- xRAlgebra --- class RANet_EXPORT xRAlgebra : public xException { public: xRAlgebra (rcsString msg_text ,rcsString src_file_name = sString() ,int line_no = 0 ,rcsString class_name = sString("xRAlgebra") ) :xException(msg_text,src_file_name,line_no ,class_name) {} // xRAlgebra (literal FName // ,int LineNo); // xRAlgebra (literal FName // ,int LineNo // ,literal What); }; //------------------------------------------------------------------------------ } //namespace RA #include Q_DECLARE_METATYPE(RA::sPhysValue) #endif