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