ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkBitwiseOpsFunctors.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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() {}
38  ~AND() {}
39  bool operator!=(const AND &) const
40  {
41  return false;
42  }
44 
45  bool operator==(const AND & other) const
46  {
47  return !( *this != other );
48  }
49 
50  inline TOutput operator()(const TInput1 & A, const TInput2 & B) const
51  {
52  return static_cast< TOutput >( A & B );
53  }
54 };
55 
61 template< typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1 >
62 class ITK_TEMPLATE_EXPORT OR
63 {
64 public:
65  OR() {}
66  ~OR() {}
67  bool operator!=(const OR &) const
68  {
69  return false;
70  }
72 
73  bool operator==(const OR & other) const
74  {
75  return !( *this != other );
76  }
77 
78  inline TOutput operator()(const TInput1 & A, const TInput2 & B) const
79  {
80  return static_cast< TOutput >( A | B );
81  }
82 };
83 
89 template< typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1 >
90 class ITK_TEMPLATE_EXPORT XOR
91 {
92 public:
93  XOR() {}
94  ~XOR() {}
95  bool operator!=(const XOR &) const
96  {
97  return false;
98  }
100 
101  bool operator==(const XOR & other) const
102  {
103  return !( *this != other );
104  }
105 
106  inline TOutput operator()(const TInput1 & A, const TInput2 & B) const
107  {
108  return static_cast< TOutput >( A ^ B );
109  }
110 };
111 
117 template< class TInput, class TOutput >
119 {
120 public:
121  // Use default copy, assigned and destructor
122  // BitwiseNot() {} default constructor OK
123 
124  bool operator!=(const BitwiseNot &) const
125  {
126  return false;
127  }
128 
129  bool operator==(const BitwiseNot & other) const
130  {
131  return !( *this != other );
132  }
133 
134  inline TOutput operator()(const TInput & A) const
135  {
136  return static_cast<TOutput>( ~A );
137  }
138 };
139 }
140 }
141 
142 #endif
TOutput operator()(const TInput &A) const
bitwise AND functor
bool operator==(const XOR &other) const
bool operator==(const BitwiseNot &other) const
bool operator==(const AND &other) const
TOutput operator()(const TInput1 &A, const TInput2 &B) const
bool operator!=(const AND &) const
bitwise OR functor
Performs the C++ unary bitwise NOT operator.
bool operator==(const OR &other) const
bitwise XOR fucntor
TOutput operator()(const TInput1 &A, const TInput2 &B) const
bool operator!=(const XOR &) const
bool operator!=(const OR &) const
TOutput operator()(const TInput1 &A, const TInput2 &B) const
bool operator!=(const BitwiseNot &) const