QGpCoreTools/Value.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of QGpCoreTools.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2006-09-22
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef VALUE_H
00029 #define VALUE_H
00030 
00031 #include "Complex.h"
00032 #include "QGpCoreToolsDLLExport.h"
00033 
00034 namespace QGpCoreTools {
00035 
00036   template <class numberType>
00037   class QGPCORETOOLS_EXPORT Value
00038   {
00039   public:
00040     Value() {_valid=false;}
00041     Value(const numberType& val) {_valid=true; _value=val;}
00042     Value(const Value<numberType>& o) {_valid=o._valid; _value=o._value;}
00043     ~Value() {}
00044 
00045     void operator=(const Value& o) {_valid=o._valid; _value=o._value;}
00046     void operator=(const numberType& val) {_valid=true; _value=val;}
00047 
00048     const numberType& value() const {return _value;}
00049     void setValue(const numberType& val) {_value=val; _valid=true;}
00050 
00051     void setValid(bool v) {_valid=v;}
00052     bool isValid() const {return _valid;}
00053 
00054   private:
00055     numberType _value;
00056     bool _valid;
00057   };
00058 
00059   class RealValue : public Value<double>
00060   {
00061   public:
00062     RealValue() : Value<double>() {}
00063     RealValue(const double& val) : Value<double>(val) {}
00064     RealValue(const RealValue& o) : Value<double>(o) {}
00065 
00066     inline void log10();
00067     inline void exp10();
00068     inline void abs();
00069   };
00070 
00071   typedef Value<Complex> ComplexValue;
00072 
00073   inline void RealValue::log10()
00074   {
00075     if(isValid()) {
00076       setValue(::log10(value()));
00077     }
00078   }
00079 
00080   inline void RealValue::exp10()
00081   {
00082     if(isValid()) {
00083       setValue(::pow(10.0, value()));
00084     }
00085   }
00086 
00087   inline void RealValue::abs()
00088   {
00089     setValue(::fabs(value()));
00090   }
00091 
00092 } // namespace QGpCoreTools
00093 
00094 #endif // VALUE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines