MySQL++ Reference Manual

MySQL++: tiny_int.h Source File

MySQL++ 3.3.0

tiny_int.h
Go to the documentation of this file.
1
4 /***********************************************************************
5 Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
6 (c) 2004-2007 by Educational Technology Resources, Inc. Others may
7 also hold copyrights on code in this file. See the CREDITS.txt file
8 in the top directory of the distribution for details.
9
10 This file is part of MySQL++.
11
12 MySQL++ is free software; you can redistribute it and/or modify it
13 under the terms of the GNU Lesser General Public License as published
14 by the Free Software Foundation; either version 2.1 of the License, or
15 (at your option) any later version.
16
17 MySQL++ is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20 License for more details.
21
22 You should have received a copy of the GNU Lesser General Public
23 License along with MySQL++; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25 USA
26 ***********************************************************************/
27
28 #if !defined(MYSQLPP_TINY_INT_H)
29 #define MYSQLPP_TINY_INT_H
30
31 #include "common.h"
32
33 #include <ostream>
34
35 namespace mysqlpp {
36
53
54 template <typename VT = signed char>
55 class tiny_int
56 {
57 public:
59 typedef tiny_int<VT> this_type;
60 typedef VT value_type;
61
65 tiny_int() { }
66
69 tiny_int(value_type v) :
70 value_(value_type(v))
71 {
72 }
73
75 operator bool() const
76 {
77 return value_;
78 }
79
81 operator int() const
82 {
83 return static_cast<int>(value_);
84 }
85
87 operator value_type() const
88 {
89 return value_;
90 }
91
93 this_type& operator =(int v)
94 {
95 value_ = static_cast<value_type>(v);
96 return *this;
97 }
98
100 this_type& operator +=(int v)
101 {
102 value_ += static_cast<value_type>(v);
103 return *this;
104 }
105
107 this_type& operator -=(int v)
108 {
109 value_ -= static_cast<value_type>(v);
110 return *this;
111 }
112
114 this_type& operator *=(int v)
115 {
116 value_ *= static_cast<value_type>(v);
117 return *this;
118 }
119
121 this_type& operator /=(int v)
122 {
123 value_ /= static_cast<value_type>(v);
124 return *this;
125 }
126
129 this_type& operator %=(int v)
130 {
131 value_ %= static_cast<value_type>(v);
132 return *this;
133 }
134
136 this_type& operator &=(int v)
137 {
138 value_ &= static_cast<value_type>(v);
139 return *this;
140 }
141
143 this_type& operator |=(int v)
144 {
145 value_ |= static_cast<value_type>(v);
146 return *this;
147 }
148
150 this_type& operator ^=(int v)
151 {
152 value_ ^= static_cast<value_type>(v);
153 return *this;
154 }
155
157 this_type& operator <<=(int v)
158 {
159 value_ <<= static_cast<value_type>(v);
160 return *this;
161 }
162
164 this_type& operator >>=(int v)
165 {
166 value_ >>= static_cast<value_type>(v);
167 return *this;
168 }
169
171 this_type& operator ++()
172 {
173 ++value_;
174 return *this;
175 }
176
178 this_type& operator --()
179 {
180 --value_;
181 return *this;
182 }
183
185 this_type operator ++(int)
186 {
187 this_type tmp = value_;
188 ++value_;
189 return tmp;
190 }
191
194 this_type operator --(int)
195 {
196 this_type tmp = value_;
197 --value_;
198 return tmp;
199 }
200
202 this_type operator -(const this_type& i) const
203 {
204 return value_ - i.value_;
205 }
206
208 this_type operator +(const this_type& i) const
209 {
210 return value_ + i.value_;
211 }
212
214 this_type operator *(const this_type& i) const
215 {
216 return value_ * i.value_;
217 }
218
220 this_type operator /(const this_type& i) const
221 {
222 return value_ / i.value_;
223 }
224
226 this_type operator %(const this_type& i) const
227 {
228 return value_ % i.value_;
229 }
230
232 this_type operator |(const this_type& i) const
233 {
234 return value_ | i.value_;
235 }
236
238 this_type operator &(const this_type& i) const
239 {
240 return value_ & i.value_;
241 }
242
244 this_type operator ^(const this_type& i) const
245 {
246 return value_ ^ i.value_;
247 }
248
250 this_type operator <<(const this_type& i) const
251 {
252 return value_ << i.value_;
253 }
254
256 this_type operator >>(const this_type& i) const
257 {
258 return value_ >> i.value_;
259 }
260
262 bool operator ==(const this_type& i) const
263 {
264 return value_ == i.value_;
265 }
266
268 bool operator !=(const this_type& i) const
269 {
270 return value_ != i.value_;
271 }
272
274 bool operator <(const this_type& i) const
275 {
276 return value_ < i.value_;
277 }
278
280 bool operator >(const this_type& i) const
281 {
282 return value_ > i.value_;
283 }
284
286 bool operator <=(const this_type& i) const
287 {
288 return value_ <= i.value_;
289 }
290
292 bool operator >=(const this_type& i) const
293 {
294 return value_ >= i.value_;
295 }
296
297 private:
298 value_type value_;
299 };
300
302 template <typename VT>
303 std::ostream& operator <<(std::ostream& os, tiny_int<VT> i)
304 {
305 os << static_cast<int>(i);
306 return os;
307 }
308
309 } // end namespace mysqlpp
310
311 #endif
mysqlpp::tiny_int
Class for holding an SQL TINYINT value.
Definition: tiny_int.h:56
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 plus i.
Definition: tiny_int.h:208
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>
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)
Shift this value right by v positions.
Definition: tiny_int.h:164
mysqlpp::tiny_int::operator/=
this_type & operator/=(int v)
Divide this value by another object.
Definition: tiny_int.h:121
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<<=(int v)
Shift this value left by v positions.
Definition: tiny_int.h:157
mysqlpp::tiny_int::tiny_int
tiny_int()
Default constructor.
Definition: tiny_int.h:65
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+=
this_type & operator+=(int v)
Add another value to this object.
Definition: tiny_int.h:100
mysqlpp::tiny_int::value_type
VT value_type
alias for type of internal value
Definition: tiny_int.h:60
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 bitwise OR'd by i.
Definition: tiny_int.h:232
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 this value minus i.
Definition: tiny_int.h:202
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--
this_type & operator--()
Subtract one from this value and return that value.
Definition: tiny_int.h:178
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==
bool operator==(const this_type &i) const
Check for equality.
Definition: tiny_int.h:262
mysqlpp::tiny_int::this_type
tiny_int< VT > this_type
alias for this object's type
Definition: tiny_int.h:59
mysqlpp::tiny_int::operator!=
bool operator!=(const this_type &i) const
Check for inequality.
Definition: tiny_int.h:268
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>>(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%=(int v)
Divide this value by another object and store the remainder.
Definition: tiny_int.h:129
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'd by i.
Definition: tiny_int.h:238
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=(int v)
Assign a new value to the object.
Definition: tiny_int.h:93
mysqlpp::tiny_int::operator^
this_type operator^(const this_type &i) const
Return this value bitwise XOR'd by i.
Definition: tiny_int.h:244
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%(const this_type &i) const
Return the modulus of this value divided by i.
Definition: tiny_int.h:226
mysqlpp::tiny_int::operator^=
this_type & operator^=(int v)
Bitwise XOR this value by another value.
Definition: tiny_int.h:150
common.h
This file includes top-level definitions for use both internal to the library, and outside it....