Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ubyte.hh
Go to the documentation of this file.
1 #ifndef INCLUDED_ObjexxFCL_ubyte_hh
2 #define INCLUDED_ObjexxFCL_ubyte_hh
3 
4 
5 // ubyte: Unsigned One-Byte Integer
6 //
7 // Project: Objexx Fortran Compatibility Library (ObjexxFCL)
8 //
9 // Version: 3.0.0
10 //
11 // Language: C++
12 //
13 // Copyright (c) 2000-2009 Objexx Engineering, Inc. All Rights Reserved.
14 // Use of this source code or any derivative of it is restricted by license.
15 // Licensing is available from Objexx Engineering, Inc.: http://objexx.com Objexx@objexx.com
16 
17 
18 // ObjexxFCL Headers
19 #include <ObjexxFCL/ubyte.fwd.hh>
20 
21 // C++ Headers
22 #include <cassert>
23 #include <cstddef>
24 #include <istream>
25 
26 
27 namespace ObjexxFCL {
28 
29 
30 /// @brief ubyte: One-Byte Integer
31 class ubyte
32 {
33 
34 
35 public: // Creation
36 
37 
38  /// @brief Default Constructor
39  inline
40  ubyte() :
41  b_( 0 )
42  {}
43 
44 
45  /// @brief Constructor
46  inline
47  explicit
48  ubyte( unsigned short int const i ) :
49  b_( i )
50  {}
51 
52 
53  /// @brief Destructor
54  inline
56  {}
57 
58 
59 public: // Conversion
60 
61 
62  /// @brief short Conversion
63  inline
64  operator unsigned short int() const
65  {
66  return static_cast< unsigned short int >( b_ );
67  }
68 
69 
70 public: // Assignment
71 
72 
73  /// @brief = short
74  inline
75  ubyte &
76  operator =( unsigned short int const i )
77  {
78  b_ = i;
79  return *this;
80  }
81 
82 
83  /// @brief += short
84  inline
85  ubyte &
86  operator +=( unsigned short int const i )
87  {
88  b_ += i;
89  return *this;
90  }
91 
92 
93  /// @brief -= short
94  inline
95  ubyte &
96  operator -=( unsigned short int const i )
97  {
98  b_ -= i;
99  return *this;
100  }
101 
102 
103  /// @brief *= short
104  inline
105  ubyte &
106  operator *=( unsigned short int const i )
107  {
108  b_ *= i;
109  return *this;
110  }
111 
112 
113  /// @brief /= short
114  inline
115  ubyte &
116  operator /=( unsigned short int const i )
117  {
118  assert( i != 0 );
119  b_ /= i;
120  return *this;
121  }
122 
123 
124 public: // Incrememt/Decrement
125 
126 
127  /// @brief ++ubyte
128  inline
129  ubyte &
131  {
132  ++b_;
133  return *this;
134  }
135 
136 
137  /// @brief ubyte++
138  inline
139  ubyte const
140  operator ++( int )
141  {
142  ubyte const old( *this );
143  ++b_;
144  return old;
145  }
146 
147 
148  /// @brief --ubyte
149  inline
150  ubyte &
152  {
153  --b_;
154  return *this;
155  }
156 
157 
158  /// @brief ubyte--
159  inline
160  ubyte const
161  operator --( int )
162  {
163  ubyte const old( *this );
164  --b_;
165  return old;
166  }
167 
168 
169 public: // Math
170 
171 
172  /// @brief +ubyte
173  inline
174  ubyte
175  operator +() const
176  {
177  return *this;
178  }
179 
180 
181  /// @brief -ubyte
182  inline
183  ubyte
184  operator -() const
185  {
186  return ubyte( -static_cast< unsigned short int >( b_ ) );
187  }
188 
189 
190  /// @brief ubyte + ubyte
191  friend
192  inline
193  ubyte
194  operator +( ubyte const & i, ubyte const & j )
195  {
196  return ubyte( i.b_ + j.b_ );
197  }
198 
199 
200  /// @brief ubyte - ubyte
201  friend
202  inline
203  ubyte
204  operator -( ubyte const & i, ubyte const & j )
205  {
206  return ubyte( i.b_ - j.b_ );
207  }
208 
209 
210  /// @brief ubyte * ubyte
211  friend
212  inline
213  ubyte
214  operator *( ubyte const & i, ubyte const & j )
215  {
216  return ubyte( i.b_ * j.b_ );
217  }
218 
219 
220  /// @brief ubyte / ubyte
221  friend
222  inline
223  ubyte
224  operator /( ubyte const & i, ubyte const & j )
225  {
226  assert( j.b_ != 0 );
227  return ubyte( i.b_ / j.b_ );
228  }
229 
230 
231 public: // Bitwise Logical
232 
233 
234  /// @brief ~ubyte
235  inline
236  ubyte
237  operator ~() const
238  {
239  return ubyte( ~b_ );
240  }
241 
242 
243  /// @brief ubyte >> std::size_t
244  inline
245  ubyte
246  operator >>( std::size_t const n ) const
247  {
248  return ubyte( b_ >> n );
249  }
250 
251 
252  /// @brief ubyte >> ubyte
253  inline
254  ubyte
255  operator >>( ubyte const n ) const
256  {
257  return ubyte( b_ >> static_cast< unsigned short int >( n ) );
258  }
259 
260 
261  /// @brief ubyte << std::size_t
262  inline
263  ubyte
264  operator <<( std::size_t const n ) const
265  {
266  return ubyte( b_ << n );
267  }
268 
269 
270  /// @brief ubyte << ubyte
271  inline
272  ubyte
273  operator <<( ubyte const n ) const
274  {
275  return ubyte( b_ << static_cast< unsigned short int >( n ) );
276  }
277 
278 
279  /// @brief &= ubyte
280  inline
281  ubyte &
282  operator &=( ubyte const & i )
283  {
284  b_ &= i.b_;
285  return *this;
286  }
287 
288 
289  /// @brief |= ubyte
290  inline
291  ubyte &
292  operator |=( ubyte const & i )
293  {
294  b_ |= i.b_;
295  return *this;
296  }
297 
298 
299  /// @brief ^= ubyte
300  inline
301  ubyte &
302  operator ^=( ubyte const & i )
303  {
304  b_ ^= i.b_;
305  return *this;
306  }
307 
308 
309  /// @brief ubyte & ubyte
310  friend
311  inline
312  ubyte
313  operator &( ubyte const & i, ubyte const & j )
314  {
315  return ubyte( i.b_ & j.b_ );
316  }
317 
318 
319  /// @brief ubyte | ubyte
320  friend
321  inline
322  ubyte
323  operator |( ubyte const & i, ubyte const & j )
324  {
325  return ubyte( i.b_ | j.b_ );
326  }
327 
328 
329  /// @brief ubyte ^ ubyte
330  friend
331  inline
332  ubyte
333  operator ^( ubyte const & i, ubyte const & j )
334  {
335  return ubyte( i.b_ ^ j.b_ );
336  }
337 
338 
339 public: // Comparison
340 
341 
342  /// @brief ubyte == ubyte
343  friend
344  inline
345  bool
346  operator ==( ubyte const & i, ubyte const & j )
347  {
348  return ( i.b_ == j.b_ );
349  }
350 
351 
352  /// @brief ubyte != ubyte
353  friend
354  inline
355  bool
356  operator !=( ubyte const & i, ubyte const & j )
357  {
358  return ( i.b_ != j.b_ );
359  }
360 
361 
362  /// @brief ubyte < ubyte
363  friend
364  inline
365  bool
366  operator <( ubyte const & i, ubyte const & j )
367  {
368  return ( i.b_ < j.b_ );
369  }
370 
371 
372  /// @brief ubyte <= ubyte
373  friend
374  inline
375  bool
376  operator <=( ubyte const & i, ubyte const & j )
377  {
378  return ( i.b_ <= j.b_ );
379  }
380 
381 
382  /// @brief ubyte > ubyte
383  friend
384  inline
385  bool
386  operator >( ubyte const & i, ubyte const & j )
387  {
388  return ( i.b_ > j.b_ );
389  }
390 
391 
392  /// @brief ubyte >= ubyte
393  friend
394  inline
395  bool
396  operator >=( ubyte const & i, ubyte const & j )
397  {
398  return ( i.b_ >= j.b_ );
399  }
400 
401 
402 public: // I/O
403 
404 
405  /// @brief Stream Input
406  friend
407  inline
408  std::istream &
409  operator >>( std::istream & stream, ubyte & b )
410  {
411  if ( stream ) {
412  unsigned short int s;
413  stream >> s;
414  b.b_ = s;
415  }
416  return stream;
417  }
418 
419 
420 private: // Data
421 
422 
423  /// @brief Value
424  unsigned char b_;
425 
426 
427 }; // ubyte
428 
429 
430 /// @brief ubyte + ubyte
431 #ifndef __clang__
432 ubyte
433 operator +( ubyte const & i, ubyte const & j );
434 #endif
435 
436 
437 /// @brief ubyte - ubyte
438 ubyte
439 operator -( ubyte const & i, ubyte const & j );
440 
441 
442 /// @brief ubyte * ubyte
443 ubyte
444 operator *( ubyte const & i, ubyte const & j );
445 
446 
447 /// @brief ubyte / ubyte
448 ubyte
449 operator /( ubyte const & i, ubyte const & j );
450 
451 
452 /// @brief ubyte & ubyte
453 #ifndef __clang__
454 ubyte
455 operator &( ubyte const & i, ubyte const & j );
456 #endif
457 
458 
459 /// @brief ubyte | ubyte
460 #ifndef __clang__
461 ubyte
462 operator |( ubyte const & i, ubyte const & j );
463 #endif
464 
465 
466 /// @brief ubyte ^ ubyte
467 ubyte
468 operator ^( ubyte const & i, ubyte const & j );
469 
470 
471 /// @brief ubyte == ubyte
472 bool
473 operator ==( ubyte const & i, ubyte const & j );
474 
475 
476 /// @brief ubyte != ubyte
477 bool
478 operator !=( ubyte const & i, ubyte const & j );
479 
480 
481 /// @brief ubyte < ubyte
482 bool
483 operator <( ubyte const & i, ubyte const & j );
484 
485 
486 /// @brief ubyte <= ubyte
487 bool
488 operator <=( ubyte const & i, ubyte const & j );
489 
490 
491 /// @brief ubyte > ubyte
492 bool
493 operator >( ubyte const & i, ubyte const & j );
494 
495 
496 /// @brief ubyte >= ubyte
497 bool
498 operator >=( ubyte const & i, ubyte const & j );
499 
500 
501 /// @brief Stream Input
502 #ifndef __clang__
503 std::istream &
504 operator >>( std::istream & stream, ubyte & b );
505 #endif
506 
507 
508 } // namespace ObjexxFCL
509 
510 
511 #endif // INCLUDED_ObjexxFCL_ubyte_HH
std::istream & operator>>(std::istream &stream, byte &b)
Stream Input.
Definition: byte.hh:409
friend ubyte operator|(ubyte const &i, ubyte const &j)
ubyte | ubyte
Definition: ubyte.hh:323
friend bool operator==(ubyte const &i, ubyte const &j)
ubyte == ubyte
Definition: ubyte.hh:346
ubyte(unsigned short int const i)
Constructor.
Definition: ubyte.hh:48
bool operator!=(byte const &i, byte const &j)
byte != byte
Definition: byte.hh:356
friend bool operator<(ubyte const &i, ubyte const &j)
ubyte < ubyte
Definition: ubyte.hh:366
friend bool operator>=(ubyte const &i, ubyte const &j)
ubyte >= ubyte
Definition: ubyte.hh:396
bool operator>=(byte const &i, byte const &j)
byte >= byte
Definition: byte.hh:396
byte operator&(byte const &i, byte const &j)
byte & byte
Definition: byte.hh:313
ubyte & operator/=(unsigned short int const i)
/= short
Definition: ubyte.hh:116
friend bool operator<=(ubyte const &i, ubyte const &j)
ubyte <= ubyte
Definition: ubyte.hh:376
ubyte & operator-=(unsigned short int const i)
-= short
Definition: ubyte.hh:96
ubyte: One-Byte Integer
Definition: ubyte.hh:31
bool operator<=(byte const &i, byte const &j)
byte <= byte
Definition: byte.hh:376
ubyte operator~() const
~ubyte
Definition: ubyte.hh:237
byte operator-(byte const &i, byte const &j)
byte - byte
Definition: byte.hh:204
ubyte & operator--()
–ubyte
Definition: ubyte.hh:151
~ubyte()
Destructor.
Definition: ubyte.hh:55
ubyte operator+() const
+ubyte
Definition: ubyte.hh:175
ubyte operator<<(std::size_t const n) const
ubyte << std::size_t
Definition: ubyte.hh:264
byte operator+(byte const &i, byte const &j)
byte + byte
Definition: byte.hh:194
friend ubyte operator*(ubyte const &i, ubyte const &j)
ubyte * ubyte
Definition: ubyte.hh:214
byte operator^(byte const &i, byte const &j)
byte ^ byte
Definition: byte.hh:333
friend bool operator>(ubyte const &i, ubyte const &j)
ubyte > ubyte
Definition: ubyte.hh:386
ubyte & operator++()
++ubyte
Definition: ubyte.hh:130
ubyte & operator|=(ubyte const &i)
|= ubyte
Definition: ubyte.hh:292
ubyte & operator^=(ubyte const &i)
^= ubyte
Definition: ubyte.hh:302
friend ubyte operator&(ubyte const &i, ubyte const &j)
ubyte & ubyte
Definition: ubyte.hh:313
ubyte & operator*=(unsigned short int const i)
*= short
Definition: ubyte.hh:106
byte operator|(byte const &i, byte const &j)
byte | byte
Definition: byte.hh:323
bool operator>(byte const &i, byte const &j)
byte > byte
Definition: byte.hh:386
ubyte()
Default Constructor.
Definition: ubyte.hh:40
ubyte & operator+=(unsigned short int const i)
+= short
Definition: ubyte.hh:86
ubyte & operator&=(ubyte const &i)
&= ubyte
Definition: ubyte.hh:282
bool operator<(byte const &i, byte const &j)
byte < byte
Definition: byte.hh:366
friend ubyte operator^(ubyte const &i, ubyte const &j)
ubyte ^ ubyte
Definition: ubyte.hh:333
byte operator*(byte const &i, byte const &j)
byte * byte
Definition: byte.hh:214
friend bool operator!=(ubyte const &i, ubyte const &j)
ubyte != ubyte
Definition: ubyte.hh:356
bool operator==(byte const &i, byte const &j)
byte == byte
Definition: byte.hh:346
friend ubyte operator/(ubyte const &i, ubyte const &j)
ubyte / ubyte
Definition: ubyte.hh:224
ubyte operator-() const
-ubyte
Definition: ubyte.hh:184
ubyte operator>>(std::size_t const n) const
ubyte >> std::size_t
Definition: ubyte.hh:246
ubyte & operator=(unsigned short int const i)
= short
Definition: ubyte.hh:76
byte operator/(byte const &i, byte const &j)
byte / byte
Definition: byte.hh:224
unsigned char b_
Value.
Definition: ubyte.hh:424