libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNReal.h
Go to the documentation of this file.
1 /* Copyright 2006-2016 Yann LEYDIER, CoReNum, INSA-Lyon, ENS-Lyon
2  *
3  * This file is part of libcrn.
4  *
5  * libcrn is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libcrn is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libcrn. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: CRNReal.h
19  * \author Yann LEYDIER
20  */
21 
22 #ifndef CRNREAL_HEADER
23 #define CRNREAL_HEADER
24 
25 #include <CRNObject.h>
26 #include <CRNMath/CRNMath.h>
27 
28 namespace crn
29 {
30  /****************************************************************************/
38  class Real: public Object
39  {
40  public:
42  Real(double d = 0):val(d) {}
44  virtual ~Real() override = default;
45 
46  Real(const Real&) = default;
47  Real(Real&&) = default;
48  Real& operator=(const Real&) = default;
49  Real& operator=(Real&&) = default;
50 
52  operator double() const noexcept { return val; }
53 
54  Real& operator+=(Real r) noexcept { val += r.val; return *this; }
55  Real& operator-=(Real r) noexcept { val -= r.val; return *this; }
56  Real& operator*=(Real r) noexcept { val *= r.val; return *this; }
57  Real& operator/=(Real r) noexcept { val /= r.val; return *this; }
58  bool operator<(Real r) noexcept { return val < r.val; }
59  bool operator>(Real r) noexcept { return val > r.val; }
60  bool operator<=(Real r) noexcept { return val <= r.val; }
61  bool operator>=(Real r) noexcept { return val >= r.val; }
62 
64  void Deserialize(xml::Element &el);
66  xml::Element Serialize(xml::Element &parent) const;
67 
68  private:
69  double val;
73  };
74  template<> struct IsSerializable<Real> : public std::true_type {};
75  template<> struct IsClonable<Real> : public std::true_type {};
76  template<> struct IsMetric<Real> : public std::true_type {};
77 
78  inline double Distance(const Real &r1, const Real &r2) noexcept { return Abs(r1 - r2); }
79 }
80 inline crn::Real operator+(crn::Real r1, const crn::Real &r2) noexcept { return r1 += r2; }
81 inline crn::Real operator-(crn::Real r1, const crn::Real &r2) noexcept { return r1 -= r2; }
82 inline crn::Real operator*(crn::Real r1, const crn::Real &r2) noexcept { return r1 *= r2; }
83 inline crn::Real operator/(crn::Real r1, const crn::Real &r2) noexcept { return r1 /= r2; }
84 
85 #include <CRNData/CRNRealPtr.h>
86 
87 #endif
BoolNotBoolDummy operator-(const BoolNotBoolDummy &, const BoolNotBoolDummy &)
Definition: CRNImage.h:124
Real & operator/=(Real r) noexcept
Definition: CRNReal.h:57
#define CRN_SERIALIZATION_CONSTRUCTOR(classname)
Defines a default constructor from xml element.
Definition: CRNObject.h:165
Real & operator+=(Real r) noexcept
Definition: CRNReal.h:54
XML element.
Definition: CRNXml.h:135
Real(double d=0)
Default constructor.
Definition: CRNReal.h:42
virtual ~Real() override=default
Destructor.
bool operator<(Real r) noexcept
Definition: CRNReal.h:58
void Deserialize(xml::Element &el)
Reads from an XML element.
Definition: CRNReal.cpp:40
Interface class for the metric real number class.
Definition: CRNReal.h:38
BoolNotBoolDummy operator*(const BoolNotBoolDummy &, const BoolNotBoolDummy &)
Definition: CRNImage.h:125
xml::Element Serialize(xml::Element &parent) const
Dumps to an XML element.
Definition: CRNReal.cpp:57
BoolNotBoolDummy operator+(const BoolNotBoolDummy &, const BoolNotBoolDummy &)
Definition: CRNImage.h:123
Real & operator=(const Real &)=default
double Distance(const Int &i1, const Int &i2) noexcept
Definition: CRNInt.h:78
bool operator<=(Real r) noexcept
Definition: CRNReal.h:60
void Abs(Image< T > &img, typename std::enable_if< std::is_arithmetic< T >::value >::type *dummy=nullptr) noexcept
Replaces each pixel by its absolute value.
Definition: CRNImageGray.h:47
Real & operator-=(Real r) noexcept
Definition: CRNReal.h:55
BoolNotBoolDummy operator/(const BoolNotBoolDummy &, const BoolNotBoolDummy &)
Definition: CRNImage.h:126
bool operator>(Real r) noexcept
Definition: CRNReal.h:59
#define CRN_DECLARE_CLASS_CONSTRUCTOR(classname)
Declares a class constructor.
Definition: CRNObject.h:173
bool operator>=(Real r) noexcept
Definition: CRNReal.h:61
Real & operator*=(Real r) noexcept
Definition: CRNReal.h:56