All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 <istream>
44 #include <ostream>
46 
47 
48 namespace blaze {
49 
50 //=================================================================================================
51 //
52 // CLASS DEFINITION
53 //
54 //=================================================================================================
55 
56 //*************************************************************************************************
63 template< typename T > // Type of the unsigned value
65 {
66  public:
67  //**Constructors********************************************************************************
70  explicit inline UnsignedValue( T value=0 );
71  // No explicitly declared copy constructor.
73  //**********************************************************************************************
74 
75  //**Destructor**********************************************************************************
76  // No explicitly declared destructor.
77  //**********************************************************************************************
78 
79  //**Assignment operator*************************************************************************
82  inline UnsignedValue& operator=( T value );
83  // No explicitly declared copy assignment operator.
85  //**********************************************************************************************
86 
87  //**Conversion operator*************************************************************************
90  inline operator T() const;
92  //**********************************************************************************************
93 
94  //**Access function*****************************************************************************
97  inline T get() const;
99  //**********************************************************************************************
100 
101  private:
102  //**Member variables****************************************************************************
105  T value_;
106 
107  //**********************************************************************************************
108 
109  //**Compile time checks*************************************************************************
113  //**********************************************************************************************
114 };
115 //*************************************************************************************************
116 
117 
118 
119 
120 //=================================================================================================
121 //
122 // CONSTRUCTOR
123 //
124 //=================================================================================================
125 
126 //*************************************************************************************************
131 template< typename T > // Type of the unsigned value
133  : value_( value ) // The wrapped built-in unsigned integral value
134 {}
135 //*************************************************************************************************
136 
137 
138 
139 
140 //=================================================================================================
141 //
142 // ASSIGNMENT OPERATOR
143 //
144 //=================================================================================================
145 
146 //*************************************************************************************************
152 template< typename T > // Type of the unsigned value
154 {
155  value_ = value;
156  return *this;
157 }
158 //*************************************************************************************************
159 
160 
161 
162 
163 //=================================================================================================
164 //
165 // CONVERSION OPERATOR
166 //
167 //=================================================================================================
168 
169 //*************************************************************************************************
174 template< typename T > // Type of the unsigned value
176 {
177  return value_;
178 }
179 //*************************************************************************************************
180 
181 
182 
183 
184 //=================================================================================================
185 //
186 // ACCESS FUNCTIONS
187 //
188 //=================================================================================================
189 
190 //*************************************************************************************************
195 template< typename T > // Type of the unsigned value
196 inline T UnsignedValue<T>::get() const
197 {
198  return value_;
199 }
200 //*************************************************************************************************
201 
202 
203 
204 
205 //=================================================================================================
206 //
207 // GLOBAL OPERATORS
208 //
209 //=================================================================================================
210 
211 //*************************************************************************************************
214 template< typename T1, typename T2 >
215 inline bool operator==( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
216 
217 template< typename T1, typename T2 >
218 inline bool operator!=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
219 
220 template< typename T1, typename T2 >
221 inline bool operator< ( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
222 
223 template< typename T1, typename T2 >
224 inline bool operator> ( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
225 
226 template< typename T1, typename T2 >
227 inline bool operator<=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
228 
229 template< typename T1, typename T2 >
230 inline bool operator>=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
231 
232 template< typename T >
233 inline std::ostream& operator<<( std::ostream& os, const UnsignedValue<T>& uv );
234 
235 template< typename T >
236 std::istream& operator>>( std::istream& is, UnsignedValue<T>& uv );
238 //*************************************************************************************************
239 
240 
241 //*************************************************************************************************
248 template< typename T1 // Type of the left-hand side unsigned value
249  , typename T2 > // Type of the right-hand side unsigned value
250 inline bool operator==( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
251 {
252  return lhs.get() == rhs.get();
253 }
254 //*************************************************************************************************
255 
256 
257 //*************************************************************************************************
264 template< typename T1 // Type of the left-hand side unsigned value
265  , typename T2 > // Type of the right-hand side unsigned value
266 inline bool operator!=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
267 {
268  return lhs.get() != rhs.get();
269 }
270 //*************************************************************************************************
271 
272 
273 //*************************************************************************************************
280 template< typename T1 // Type of the left-hand side unsigned value
281  , typename T2 > // Type of the right-hand side unsigned value
282 inline bool operator<( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
283 {
284  return lhs.get() < rhs.get();
285 }
286 //*************************************************************************************************
287 
288 
289 //*************************************************************************************************
296 template< typename T1 // Type of the left-hand side unsigned value
297  , typename T2 > // Type of the right-hand side unsigned value
298 inline bool operator>( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
299 {
300  return lhs.get() > rhs.get();
301 }
302 //*************************************************************************************************
303 
304 
305 //*************************************************************************************************
312 template< typename T1 // Type of the left-hand side unsigned value
313  , typename T2 > // Type of the right-hand side unsigned value
314 inline bool operator<=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
315 {
316  return lhs.get() <= rhs.get();
317 }
318 //*************************************************************************************************
319 
320 
321 //*************************************************************************************************
328 template< typename T1 // Type of the left-hand side unsigned value
329  , typename T2 > // Type of the right-hand side unsigned value
330 inline bool operator>=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
331 {
332  return lhs.get() >= rhs.get();
333 }
334 //*************************************************************************************************
335 
336 
337 //*************************************************************************************************
344 template< typename T > // Type of the unsigned value
345 inline std::ostream& operator<<( std::ostream& os, const UnsignedValue<T>& uv )
346 {
347  return os << uv.get();
348 }
349 //*************************************************************************************************
350 
351 
352 //*************************************************************************************************
364 template< typename T > // Type of the unsigned value
365 std::istream& operator>>( std::istream& is, UnsignedValue<T>& uv )
366 {
367  T tmp;
368  const std::istream::pos_type pos( is.tellg() );
369 
370  // Skipping any leading whitespaces
371  is >> std::ws;
372 
373  // Extracting the value
374  if( is.peek() == '-' || !(is >> tmp) )
375  {
376  is.clear();
377  is.seekg( pos );
378  is.setstate( std::istream::failbit );
379  return is;
380  }
381 
382  // Transfering the input to the unsigned integer value
383  uv = tmp;
384 
385  return is;
386 }
387 //*************************************************************************************************
388 
389 } // namespace blaze
390 
391 #endif
UnsignedValue(T value=0)
The default constructor for UnsignedInt.
Definition: UnsignedValue.h:132
bool operator>(const NegativeAccuracy< A > &lhs, const T &rhs)
Greater-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:366
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:442
#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:79
T value_
The wrapped built-in unsigned integral value.
Definition: UnsignedValue.h:105
T get() const
Access to the wrapped built-in unsigned integral value.
Definition: UnsignedValue.h:196
Constraint on the data type.
std::istream & operator>>(std::istream &is, Quaternion< Type > &q)
Global input operator for quaternions.
Definition: Quaternion.h:902
UnsignedValue & operator=(T value)
Assignment of a built-in unsigned integral value.
Definition: UnsignedValue.h:153
Implementation of a wrapper for built-in unsigned integral values.This class wraps a value of built-i...
Definition: UnsignedValue.h:64
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289