binary.h
説明を見る。
1 //
2 // Copyright (c) 2003-2011, MIST Project, Nagoya University
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the name of the Nagoya University nor the names of its contributors
16 // may be used to endorse or promote products derived from this software
17 // without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28 
33 
34 #ifndef __INCLUDE_MIST_BINARY_H__
35 #define __INCLUDE_MIST_BINARY_H__
36 
37 
38 #ifndef __INCLUDE_MIST_CONF_H__
39 #include "mist_conf.h"
40 #endif
41 
42 #include <iostream>
43 
44 // mist名前空間の始まり
46 
47 
48 // MISTで利用する基底のデータ型
49 
50 
57 class binary
58 {
59 public:
60  typedef size_t size_type;
61  typedef ptrdiff_t difference_type;
62  typedef bool& reference;
63  typedef const bool& const_reference;
64  typedef bool value_type;
65  typedef bool* pointer;
66  typedef const bool* const_pointer;
67 
68 private:
69  bool value_;
70 
71 public:
73  binary( ) : value_( false ){ }
74 
76  binary( const value_type &b ) : value_( b ){ }
77 
79  binary( const binary &b ) : value_( b.value_ ){ }
80 
81 
83  const binary &operator =( const binary &b ){ value_ = b.value_; return( *this ); }
84 
86  const binary &operator =( const value_type &b ){ value_ = b; return( *this ); }
87 
88 
101  const binary &operator +=( const binary &b ){ value_ = value_ || b.value_; return( *this ); }
102 
115  const binary &operator -=( const binary &b ){ value_ = value_ && !b.value_; return( *this ); }
116 
129  const binary &operator *=( const binary &b ){ value_ = value_ && b.value_; return( *this ); }
130 
143  const binary &operator /=( const binary &b ){ value_ = value_ == b.value_; return( *this ); }
144 
157  const binary &operator %=( const binary &b ){ value_ = value_ && !b.value_; return( *this ); }
158 
171  const binary &operator |=( const binary &b ){ value_ = value_ || b.value_; return( *this ); }
172 
185  const binary &operator &=( const binary &b ){ value_ = value_ && b.value_; return( *this ); }
186 
199  const binary &operator ^=( const binary &b ){ value_ = value_ != b.value_; return( *this ); }
200 
201 
203  const binary &operator +=( const value_type &b ){ return( operator +=( binary( b ) ) ); }
204 
206  const binary &operator -=( const value_type &b ){ return( operator -=( binary( b ) ) ); }
207 
209  const binary &operator *=( const value_type &b ){ return( operator *=( binary( b ) ) ); }
210 
212  const binary &operator /=( const value_type &b ){ return( operator /=( binary( b ) ) ); }
213 
214 
216  bool operator ==( const binary &b ) const { return( value_ == b.value_ ); }
217 
219  bool operator !=( const binary &b ) const { return( value_ != b.value_ ); }
220 
222  bool operator < ( const binary &b ) const { return( value_ < b.value_ ); }
223 
225  bool operator <=( const binary &b ) const { return( value_ <= b.value_ ); }
226 
228  bool operator > ( const binary &b ) const { return( value_ > b.value_ ); }
229 
231  bool operator >=( const binary &b ) const { return( value_ >= b.value_ ); }
232 
233 
235  value_type get_value( ) const { return( value_ ); }
236 
237  // boolへの自動キャスト演算子(危険のため一時停止)
238  //operator bool( ) const { return( value_ ); }
239 };
240 
241 
243 inline const binary operator +( const binary &b1, const binary &b2 ){ return( binary( b1 ) += b2 ); }
244 
246 inline const binary operator -( const binary &b1, const binary &b2 ){ return( binary( b1 ) -= b2 ); }
247 
249 inline const binary operator *( const binary &b1, const binary &b2 ){ return( binary( b1 ) *= b2 ); }
250 
252 inline const binary operator /( const binary &b1, const binary &b2 ){ return( binary( b1 ) /= b2 ); }
253 
255 inline const binary operator %( const binary &b1, const binary &b2 ){ return( binary( b1 ) %= b2 ); }
256 
258 inline const binary operator |( const binary &b1, const binary &b2 ){ return( binary( b1 ) |= b2 ); }
259 
261 inline const binary operator &( const binary &b1, const binary &b2 ){ return( binary( b1 ) &= b2 ); }
262 
264 inline const binary operator ^( const binary &b1, const binary &b2 ){ return( binary( b1 ) ^= b2 ); }
265 
266 
268 inline const binary operator *( const binary &b1, const binary::value_type &b2 ){ return( binary( b1 ) *= b2 ); }
269 
271 inline const binary operator *( const binary::value_type &b1, const binary &b2 ){ return( binary( b2 ) *= b1 ); }
272 
274 inline const binary operator /( const binary &b1, const binary::value_type &b2 ){ return( binary( b1 ) /= b2 ); }
275 
276 
278 inline const binary operator +( const binary &b1, const binary::value_type &b2 ){ return( binary( b1 ) += b2 ); }
279 
281 inline const binary operator +( const binary::value_type &b1, const binary &b2 ){ return( binary( b2 ) += b1 ); }
282 
284 inline const binary operator -( const binary &b1, const binary::value_type &b2 ){ return( binary( b1 ) -= b2 ); }
285 
287 inline const binary operator -( const binary::value_type &b1, const binary &b2 ){ return( binary( b1 ) -= b2 ); }
288 
289 
290 
302 inline std::ostream &operator <<( std::ostream &out, const binary &b )
303 {
304  out << b.get_value( );
305  return( out );
306 }
307 
308 
309 // mist名前空間の終わり
310 _MIST_END
311 
312 
313 #endif // __INCLUDE_MIST_BINARY_H__
314 

Generated on Wed Nov 12 2014 19:44:13 for MIST by doxygen 1.8.1.2