SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FieldIndex.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 ///@author
32 /// Marty Cole
33 /// Department of Computer Science
34 /// University of Utah
35 ///@date January 2001
36 ///
37 ///
38 
39 #ifndef Datatypes_FieldIndex_h
40 #define Datatypes_FieldIndex_h
41 
44 
45 #include <vector>
46 
47 namespace SCIRun {
48 
49 /// Base type for index types.
50 template <class T>
52 public:
53  typedef T value_type;
54 
56  index_(i) {}
57 
58  /// Required interface for an Index.
59  operator T const &() const { return index_; }
60 
61  std::ostream& str_render(std::ostream& os) const {
62  os << index_;
63  return os;
64  }
65 
66  T index_;
67 };
68 
69 
70 /// Distinct type for node index.
71 template <class T>
72 struct NodeIndex : public FieldIndexBase<T> {
74  FieldIndexBase<T>(0) {}
75  NodeIndex(T index) :
76  FieldIndexBase<T>(index) {}
77 };
78 
79 /// Distinct type for edge index.
80 template <class T>
81 struct EdgeIndex : public FieldIndexBase<T> {
83  FieldIndexBase<T>(0) {}
84  EdgeIndex(T index) :
85  FieldIndexBase<T>(index) {}
86 };
87 
88 /// Distinct type for face index.
89 template <class T>
90 struct FaceIndex : public FieldIndexBase<T> {
92  FieldIndexBase<T>(0) {}
93  FaceIndex(T index) :
94  FieldIndexBase<T>(index) {}
95 };
96 
97 /// Distinct type for cell index.
98 template <class T>
99 struct CellIndex : public FieldIndexBase<T> {
101  FieldIndexBase<T>(0) {}
102  CellIndex(T index) :
103  FieldIndexBase<T>(index) {}
104 };
105 
106 // the following operators only exist to get the generic interpolate to compile
107 //
108 template <class T>
109 std::vector<CellIndex<T> >
110 operator*(const std::vector<CellIndex<T> >& r, double &) {
111  ASSERTFAIL("FieldIndex.h Bogus operator");
112  return r;
113 }
114 
115 template <class T>
116 std::vector<CellIndex<T> >
117 operator+=(const std::vector<CellIndex<T> >& l, const std::vector<CellIndex<T> >& r) {
118  ASSERTFAIL("FieldIndex.h Bogus operator");
119  return l;
120 }
121 
122 template <class T>
124 {
125  static TypeDescription* td = 0;
126 
127  if(!td){
128  const TypeDescription *sub = get_type_description(static_cast<T*>(0));
130  (*subs)[0] = sub;
131  td = new TypeDescription("NodeIndex", subs, __FILE__, "SCIRun");
132  }
133  return td;
134 }
135 
136 template <class T>
138 {
139  static TypeDescription* td = 0;
140  if(!td){
141  const TypeDescription *sub = get_type_description(static_cast<T*>(0));
143  (*subs)[0] = sub;
144  td = new TypeDescription("EdgeIndex", subs, __FILE__, "SCIRun");
145  }
146  return td;
147 }
148 
149 template <class T>
151 {
152  static TypeDescription* td = 0;
153  if(!td){
154  const TypeDescription *sub = get_type_description(static_cast<T*>(0));
156  (*subs)[0] = sub;
157  td = new TypeDescription("FaceIndex", subs, __FILE__, "SCIRun");
158  }
159  return td;
160 }
161 
162 template <class T>
164 {
165  static TypeDescription* td = 0;
166  if(!td){
167  const TypeDescription *sub = get_type_description(static_cast<T*>(0));
169  (*subs)[0] = sub;
170  td = new TypeDescription("CellIndex", subs, __FILE__, "SCIRun");
171  }
172  return td;
173 }
174 
175 #define FIELDINDEXBASE_VERSION 1
176 
177 template<class T>
179 {
180  Pio(stream, data.index_);
181 }
182 
183 template <class T> const std::string find_type_name(NodeIndex<T> *)
184 {
185  static const std::string name = TypeNameGenerator::make_template_id("NodeIndex", find_type_name(static_cast<T*>(0)));
186  return name;
187 }
188 
189 template <class T> const std::string find_type_name(EdgeIndex<T> *)
190 {
191  static const std::string name = TypeNameGenerator::make_template_id("EdgeIndex", find_type_name(static_cast<T*>(0)));
192  return name;
193 }
194 
195 template <class T> const std::string find_type_name(FaceIndex<T> *)
196 {
197  static const std::string name = TypeNameGenerator::make_template_id("FaceIndex", find_type_name(static_cast<T*>(0)));
198  return name;
199 }
200 
201 template <class T> const std::string find_type_name(CellIndex<T> *)
202 {
203  static const std::string name = TypeNameGenerator::make_template_id("CellIndex", find_type_name(static_cast<T*>(0)));
204  return name;
205 }
206 
207 } // end namespace SCIRun
208 
209 #endif // Datatypes_FieldIndex_h
EdgeIndex()
Definition: FieldIndex.h:82
T value_type
Definition: FieldIndex.h:53
specializations of template&lt;class T&gt; find_type_name() function for build-in and simple types not deri...
FaceIndex(T index)
Definition: FieldIndex.h:93
Definition: Persistent.h:89
Definition: TypeDescription.h:45
std::vector< const TypeDescription * > td_vec
Definition: TypeDescription.h:56
CellIndex(T index)
Definition: FieldIndex.h:102
CellIndex()
Definition: FieldIndex.h:100
const string find_type_name(float *)
Definition: TypeName.cc:63
Distinct type for cell index.
Definition: FieldIndex.h:99
NodeIndex(T index)
Definition: FieldIndex.h:75
Distinct type for node index.
Definition: FieldIndex.h:72
std::vector< CellIndex< T > > operator*(const std::vector< CellIndex< T > > &r, double &)
Definition: FieldIndex.h:110
const char * name[]
Definition: BoostGraphExampleTests.cc:87
EdgeIndex(T index)
Definition: FieldIndex.h:84
std::vector< CellIndex< T > > operator+=(const std::vector< CellIndex< T > > &l, const std::vector< CellIndex< T > > &r)
Definition: FieldIndex.h:117
dictionary data
Definition: eabLatVolData.py:11
T index_
Definition: FieldIndex.h:66
Distinct type for face index.
Definition: FieldIndex.h:90
FieldIndexBase(T i)
Definition: FieldIndex.h:55
static const std::string make_template_id(const std::string &templateName, const std::string &templateParam)
Definition: TypeName.h:62
Base type for index types.
Definition: FieldIndex.h:51
#define ASSERTFAIL(string)
Definition: Assert.h:52
void Pio(Piostream &stream, Array1< T > &array)
Definition: Array1.h:65
FaceIndex()
Definition: FieldIndex.h:91
Distinct type for edge index.
Definition: FieldIndex.h:81
std::ostream & str_render(std::ostream &os) const
Definition: FieldIndex.h:61
NodeIndex()
Definition: FieldIndex.h:73
const TypeDescription * get_type_description(Core::Basis::ConstantBasis< T > *)
Definition: Constant.h:209