SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
builtin.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 /*
30  *@file builtin.h
31  *
32  *@author
33  * Yarden Livnat
34  * Department of Computer Science
35  * University of Utah
36  *@date March 2001
37  *
38  *@brief Classes for built in datatypes
39  */
40 
41 #ifndef builtin_h
42 #define builtin_h
43 
46 
47 namespace SCIRun {
48 
49 class Scalar {
50 public:
51  virtual ~Scalar() {}
52  virtual operator char() = 0;
53  virtual operator short() = 0;
54  virtual operator int() = 0;
55  virtual operator float() = 0;
56  virtual operator double() = 0;
57 };
58 
59 template<class T>
60 class ScalarType : public Scalar{
61 public:
62  T val_;
63 
65  ScalarType( T v ) : val_(v) {}
66 
67  void operator=( const ScalarType &copy ) { val_ = copy.val_;}
68  operator char() { return char(val_); }
69  operator short() { return short(val_); }
70  operator int() { return int(val_); }
71  operator float() { return float(val_); }
72  operator double() { return double(val_); }
73 };
74 
84 
85 inline void Pio(Piostream& stream, Char& d) {Pio(stream,d.val_);}
86 inline void Pio(Piostream& stream, UChar& d) {Pio(stream,d.val_);}
87 inline void Pio(Piostream& stream, Short& d) {Pio(stream,d.val_);}
88 inline void Pio(Piostream& stream, UShort& d){Pio(stream,d.val_);}
89 inline void Pio(Piostream& stream, Int& d) {Pio(stream,d.val_);}
90 inline void Pio(Piostream& stream, UInt& d) {Pio(stream,d.val_);}
91 inline void Pio(Piostream& stream, Float& d) {Pio(stream,d.val_);}
92 inline void Pio(Piostream& stream, Double& d){Pio(stream,d.val_);}
93 inline void Pio(Piostream& stream, LongLong& d){Pio(stream,d.val_);}
94 
95 inline const std::string find_type_name(Char*) {return find_type_name(static_cast<char *>(0));}
96 inline const std::string find_type_name(UChar*) {return find_type_name(static_cast<unsigned char *>(0));}
97 inline const std::string find_type_name(Short*) {return find_type_name(static_cast<short *>(0));}
98 inline const std::string find_type_name(UShort*){return find_type_name(static_cast<unsigned short *>(0));}
99 inline const std::string find_type_name(Int*) {return find_type_name(static_cast<int *>(0));}
100 inline const std::string find_type_name(UInt*) {return find_type_name(static_cast<unsigned int *>(0));}
101 inline const std::string find_type_name(Float*) {return find_type_name(static_cast<float *>(0));}
102 inline const std::string find_type_name(Double*){return find_type_name(static_cast<double *>(0));}
103 inline const std::string find_type_name(LongLong*){return find_type_name(static_cast<double *>(0));}
104 
105 template<class T> bool is_scalar() { return false; }
106 template<> inline bool is_scalar<char>() { return true; }
107 template<> inline bool is_scalar<unsigned char>() { return true; }
108 template<> inline bool is_scalar<short>() { return true; }
109 template<> inline bool is_scalar<unsigned short>() { return true; }
110 template<> inline bool is_scalar<int>() { return true; }
111 template<> inline bool is_scalar<float>() { return true; }
112 template<> inline bool is_scalar<double>() { return true; }
113 
114 } // end namespace SCIRun
115 
116 #endif // builtin_h
ScalarType< char > Char
Definition: builtin.h:75
bool is_scalar< short >()
Definition: builtin.h:108
ScalarType< double > Double
Definition: builtin.h:83
Definition: builtin.h:60
bool is_scalar< unsigned short >()
Definition: builtin.h:109
ScalarType< float > Float
Definition: builtin.h:82
specializations of template&lt;class T&gt; find_type_name() function for build-in and simple types not deri...
bool is_scalar< double >()
Definition: builtin.h:112
Definition: Persistent.h:89
bool is_scalar< unsigned char >()
Definition: builtin.h:107
ScalarType< unsigned char > UChar
Definition: builtin.h:76
ScalarType< short > Short
Definition: builtin.h:77
ScalarType()
Definition: builtin.h:64
bool is_scalar< char >()
Definition: builtin.h:106
const string find_type_name(float *)
Definition: TypeName.cc:63
ScalarType< long long > LongLong
Definition: builtin.h:81
Base class for persistent objects...
ScalarType< unsigned short > UShort
Definition: builtin.h:78
bool is_scalar< int >()
Definition: builtin.h:110
ScalarType(T v)
Definition: builtin.h:65
ScalarType< int > Int
Definition: builtin.h:79
v
Definition: readAllFields.py:42
bool is_scalar< float >()
Definition: builtin.h:111
void Pio(Piostream &stream, Array1< T > &array)
Definition: Array1.h:65
T val_
Definition: builtin.h:62
Definition: builtin.h:49
virtual ~Scalar()
Definition: builtin.h:51
ScalarType< unsigned int > UInt
Definition: builtin.h:80
void operator=(const ScalarType &copy)
Definition: builtin.h:67
bool is_scalar()
Definition: builtin.h:105