MySQL++ Reference Manual

- Main Page
- Classes
- Files

- File List
- File Members

# tiny_int.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004 /***********************************************************************
    00005  Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
    00006  (c) 2004-2007 by Educational Technology Resources, Inc.  Others may
    00007  also hold copyrights on code in this file.  See the CREDITS.txt file
    00008  in the top directory of the distribution for details.
    00009
    00010  This file is part of MySQL++.
    00011
    00012  MySQL++ is free software; you can redistribute it and/or modify it
    00013  under the terms of the GNU Lesser General Public License as published
    00014  by the Free Software Foundation; either version 2.1 of the License, or
    00015  (at your option) any later version.
    00016
    00017  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00018  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00019  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00020  License for more details.
    00021
    00022  You should have received a copy of the GNU Lesser General Public
    00023  License along with MySQL++; if not, write to the Free Software
    00024  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00025  USA
    00026 ***********************************************************************/
    00027
    00028 #if !defined(MYSQLPP_TINY_INT_H)
    00029 #define MYSQLPP_TINY_INT_H
    00030
    00031 #include "common.h"
    00032
    00033 #include <ostream>
    00034
    00035 namespace mysqlpp {
    00036
    00053
    00054 template <typename VT = signed char>
    00055 class tiny_int
    00056 {
    00057 public:
    00059         typedef tiny_int<VT> this_type;
    00060         typedef VT value_type;
    00061
    00065         tiny_int() { }
    00066
    00069         tiny_int(value_type v) :
    00070         value_(value_type(v))
    00071         {
    00072         }
    00073
    00075         operator bool() const
    00076         {
    00077                 return value_;
    00078         }
    00079
    00081         operator int() const
    00082         {
    00083                 return static_cast<int>(value_);
    00084         }
    00085
    00087         operator value_type() const
    00088         {
    00089                 return value_;
    00090         }
    00091
    00093         this_type& operator =(int v)
    00094         {
    00095                 value_ = static_cast<value_type>(v);
    00096                 return *this;
    00097         }
    00098
    00100         this_type& operator +=(int v)
    00101         {
    00102                 value_ += static_cast<value_type>(v);
    00103                 return *this;
    00104         }
    00105
    00107         this_type& operator -=(int v)
    00108         {
    00109                 value_ -= static_cast<value_type>(v);
    00110                 return *this;
    00111         }
    00112
    00114         this_type& operator *=(int v)
    00115         {
    00116                 value_ *= static_cast<value_type>(v);
    00117                 return *this;
    00118         }
    00119
    00121         this_type& operator /=(int v)
    00122         {
    00123                 value_ /= static_cast<value_type>(v);
    00124                 return *this;
    00125         }
    00126
    00129         this_type& operator %=(int v)
    00130         {
    00131                 value_ %= static_cast<value_type>(v);
    00132                 return *this;
    00133         }
    00134
    00136         this_type& operator &=(int v)
    00137         {
    00138                 value_ &= static_cast<value_type>(v);
    00139                 return *this;
    00140         }
    00141
    00143         this_type& operator |=(int v)
    00144         {
    00145                 value_ |= static_cast<value_type>(v);
    00146                 return *this;
    00147         }
    00148
    00150         this_type& operator ^=(int v)
    00151         {
    00152                 value_ ^= static_cast<value_type>(v);
    00153                 return *this;
    00154         }
    00155
    00157         this_type& operator <<=(int v)
    00158         {
    00159                 value_ <<= static_cast<value_type>(v);
    00160                 return *this;
    00161         }
    00162
    00164         this_type& operator >>=(int v)
    00165         {
    00166                 value_ >>= static_cast<value_type>(v);
    00167                 return *this;
    00168         }
    00169
    00171         this_type& operator ++()
    00172         {
    00173                 ++value_;
    00174                 return *this;
    00175         }
    00176
    00178         this_type& operator --()
    00179         {
    00180                 --value_;
    00181                 return *this;
    00182         }
    00183
    00185         this_type operator ++(int)
    00186         {
    00187                 this_type tmp = value_;
    00188                 ++value_;
    00189                 return tmp;
    00190         }
    00191
    00194         this_type operator --(int)
    00195         {
    00196                 this_type tmp = value_;
    00197                 --value_;
    00198                 return tmp;
    00199         }
    00200
    00202         this_type operator -(const this_type& i) const
    00203         {
    00204                 return value_ - i.value_;
    00205         }
    00206
    00208         this_type operator +(const this_type& i) const
    00209         {
    00210                 return value_ + i.value_;
    00211         }
    00212
    00214         this_type operator *(const this_type& i) const
    00215         {
    00216                 return value_ * i.value_;
    00217         }
    00218
    00220         this_type operator /(const this_type& i) const
    00221         {
    00222                 return value_ / i.value_;
    00223         }
    00224
    00226         this_type operator %(const this_type& i) const
    00227         {
    00228                 return value_ % i.value_;
    00229         }
    00230
    00232         this_type operator |(const this_type& i) const
    00233         {
    00234                 return value_ | i.value_;
    00235         }
    00236
    00238         this_type operator &(const this_type& i) const
    00239         {
    00240                 return value_ & i.value_;
    00241         }
    00242
    00244         this_type operator ^(const this_type& i) const
    00245         {
    00246                 return value_ ^ i.value_;
    00247         }
    00248
    00250         this_type operator <<(const this_type& i) const
    00251         {
    00252                 return value_ << i.value_;
    00253         }
    00254
    00256         this_type operator >>(const this_type& i) const
    00257         {
    00258                 return value_ >> i.value_;
    00259         }
    00260
    00261 private:
    00262         value_type value_;
    00263 };
    00264
    00266 template <typename VT>
    00267 std::ostream& operator <<(std::ostream& os, tiny_int<VT> i)
    00268 {
    00269         os << static_cast<int>(i);
    00270         return os;
    00271 }
    00272
    00273 } // end namespace mysqlpp
    00274
    00275 #endif