/usr/include/itpp/base/binary.h is in libitpp-dev 4.3.1-7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | /*!
* \file
* \brief Binary class definition
* \author Tony Ottosson
*
* -------------------------------------------------------------------------
*
* Copyright (C) 1995-2010 (see AUTHORS file for a list of contributors)
*
* This file is part of IT++ - a C++ library of mathematical, signal
* processing, speech processing, and communications classes and functions.
*
* IT++ is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* IT++ is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with IT++. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef BINARY_H
#define BINARY_H
#include <itpp/base/itassert.h>
#include <itpp/itexports.h>
namespace itpp
{
/*!
\brief Binary arithmetic (boolean) class
\author Tony Ottosson
This class creates a binary arithmetic class, following the ordinary
rules for binary (GF(2)) fields.
Examples:
\code
bin a; // Creation of variable
bin a = 0; // Creating a variable and assigning it value 0
bin b = 1; // Creating a variable and assigning it value 1
bin c = a + b; // XOR operation
c = !a; // NOT
c = a * b; // AND
c = a / b; // OR
\endcode
*/
class bin
{
public:
//! Default constructor
bin(): b(0) {}
//! Set the binary object equal to \c value. Either "0" or "1".
bin(const int &value): b(static_cast<char>(value)) {
it_assert_debug((value == 0) || (value == 1),
"bin::bin(): value must be 0 or 1");
}
//! Copy constructor
bin(const bin &inbin): b(inbin.b) {}
//! Assign a value
void operator=(const int &value) {
it_assert_debug((value == 0) || (value == 1),
"bin::operator=(): value must be 0 or 1");
b = static_cast<char>(value);
}
//! Assign a value
void operator=(const bin &inbin) { b = inbin.b; }
//! OR
void operator/=(const bin &inbin) { b |= inbin.b; }
//! OR
void operator|=(const bin &inbin) { b |= inbin.b; }
//! OR
bin operator/(const bin &inbin) const { return bin(b | inbin.b); }
//! OR
bin operator|(const bin &inbin) const { return bin(b | inbin.b); }
//! XOR
void operator+=(const bin &inbin) { b ^= inbin.b; }
//! XOR
void operator^=(const bin &inbin) { b ^= inbin.b; }
//! XOR
bin operator+(const bin &inbin) const { return bin(b ^ inbin.b); }
//! XOR
bin operator^(const bin &inbin) const { return bin(b ^ inbin.b); }
//! XOR
void operator-=(const bin &inbin) { b ^= inbin.b; }
//! XOR
bin operator-(const bin &inbin) const { return bin(b ^ inbin.b); }
//! Dummy definition to be able to use vec<bin>
bin operator-() const { return bin(b); }
//! AND
void operator*=(const bin &inbin) { b &= inbin.b; }
//! AND
void operator&=(const bin &inbin) { b &= inbin.b; }
//! AND
bin operator*(const bin &inbin) const { return bin(b & inbin.b); }
//! AND
bin operator&(const bin &inbin) const { return bin(b & inbin.b); }
//! NOT
bin operator!(void) const { return bin(b ^ 1); }
//! NOT
bin operator~(void) const { return bin(b ^ 1); }
//! Check if equal
bool operator==(const bin &inbin) const { return b == inbin.b; }
//! Check if equal
bool operator==(const int &i) const { return b == i; }
//! Check if not equal
bool operator!=(const bin &inbin) const { return b != inbin.b; }
//! Check if not equal
bool operator!=(const int &i) const { return b != i; }
//! Less than (interpret the binary values {0,1} as integers)
bool operator<(const bin &inbin) const { return b < inbin.b; }
//! Less than equal (interpret the binary values {0,1} as integers)
bool operator<=(const bin &inbin) const { return b <= inbin.b; }
//! Greater than (interpret the binary values {0,1} as integers)
bool operator>(const bin &inbin) const { return b > inbin.b; }
//! Greater than equal (interpret the binary values {0,1} as integers)
bool operator>=(const bin &inbin) const { return b >= inbin.b; }
//! Convert \c bin to \c short
operator short() const { return static_cast<short>(b); }
//! Convert \c bin to \c int
operator int() const { return static_cast<int>(b); }
//! Convert \c bin to \c bool
operator bool() const { return b != 0; }
//! Convert \c bin to \c float
operator float() const { return static_cast<float>(b); }
//! Convert \c bin to \c double
operator double() const { return static_cast<double>(b); }
//! Output the binary value of the object
char value() const { return b; }
private:
char b;
};
/*!
\relatesalso bin
\brief Output stream of bin
*/
ITPP_EXPORT std::ostream &operator<<(std::ostream &output, const bin &inbin);
/*!
\relatesalso bin
\brief Input stream of bin
*/
ITPP_EXPORT std::istream &operator>>(std::istream &input, bin &outbin);
/*!
\relatesalso bin
\brief absolute value of bin
*/
inline bin abs(const bin &inbin) { return inbin; }
} // namespace itpp
namespace std // added 11/2005, EGL
{
/*!
\relatesalso itpp::bin
\brief absolute value of bin
*/
inline int abs(const itpp::bin &inbin) { return inbin; }
} // namespace std
#endif // #ifndef BINARY_H
|