tiny_int.h
Go to the documentation of this file.
/***********************************************************************
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 {
template <typename VT = signed char>
class tiny_int
{
public:
typedef tiny_int<VT> this_type;
typedef VT value_type;
tiny_int() { }
tiny_int(value_type v) :
value_(value_type(v))
{
}
operator bool() const
{
return value_;
}
operator int() const
{
return static_cast<int>(value_);
}
operator value_type() const
{
return value_;
}
this_type& operator =(int v)
{
value_ = static_cast<value_type>(v);
return *this;
}
this_type& operator +=(int v)
{
value_ += static_cast<value_type>(v);
return *this;
}
this_type& operator -=(int v)
{
value_ -= static_cast<value_type>(v);
return *this;
}
this_type& operator *=(int v)
{
value_ *= static_cast<value_type>(v);
return *this;
}
this_type& operator /=(int v)
{
value_ /= static_cast<value_type>(v);
return *this;
}
this_type& operator %=(int v)
{
value_ %= static_cast<value_type>(v);
return *this;
}
this_type& operator &=(int v)
{
value_ &= static_cast<value_type>(v);
return *this;
}
this_type& operator |=(int v)
{
value_ |= static_cast<value_type>(v);
return *this;
}
this_type& operator ^=(int v)
{
value_ ^= static_cast<value_type>(v);
return *this;
}
this_type& operator <<=(int v)
{
value_ <<= static_cast<value_type>(v);
return *this;
}
this_type& operator >>=(int v)
{
value_ >>= static_cast<value_type>(v);
return *this;
}
this_type& operator ++()
{
++value_;
return *this;
}
this_type& operator --()
{
--value_;
return *this;
}
this_type operator ++(int)
{
this_type tmp = value_;
++value_;
return tmp;
}
this_type operator --(int)
{
this_type tmp = value_;
--value_;
return tmp;
}
this_type operator -(const this_type& i) const
{
return value_ - i.value_;
}
this_type operator +(const this_type& i) const
{
return value_ + i.value_;
}
this_type operator *(const this_type& i) const
{
return value_ * i.value_;
}
this_type operator /(const this_type& i) const
{
return value_ / i.value_;
}
this_type operator %(const this_type& i) const
{
return value_ % i.value_;
}
this_type operator |(const this_type& i) const
{
return value_ | i.value_;
}
this_type operator &(const this_type& i) const
{
return value_ & i.value_;
}
this_type operator ^(const this_type& i) const
{
return value_ ^ i.value_;
}
this_type operator <<(const this_type& i) const
{
return value_ << i.value_;
}
this_type operator >>(const this_type& i) const
{
return value_ >> i.value_;
}
bool operator ==(const this_type& i) const
{
return value_ == i.value_;
}
bool operator !=(const this_type& i) const
{
return value_ != i.value_;
}
bool operator <(const this_type& i) const
{
return value_ < i.value_;
}
bool operator >(const this_type& i) const
{
return value_ > i.value_;
}
bool operator <=(const this_type& i) const
{
return value_ <= i.value_;
}
bool operator >=(const this_type& i) const
{
return value_ >= i.value_;
}
private:
value_type value_;
};
template <typename VT>
std::ostream& operator <<(std::ostream& os, tiny_int<VT> i)
{
os << static_cast<int>(i);
return os;
}
} // end namespace mysqlpp
#endif
mysqlpp::tiny_int::operator|=
this_type & operator|=(int v)
Bitwise OR this value by another value.
Definition: tiny_int.h:143
mysqlpp::tiny_int::operator<<=
this_type & operator<<=(int v)
Shift this value left by v positions.
Definition: tiny_int.h:157
mysqlpp::tiny_int::operator|
this_type operator|(const this_type &i) const
Return this value bitwise OR&#39;d by i.
Definition: tiny_int.h:232
mysqlpp::tiny_int::operator&=
this_type & operator&=(int v)
Bitwise AND this value by another value.
Definition: tiny_int.h:136
mysqlpp::tiny_int::operator*
this_type operator*(const this_type &i) const
Return this value multiplied by i.
Definition: tiny_int.h:214
mysqlpp::tiny_int::operator<=
bool operator<=(const this_type &i) const
Check this object is less than or equal to another.
Definition: tiny_int.h:286
mysqlpp::tiny_int::operator%
this_type operator%(const this_type &i) const
Return the modulus of this value divided by i.
Definition: tiny_int.h:226
mysqlpp::tiny_int::operator!=
bool operator!=(const this_type &i) const
Check for inequality.
Definition: tiny_int.h:268
mysqlpp::tiny_int::operator<
bool operator<(const this_type &i) const
Check that this object is less than another.
Definition: tiny_int.h:274
mysqlpp::tiny_int::operator==
bool operator==(const this_type &i) const
Check for equality.
Definition: tiny_int.h:262
mysqlpp::tiny_int::operator%=
this_type & operator%=(int v)
Divide this value by another object and store the remainder.
Definition: tiny_int.h:129
mysqlpp::tiny_int::tiny_int
tiny_int(value_type v)
Create object from any integral type that can be converted to a short int.
Definition: tiny_int.h:69
mysqlpp::tiny_int::operator+
this_type operator+(const this_type &i) const
Return this value plus i.
Definition: tiny_int.h:208
mysqlpp::tiny_int::operator^=
this_type & operator^=(int v)
Bitwise XOR this value by another value.
Definition: tiny_int.h:150
mysqlpp::tiny_int::this_type
tiny_int< VT > this_type
alias for this object&#39;s type
Definition: tiny_int.h:59
mysqlpp::tiny_int::operator<<
this_type operator<<(const this_type &i) const
Return this value bitwise shifted left by i.
Definition: tiny_int.h:250
mysqlpp::tiny_int::operator^
this_type operator^(const this_type &i) const
Return this value bitwise XOR&#39;d by i.
Definition: tiny_int.h:244
mysqlpp::tiny_int::operator--
this_type & operator--()
Subtract one from this value and return that value.
Definition: tiny_int.h:178
mysqlpp::tiny_int
Class for holding an SQL TINYINT value.
Definition: tiny_int.h:55
mysqlpp::tiny_int::operator=
this_type & operator=(int v)
Assign a new value to the object.
Definition: tiny_int.h:93
mysqlpp::tiny_int::operator>
bool operator>(const this_type &i) const
Check that this object is greater than another.
Definition: tiny_int.h:280
mysqlpp::tiny_int::operator*=
this_type & operator*=(int v)
Multiply this value by another object.
Definition: tiny_int.h:114
mysqlpp::tiny_int::operator/=
this_type & operator/=(int v)
Divide this value by another object.
Definition: tiny_int.h:121
mysqlpp::tiny_int::tiny_int
tiny_int()
Default constructor.
Definition: tiny_int.h:65
mysqlpp::tiny_int::operator>>=
this_type & operator>>=(int v)
Shift this value right by v positions.
Definition: tiny_int.h:164
mysqlpp::tiny_int::operator-=
this_type & operator-=(int v)
Subtract another value to this object.
Definition: tiny_int.h:107
mysqlpp::tiny_int::operator+=
this_type & operator+=(int v)
Add another value to this object.
Definition: tiny_int.h:100
mysqlpp::tiny_int::operator>>
this_type operator>>(const this_type &i) const
Return this value bitwise shifted right by i.
Definition: tiny_int.h:256
mysqlpp::tiny_int::operator-
this_type operator-(const this_type &i) const
Return this value minus i.
Definition: tiny_int.h:202
common.h
This file includes top-level definitions for use both internal to the library, and outside it...
mysqlpp::tiny_int::value_type
VT value_type
alias for type of internal value
Definition: tiny_int.h:60
mysqlpp::tiny_int::operator>=
bool operator>=(const this_type &i) const
Check this object is greater than or equal to another.
Definition: tiny_int.h:292
mysqlpp::tiny_int::operator/
this_type operator/(const this_type &i) const
Return this value divided by i.
Definition: tiny_int.h:220
mysqlpp::tiny_int::operator++
this_type & operator++()
Add one to this value and return that value.
Definition: tiny_int.h:171
mysqlpp::tiny_int::operator&
this_type operator&(const this_type &i) const
Return this value bitwise AND&#39;d by i.
Definition: tiny_int.h:238