libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNInt.h
Go to the documentation of this file.
1 /* Copyright 2009-2016 INSA Lyon, CoReNum, 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: CRNInt.h
19  * \author Yann LEYDIER
20  */
21 
22 #ifndef CRNInt_HEADER
23 #define CRNInt_HEADER
24 
25 #include <CRNObject.h>
26 #include <CRNString.h>
27 #include <CRNMath/CRNProp3.h>
28 #include <CRNMath/CRNMath.h>
29 
30 namespace crn
31 {
32  /****************************************************************************/
40  class Int: public Object
41  {
42  public:
44  Int(int i = 0) noexcept:val(i) {}
45  virtual ~Int() override = default;
46 
47  Int(const Int&) = default;
48  Int(Int&&) = default;
49  Int& operator=(const Int&) = default;
50  Int& operator=(Int&&) = default;
51 
53  operator int() const noexcept { return val; }
54 
55  Int& operator+=(Int i) noexcept { val += i.val; return *this; }
56  Int& operator-=(Int i) noexcept { val -= i.val; return *this; }
57  Int& operator*=(Int i) noexcept { val *= i.val; return *this; }
58  Int& operator/=(Int i) noexcept { val /= i.val; return *this; }
59  bool operator<(Int i) noexcept { return val < i.val; }
60  bool operator>(Int i) noexcept { return val > i.val; }
61  bool operator<=(Int i) noexcept { return val <= i.val; }
62  bool operator>=(Int i) noexcept { return val >= i.val; }
63 
65  void Deserialize(xml::Element &el);
67  xml::Element Serialize(xml::Element &parent) const;
68 
69  private:
70  int val;
73  };
74  template<> struct IsSerializable<Int> : public std::true_type {};
75  template<> struct IsClonable<Int> : public std::true_type {};
76  template<> struct IsMetric<Int> : public std::true_type {};
77 
78  inline double Distance(const Int &i1, const Int &i2) noexcept { return Abs(i1 - i2); }
79 }
80 inline crn::Int operator+(crn::Int i1, const crn::Int &i2) noexcept { return i1 += i2; }
81 inline crn::Int operator-(crn::Int i1, const crn::Int &i2) noexcept { return i1 -= i2; }
82 inline crn::Int operator*(crn::Int i1, const crn::Int &i2) noexcept { return i1 *= i2; }
83 inline double operator*(double d, const crn::Int &i) noexcept { return d * int(i); }
84 inline double operator*(const crn::Int &i, double d) noexcept { return d * int(i); }
85 inline crn::Int operator/(crn::Int i1, const crn::Int &i2) noexcept { return i1 /= i2; }
86 
87 #include <CRNData/CRNIntPtr.h>
88 
89 #endif
90 
91 
BoolNotBoolDummy operator-(const BoolNotBoolDummy &, const BoolNotBoolDummy &)
Definition: CRNImage.h:124
bool operator<=(Int i) noexcept
Definition: CRNInt.h:61
void Deserialize(xml::Element &el)
Reads from an XML element.
Definition: CRNInt.cpp:37
#define CRN_SERIALIZATION_CONSTRUCTOR(classname)
Defines a default constructor from xml element.
Definition: CRNObject.h:165
XML element.
Definition: CRNXml.h:135
bool operator>(Int i) noexcept
Definition: CRNInt.h:60
bool operator>=(Int i) noexcept
Definition: CRNInt.h:62
bool operator<(Int i) noexcept
Definition: CRNInt.h:59
Int & operator/=(Int i) noexcept
Definition: CRNInt.h:58
Int & operator+=(Int i) noexcept
Definition: CRNInt.h:55
Int & operator=(const Int &)=default
xml::Element Serialize(xml::Element &parent) const
Dumps to an XML element.
Definition: CRNInt.cpp:54
BoolNotBoolDummy operator*(const BoolNotBoolDummy &, const BoolNotBoolDummy &)
Definition: CRNImage.h:125
BoolNotBoolDummy operator+(const BoolNotBoolDummy &, const BoolNotBoolDummy &)
Definition: CRNImage.h:123
Int & operator-=(Int i) noexcept
Definition: CRNInt.h:56
double Distance(const Int &i1, const Int &i2) noexcept
Definition: CRNInt.h:78
Int(int i=0) noexcept
Default constructor.
Definition: CRNInt.h:44
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
BoolNotBoolDummy operator/(const BoolNotBoolDummy &, const BoolNotBoolDummy &)
Definition: CRNImage.h:126
Int & operator*=(Int i) noexcept
Definition: CRNInt.h:57
#define CRN_DECLARE_CLASS_CONSTRUCTOR(classname)
Declares a class constructor.
Definition: CRNObject.h:173
Interface class for the metric real number class.
Definition: CRNInt.h:40
virtual ~Int() override=default