SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TypeName.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 /*
31  *@file TypeName.h
32  *@brief template to return name of argument type;
33  * used in PIO of templatized types
34  *
35  *@author
36  * Alexei Samsonov
37  * Department of Computer Science
38  * University of Utah
39  *@date December 2000
40  *
41  */
42 
43 #ifndef TYPENAME_H
44 #define TYPENAME_H
45 
46 #include <string>
47 #include <vector>
48 #include <map>
49 #include <sstream>
50 
53 
54 namespace SCIRun {
55 
56 
57 
59 {
60 /// @todo: callers of these can be compressed using macros. worth it?
61 public:
62  static const std::string make_template_id(const std::string& templateName, const std::string& templateParam)
63  {
64  std::ostringstream o;
65  o << templateName << leftAngleBracket << templateParam << rightAngleBracket;
66  return o.str();
67  }
68 
69  static const std::string make_template_id(const std::string& templateName,
70  const std::string& templateParam1,
71  const std::string& templateParam2)
72  {
73  std::ostringstream o;
74  o << templateName << leftAngleBracket
75  << templateParam1 << comma
76  << templateParam2 << rightAngleBracket;
77  return o.str();
78  }
79 
80  static const std::string make_template_id(const std::string& templateName,
81  const std::string& templateParam1,
82  const std::string& templateParam2,
83  const std::string& templateParam3)
84  {
85  std::ostringstream o;
86  o << templateName << leftAngleBracket
87  << templateParam1 << comma
88  << templateParam2 << comma
89  << templateParam3 << rightAngleBracket;
90  return o.str();
91  }
92 
93 private:
94  static const char leftAngleBracket = '<';
95  static const char comma = ',';
96  static const char rightAngleBracket = '>';
97 };
98 
99 
100 //////////
101 // Function to return name of type of its argument
102 template <class T> const std::string find_type_name(T*)
103 {
104  return T::type_name(-1);
105 }
106 
107 
108 template<class T, class S> const std::string find_type_name( std::pair<T,S> *);
109 
110 class IntVector;
111 class NrrdData;
112 
113 template<> SCISHARE const std::string find_type_name(float*);
114 template<> SCISHARE const std::string find_type_name(double*);
115 template<> SCISHARE const std::string find_type_name(long double*);
116 template<> SCISHARE const std::string find_type_name(short*);
117 template<> SCISHARE const std::string find_type_name(unsigned short*);
118 template<> SCISHARE const std::string find_type_name(int*);
119 template<> SCISHARE const std::string find_type_name(unsigned int*);
120 template<> SCISHARE const std::string find_type_name(long*);
121 template<> SCISHARE const std::string find_type_name(unsigned long*);
122 template<> SCISHARE const std::string find_type_name(long long*);
123 template<> SCISHARE const std::string find_type_name(unsigned long long*);
124 template<> SCISHARE const std::string find_type_name(char*);
125 template<> SCISHARE const std::string find_type_name(unsigned char*);
126 template<> SCISHARE const std::string find_type_name(bool*);
127 template<> SCISHARE const std::string find_type_name(SCIRun::Core::Geometry::Vector*);
128 template<> SCISHARE const std::string find_type_name(IntVector*);
129 template<> SCISHARE const std::string find_type_name(SCIRun::Core::Geometry::Point*);
130 template<> SCISHARE const std::string find_type_name(SCIRun::Core::Geometry::Transform*);
131 template<> SCISHARE const std::string find_type_name(std::string*);
132 
133 #ifdef SCIRUN4_CODE_TO_BE_ENABLED_LATER
134 template<> SCISHARE const std::string find_type_name(LockingHandle< Matrix<double> > *);
135 template<> SCISHARE const std::string find_type_name(LockingHandle<NrrdData> *);
136 template<> SCISHARE const std::string find_type_name(LockingHandle<Field> *);
137 template<> SCISHARE const std::string find_type_name(LockingHandle<String> *);
138 #endif
139 
140 //////////
141 // Function overloading for templates
142 template<class T> class Array1;
143 template<class T> class Array2;
144 
145 template <class T> const std::string find_type_name(Array1<T>*)
146 {
147  static const std::string name = TypeNameGenerator::make_template_id("Array1", find_type_name(static_cast<T*>(0)));
148  return name;
149 }
150 
151 template <class T> const std::string find_type_name(Array2<T>*)
152 {
153  static const std::string name = TypeNameGenerator::make_template_id("Array2", find_type_name(static_cast<T*>(0)));
154  return name;
155 }
156 
157 template <class T> const std::string find_type_name(std::vector<T>*)
158 {
159  static const std::string name = TypeNameGenerator::make_template_id("vector", find_type_name(static_cast<T*>(0)));
160  return name;
161 }
162 
163 template<class T, class S> const std::string find_type_name( std::pair<T,S> *)
164 {
165  static const std::string name = TypeNameGenerator::make_template_id("pair", find_type_name(static_cast<T*>(0)), find_type_name(static_cast<S*>(0)));
166  return name;
167 }
168 
169 } // namespace SCIRun
170 
171 #endif
static const std::string make_template_id(const std::string &templateName, const std::string &templateParam1, const std::string &templateParam2, const std::string &templateParam3)
Definition: TypeName.h:80
Definition: TypeName.h:58
Definition: Point.h:49
#define SCISHARE
Definition: share.h:39
Definition: Vector.h:63
const string find_type_name(float *)
Definition: TypeName.cc:63
const char * name[]
Definition: BoostGraphExampleTests.cc:87
Definition: Transform.h:53
static const std::string make_template_id(const std::string &templateName, const std::string &templateParam1, const std::string &templateParam2)
Definition: TypeName.h:69
static const std::string make_template_id(const std::string &templateName, const std::string &templateParam)
Definition: TypeName.h:62
Definition: Array2.h:51
Definition: Array1.h:51