/usr/include/mysql++/tiny_int.h is in libmysql++-dev 3.2.1+pristine-1.
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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | /// \file tiny_int.h
/// \brief Declares class for holding a SQL TINYINT
/***********************************************************************
Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
(c) 2004-2007 by Educational Technology Resources, Inc. Others may
also hold copyrights on code in this file. See the CREDITS.txt file
in the top directory of the distribution for details.
This file is part of MySQL++.
MySQL++ is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
MySQL++ 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 Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with MySQL++; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
***********************************************************************/
#if !defined(MYSQLPP_TINY_INT_H)
#define MYSQLPP_TINY_INT_H
#include "common.h"
#include <ostream>
namespace mysqlpp {
/// \brief Class for holding an SQL \c TINYINT value
///
/// This is required because the closest C++ type, \c char, doesn't
/// have all the right semantics. For one, inserting a \c char into a
/// stream won't give you a number. For another, if you don't specify
/// signedness explicitly, C++ doesn't give a default, so it's signed
/// on some platforms, unsigned on others.
///
/// The template parameter is intended to allow instantiating it as
/// tiny_int<unsigned char> to hold \c TINYINT \c UNSIGNED values.
/// There's nothing stopping you from using any other integer type if
/// you want to be perverse, but please don't do that.
///
/// Several of the functions below accept an \c int argument, but
/// internally we store the data as a \c char by default. Beware of
/// integer overflows!
template <typename VT = signed char>
class tiny_int
{
public:
//// Type aliases
typedef tiny_int<VT> this_type; ///< alias for this object's type
typedef VT value_type; ///< alias for type of internal value
/// \brief Default constructor
///
/// Value is uninitialized
tiny_int() { }
/// \brief Create object from any integral type that can be
/// converted to a \c short \c int.
tiny_int(value_type v) :
value_(value_type(v))
{
}
/// \brief Return truthiness of value
operator bool() const
{
return value_;
}
/// \brief Return value as an \c int.
operator int() const
{
return static_cast<int>(value_);
}
/// \brief Return raw data value with no size change
operator value_type() const
{
return value_;
}
/// \brief Assign a new value to the object.
this_type& operator =(int v)
{
value_ = static_cast<value_type>(v);
return *this;
}
/// \brief Add another value to this object
this_type& operator +=(int v)
{
value_ += static_cast<value_type>(v);
return *this;
}
/// \brief Subtract another value to this object
this_type& operator -=(int v)
{
value_ -= static_cast<value_type>(v);
return *this;
}
/// \brief Multiply this value by another object
this_type& operator *=(int v)
{
value_ *= static_cast<value_type>(v);
return *this;
}
/// \brief Divide this value by another object
this_type& operator /=(int v)
{
value_ /= static_cast<value_type>(v);
return *this;
}
/// \brief Divide this value by another object and store the
/// remainder
this_type& operator %=(int v)
{
value_ %= static_cast<value_type>(v);
return *this;
}
/// \brief Bitwise AND this value by another value
this_type& operator &=(int v)
{
value_ &= static_cast<value_type>(v);
return *this;
}
/// \brief Bitwise OR this value by another value
this_type& operator |=(int v)
{
value_ |= static_cast<value_type>(v);
return *this;
}
/// \brief Bitwise XOR this value by another value
this_type& operator ^=(int v)
{
value_ ^= static_cast<value_type>(v);
return *this;
}
/// \brief Shift this value left by \c v positions
this_type& operator <<=(int v)
{
value_ <<= static_cast<value_type>(v);
return *this;
}
/// \brief Shift this value right by \c v positions
this_type& operator >>=(int v)
{
value_ >>= static_cast<value_type>(v);
return *this;
}
/// \brief Add one to this value and return that value
this_type& operator ++()
{
++value_;
return *this;
}
/// \brief Subtract one from this value and return that value
this_type& operator --()
{
--value_;
return *this;
}
/// \brief Add one to this value and return the previous value
this_type operator ++(int)
{
this_type tmp = value_;
++value_;
return tmp;
}
/// \brief Subtract one from this value and return the previous
/// value
this_type operator --(int)
{
this_type tmp = value_;
--value_;
return tmp;
}
/// \brief Return this value minus \c i
this_type operator -(const this_type& i) const
{
return value_ - i.value_;
}
/// \brief Return this value plus \c i
this_type operator +(const this_type& i) const
{
return value_ + i.value_;
}
/// \brief Return this value multiplied by \c i
this_type operator *(const this_type& i) const
{
return value_ * i.value_;
}
/// \brief Return this value divided by \c i
this_type operator /(const this_type& i) const
{
return value_ / i.value_;
}
/// \brief Return the modulus of this value divided by \c i
this_type operator %(const this_type& i) const
{
return value_ % i.value_;
}
/// \brief Return this value bitwise OR'd by \c i
this_type operator |(const this_type& i) const
{
return value_ | i.value_;
}
/// \brief Return this value bitwise AND'd by \c i
this_type operator &(const this_type& i) const
{
return value_ & i.value_;
}
/// \brief Return this value bitwise XOR'd by \c i
this_type operator ^(const this_type& i) const
{
return value_ ^ i.value_;
}
/// \brief Return this value bitwise shifted left by \c i
this_type operator <<(const this_type& i) const
{
return value_ << i.value_;
}
/// \brief Return this value bitwise shifted right by \c i
this_type operator >>(const this_type& i) const
{
return value_ >> i.value_;
}
/// \brief Check for equality
bool operator ==(const this_type& i) const
{
return value_ == i.value_;
}
/// \brief Check for inequality
bool operator !=(const this_type& i) const
{
return value_ != i.value_;
}
/// \brief Check that this object is less than another
bool operator <(const this_type& i) const
{
return value_ < i.value_;
}
/// \brief Check that this object is greater than another
bool operator >(const this_type& i) const
{
return value_ > i.value_;
}
/// \brief Check this object is less than or equal to another
bool operator <=(const this_type& i) const
{
return value_ <= i.value_;
}
/// \brief Check this object is greater than or equal to another
bool operator >=(const this_type& i) const
{
return value_ >= i.value_;
}
private:
value_type value_;
};
/// \brief Insert a \c tiny_int into a C++ stream
template <typename VT>
std::ostream& operator <<(std::ostream& os, tiny_int<VT> i)
{
os << static_cast<int>(i);
return os;
}
} // end namespace mysqlpp
#endif
|