ITK  5.2.0
Insight Toolkit
itkBitwiseOpsFunctors.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkBitwiseOpsFunctors_h
19 #define itkBitwiseOpsFunctors_h
20 
21 #include "itkMacro.h"
22 
23 namespace itk
24 {
25 namespace Functor
26 {
27 
33 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
34 class ITK_TEMPLATE_EXPORT AND
35 {
36 public:
37  AND() = default;
38  ~AND() = default;
39  bool
40  operator!=(const AND &) const
41  {
42  return false;
43  }
45 
46  bool
47  operator==(const AND & other) const
48  {
49  return !(*this != other);
50  }
51 
52  inline TOutput
53  operator()(const TInput1 & A, const TInput2 & B) const
54  {
55  return static_cast<TOutput>(A & B);
56  }
57 };
58 
64 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
65 class ITK_TEMPLATE_EXPORT OR
66 {
67 public:
68  OR() = default;
69  ~OR() = default;
70  bool
71  operator!=(const OR &) const
72  {
73  return false;
74  }
76 
77  bool
78  operator==(const OR & other) const
79  {
80  return !(*this != other);
81  }
82 
83  inline TOutput
84  operator()(const TInput1 & A, const TInput2 & B) const
85  {
86  return static_cast<TOutput>(A | B);
87  }
88 };
89 
95 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
96 class ITK_TEMPLATE_EXPORT XOR
97 {
98 public:
99  XOR() = default;
100  ~XOR() = default;
101  bool
102  operator!=(const XOR &) const
103  {
104  return false;
105  }
107 
108  bool
109  operator==(const XOR & other) const
110  {
111  return !(*this != other);
112  }
113 
114  inline TOutput
115  operator()(const TInput1 & A, const TInput2 & B) const
116  {
117  return static_cast<TOutput>(A ^ B);
118  }
119 };
120 
126 template <class TInput, class TOutput>
128 {
129 public:
130  // Use default copy, assigned and destructor
131  // BitwiseNot() {} default constructor OK
132 
133  bool
134  operator!=(const BitwiseNot &) const
135  {
136  return false;
137  }
138 
139  bool
140  operator==(const BitwiseNot & other) const
141  {
142  return !(*this != other);
143  }
144 
145  inline TOutput
146  operator()(const TInput & A) const
147  {
148  return static_cast<TOutput>(~A);
149  }
150 };
151 } // namespace Functor
152 } // namespace itk
153 
154 #endif
itk::Functor::XOR
bitwise XOR fucntor
Definition: itkBitwiseOpsFunctors.h:96
itk::Functor::OR::operator==
bool operator==(const OR &other) const
Definition: itkBitwiseOpsFunctors.h:78
itk::Functor::XOR::operator!=
bool operator!=(const XOR &) const
Definition: itkBitwiseOpsFunctors.h:102
itk::Functor::BitwiseNot::operator==
bool operator==(const BitwiseNot &other) const
Definition: itkBitwiseOpsFunctors.h:140
itk::Functor::AND::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkBitwiseOpsFunctors.h:53
itk::Functor::BitwiseNot::operator!=
bool operator!=(const BitwiseNot &) const
Definition: itkBitwiseOpsFunctors.h:134
itk::Functor::AND
bitwise AND functor
Definition: itkBitwiseOpsFunctors.h:34
itkMacro.h
itk::Functor::XOR::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkBitwiseOpsFunctors.h:115
itk::Functor::AND::operator!=
bool operator!=(const AND &) const
Definition: itkBitwiseOpsFunctors.h:40
itk::Functor::BitwiseNot
Performs the C++ unary bitwise NOT operator.
Definition: itkBitwiseOpsFunctors.h:127
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Functor::BitwiseNot::operator()
TOutput operator()(const TInput &A) const
Definition: itkBitwiseOpsFunctors.h:146
itk::Functor::OR::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkBitwiseOpsFunctors.h:84
itk::Functor::AND::operator==
bool operator==(const AND &other) const
Definition: itkBitwiseOpsFunctors.h:47
itk::Functor::OR
bitwise OR functor
Definition: itkBitwiseOpsFunctors.h:65
itk::Functor::XOR::operator==
bool operator==(const XOR &other) const
Definition: itkBitwiseOpsFunctors.h:109
itk::Functor::OR::operator!=
bool operator!=(const OR &) const
Definition: itkBitwiseOpsFunctors.h:71