SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TypeDescription.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 /// @file TypeDescription.h
30 /// @author Martin Cole
31 /// @date Mon May 14 10:16:28 2001
32 
33 #if ! defined(Disclosure_TypeDescription_h)
34 #define Disclosure_TypeDescription_h
35 
36 #include <vector>
37 #include <string>
38 
40 
41 namespace SCIRun {
42 
43 struct CompileInfo;
44 
46 public:
47  enum category_e {
53  OTHER_E
54  };
55 
56  typedef std::vector<const TypeDescription*> td_vec;
57 
58  TypeDescription(const std::string& name,
59  const std::string& path,
60  const std::string& namesp,
61  category_e c = OTHER_E);
62  TypeDescription(const std::string& name,
63  td_vec *sub, // this takes ownership of the memory.
64  const std::string& path,
65  const std::string& namesp,
66  category_e c = OTHER_E);
67  ~TypeDescription();
68 
69  td_vec* get_sub_type() const {
70  return subtype_;
71  }
72  /// The arguments determine how the templated types are separated.
73  /// default is "<" and "> "
74  std::string get_name(const std::string & type_sep_start = "<",
75  const std::string & type_sep_end = "> ") const;
76  std::string get_similar_name(const std::string &substitute,
77  const int pos,
78  const std::string & type_sep_start = "<",
79  const std::string & type_sep_end = "> ") const;
80 
81  std::string get_filename() const;
82 
83  std::string get_h_file_path() const { return h_file_path_; }
84  std::string get_namespace() const { return namespace_; }
85 
86  struct Register {
87  Register(const TypeDescription*);
88  ~Register();
89  };
90 
91 // void fill_compile_info(CompileInfo *ci) const;
92 
93  /// convert a string that ends in .cc to end in .h
94  static std::string cc_to_h(const std::string &dot_cc);
95  static std::string strip_absolute_path(const std::string &path);
96  static const TypeDescription* lookup_type(const std::string&);
97 
98 private:
99  td_vec *subtype_;
100  std::string name_;
101  std::string h_file_path_;
102  std::string namespace_;
103  category_e category_;
104  // Hide these methods
106  TypeDescription& operator=(const TypeDescription&);
107 
108  void register_type();
109 };
110 
111 
115 SCISHARE const TypeDescription* get_type_description(unsigned short*);
117 SCISHARE const TypeDescription* get_type_description(unsigned int*);
119 SCISHARE const TypeDescription* get_type_description(unsigned long*);
121 SCISHARE const TypeDescription* get_type_description(unsigned long long*);
123 SCISHARE const TypeDescription* get_type_description(unsigned char*);
125 SCISHARE const TypeDescription* get_type_description(std::string*);
126 
127 template <class T>
128 const TypeDescription* get_type_description(std::vector<T>*)
129 {
130  static TypeDescription* td = 0;
131  if(!td){
132  const TypeDescription *sub = get_type_description(static_cast<T*>(0));
134  (*subs)[0] = sub;
135  td = new TypeDescription("vector", subs, "std::vector", "std",
137  }
138  return td;
139 }
140 
141 template <class T1, class T2>
142 const TypeDescription* get_type_description (std::pair<T1,T2> *)
143 {
144  static TypeDescription* td = 0;
145  if(!td){
146  const TypeDescription *sub1 = get_type_description(static_cast<T1*>(0));
147  const TypeDescription *sub2 = get_type_description(static_cast<T2*>(0));
149  (*subs)[0] = sub1;
150  (*subs)[1] = sub2;
151  td = new TypeDescription("pair", subs, "std::utility", "std",
153  }
154  return td;
155 
156 }
157 
158 } // End namespace SCIRun
159 
160 #endif //Disclosure_TypeDescription_h
161 
Definition: TypeDescription.h:51
td_vec * get_sub_type() const
Definition: TypeDescription.h:69
Definition: TypeDescription.h:50
Definition: TypeDescription.h:45
#define SCISHARE
Definition: share.h:39
std::vector< const TypeDescription * > td_vec
Definition: TypeDescription.h:56
std::string get_namespace() const
Definition: TypeDescription.h:84
Definition: TypeDescription.h:52
const char * name[]
Definition: BoostGraphExampleTests.cc:87
std::string get_h_file_path() const
Definition: TypeDescription.h:83
category_e
Definition: TypeDescription.h:47
Definition: TypeDescription.h:86
Definition: TypeDescription.h:48
Definition: TypeDescription.h:49
const TypeDescription * get_type_description(Core::Basis::ConstantBasis< T > *)
Definition: Constant.h:209