UnsignedValue.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_UTIL_UNSIGNEDVALUE_H_
36 #define _BLAZE_UTIL_UNSIGNEDVALUE_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iosfwd>
45 
46 
47 namespace blaze {
48 
49 //=================================================================================================
50 //
51 // CLASS DEFINITION
52 //
53 //=================================================================================================
54 
55 //*************************************************************************************************
62 template< typename T > // Type of the unsigned value
64 {
65  public:
66  //**Constructors********************************************************************************
69  explicit inline UnsignedValue( T value=0 );
70  // No explicitly declared copy constructor.
72  //**********************************************************************************************
73 
74  //**Destructor**********************************************************************************
75  // No explicitly declared destructor.
76  //**********************************************************************************************
77 
78  //**Assignment operator*************************************************************************
81  inline UnsignedValue& operator=( T value );
82  // No explicitly declared copy assignment operator.
84  //**********************************************************************************************
85 
86  //**Conversion operator*************************************************************************
89  inline operator T() const;
91  //**********************************************************************************************
92 
93  //**Access function*****************************************************************************
96  inline T get() const;
98  //**********************************************************************************************
99 
100  private:
101  //**Member variables****************************************************************************
104  T value_;
105 
106  //**********************************************************************************************
107 
108  //**Compile time checks*************************************************************************
112  //**********************************************************************************************
113 };
114 //*************************************************************************************************
115 
116 
117 
118 
119 //=================================================================================================
120 //
121 // CONSTRUCTOR
122 //
123 //=================================================================================================
124 
125 //*************************************************************************************************
130 template< typename T > // Type of the unsigned value
132  : value_( value ) // The wrapped built-in unsigned integral value
133 {}
134 //*************************************************************************************************
135 
136 
137 
138 
139 //=================================================================================================
140 //
141 // ASSIGNMENT OPERATOR
142 //
143 //=================================================================================================
144 
145 //*************************************************************************************************
151 template< typename T > // Type of the unsigned value
153 {
154  value_ = value;
155  return *this;
156 }
157 //*************************************************************************************************
158 
159 
160 
161 
162 //=================================================================================================
163 //
164 // CONVERSION OPERATOR
165 //
166 //=================================================================================================
167 
168 //*************************************************************************************************
173 template< typename T > // Type of the unsigned value
175 {
176  return value_;
177 }
178 //*************************************************************************************************
179 
180 
181 
182 
183 //=================================================================================================
184 //
185 // ACCESS FUNCTIONS
186 //
187 //=================================================================================================
188 
189 //*************************************************************************************************
194 template< typename T > // Type of the unsigned value
195 inline T UnsignedValue<T>::get() const
196 {
197  return value_;
198 }
199 //*************************************************************************************************
200 
201 
202 
203 
204 //=================================================================================================
205 //
206 // GLOBAL OPERATORS
207 //
208 //=================================================================================================
209 
210 //*************************************************************************************************
213 template< typename T1, typename T2 >
214 inline bool operator==( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
215 
216 template< typename T1, typename T2 >
217 inline bool operator!=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
218 
219 template< typename T1, typename T2 >
220 inline bool operator< ( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
221 
222 template< typename T1, typename T2 >
223 inline bool operator> ( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
224 
225 template< typename T1, typename T2 >
226 inline bool operator<=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
227 
228 template< typename T1, typename T2 >
229 inline bool operator>=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
230 
231 template< typename T >
232 inline std::ostream& operator<<( std::ostream& os, const UnsignedValue<T>& uv );
233 
234 template< typename T >
235 std::istream& operator>>( std::istream& is, UnsignedValue<T>& uv );
237 //*************************************************************************************************
238 
239 
240 //*************************************************************************************************
247 template< typename T1 // Type of the left-hand side unsigned value
248  , typename T2 > // Type of the right-hand side unsigned value
249 inline bool operator==( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
250 {
251  return lhs.get() == rhs.get();
252 }
253 //*************************************************************************************************
254 
255 
256 //*************************************************************************************************
263 template< typename T1 // Type of the left-hand side unsigned value
264  , typename T2 > // Type of the right-hand side unsigned value
265 inline bool operator!=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
266 {
267  return lhs.get() != rhs.get();
268 }
269 //*************************************************************************************************
270 
271 
272 //*************************************************************************************************
279 template< typename T1 // Type of the left-hand side unsigned value
280  , typename T2 > // Type of the right-hand side unsigned value
281 inline bool operator<( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
282 {
283  return lhs.get() < rhs.get();
284 }
285 //*************************************************************************************************
286 
287 
288 //*************************************************************************************************
295 template< typename T1 // Type of the left-hand side unsigned value
296  , typename T2 > // Type of the right-hand side unsigned value
297 inline bool operator>( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
298 {
299  return lhs.get() > rhs.get();
300 }
301 //*************************************************************************************************
302 
303 
304 //*************************************************************************************************
311 template< typename T1 // Type of the left-hand side unsigned value
312  , typename T2 > // Type of the right-hand side unsigned value
313 inline bool operator<=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
314 {
315  return lhs.get() <= rhs.get();
316 }
317 //*************************************************************************************************
318 
319 
320 //*************************************************************************************************
327 template< typename T1 // Type of the left-hand side unsigned value
328  , typename T2 > // Type of the right-hand side unsigned value
329 inline bool operator>=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
330 {
331  return lhs.get() >= rhs.get();
332 }
333 //*************************************************************************************************
334 
335 
336 //*************************************************************************************************
343 template< typename T > // Type of the unsigned value
344 inline std::ostream& operator<<( std::ostream& os, const UnsignedValue<T>& uv )
345 {
346  return os << uv.get();
347 }
348 //*************************************************************************************************
349 
350 
351 //*************************************************************************************************
363 template< typename T > // Type of the unsigned value
364 std::istream& operator>>( std::istream& is, UnsignedValue<T>& uv )
365 {
366  T tmp;
367  const std::istream::pos_type pos( is.tellg() );
368 
369  // Skipping any leading whitespaces
370  is >> std::ws;
371 
372  // Extracting the value
373  if( is.peek() == '-' || !(is >> tmp) )
374  {
375  is.clear();
376  is.seekg( pos );
377  is.setstate( std::istream::failbit );
378  return is;
379  }
380 
381  // Transfering the input to the unsigned integer value
382  uv = tmp;
383 
384  return is;
385 }
386 //*************************************************************************************************
387 
388 } // namespace blaze
389 
390 #endif
std::istream & operator>>(std::istream &is, UnsignedValue< T > &uv)
Global input operator for the UnsignedValue wrapper.
Definition: UnsignedValue.h:364
UnsignedValue(T value=0)
The default constructor for UnsignedInt.
Definition: UnsignedValue.h:131
#define BLAZE_CONSTRAINT_MUST_BE_UNSIGNED_TYPE(T)
Constraint on the data type.In case the given data type T is not an unsigned integral data type...
Definition: Unsigned.h:61
T value_
The wrapped built-in unsigned integral value.
Definition: UnsignedValue.h:104
Constraint on the data type.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
constexpr bool operator>(const NegativeAccuracy< A > &lhs, const T &rhs)
Greater-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:367
constexpr bool operator>=(const NegativeAccuracy< A > &, const T &rhs)
Greater-or-equal-than comparison between a NegativeAccuracy object and a floating point value...
Definition: Accuracy.h:443
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:250
UnsignedValue & operator=(T value)
Assignment of a built-in unsigned integral value.
Definition: UnsignedValue.h:152
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:290
T get() const
Access to the wrapped built-in unsigned integral value.
Definition: UnsignedValue.h:195
Implementation of a wrapper for built-in unsigned integral values.This class wraps a value of built-i...
Definition: UnsignedValue.h:63