FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
FiberType.hpp
1#ifndef __FIBERTYPE_HPP
2#define __FIBERTYPE_HPP "Created 27.02.2001 21:42:27 by werner"
3
4#include "FieldAPI.h"
5
6#include <meta/LIST.hpp>
7#include <eagle/MetaInfo.hpp>
8#include <memcore/RefPtr.hpp>
9#include <memcore/typemap.hpp>
10#include <memcore/stringlist.hpp>
11#include <memcore/Chunk.hpp>
12
13#include <assert.h>
14#include <string>
15
16#include "FiberTypeIndex.hpp"
17#include "FiberTypeBase.hpp"
18
22namespace Fiber
23{
24
25
26template <class T>
27struct SizeOf
28{
29static size_t memsize() { return sizeof(T); }
30
31static MemCore::RefPtr<MemCore::Chunk<T> > newChunk(size_t N, bool ReserveOnly = false)
32 {
33 return new MemCore::Chunk<T>(N, ReserveOnly);
34 }
35};
36
37#if 0
38template <> struct SizeOf<void>
39{
40static size_t memsize() { return 0; }
41
42static MemCore::NullPtr newChunk(size_t, bool=false)
43 {
44 return MemCore::NullPtr();
45 }
46};
47#endif
48
49
50
59template <class T>
61{
62public:
63
65 typedef typename FiberInfo_t::element_t element_t;
66
67 typedef typename FiberInfo_t::Chart_t Chart_t;
68
70
71
72static FiberTypeIndex getFiberTypeIndex()
73 {
74 return
75 {
77/* mem_size */ , unsigned( SizeOf<T>::memsize() )
78/* rank */ , FiberInfo_t::RANK
79/* grade*/ , FiberInfo_t::GRADE
81/* type_name */ , MemCore::Typename(typeid(T) )
82/* element_type_name */ , MemCore::Typename(typeid(typename FiberInfo_t::element_t))
83/* chart_name */ , MemCore::Typename(typeid(Chart_t) )
84/* chart_dimension */ , Dims
85 };
86 }
87
88
89 FiberType()
90 : FiberTypeBase( getFiberTypeIndex() )
91 {
92 FiberTypeBase::remember();
93 }
94
95 FiberType(const FiberType&) = delete;
96
97
98//static FiberType TypeInfo;
99
100 const std::type_info&getType() const override
101 {
102 return typeid(T);
103 }
104
107 {
108 return SizeOf<T>::newChunk(N);
109 }
110
111 bool isType(const std::type_info&theType) const override
112 {
113 return theType == typeid(T);
114 }
115
127 {
128 static MemCore::Auto<FiberType<T>> myType;
129 return myType.self();
130 }
131
132 WeakPtr_t element_type() const override
133 {
135 }
136/*
137 unsigned multiplicity() const override
138 {
139 return FiberInfo_t::MULTIPLICITY;
140 }
141
142 int rank() const override
143 {
144 return FiberInfo_t::RANK;
145 }
146*/
147
153/* int grade() const override
154 {
155 return FiberInfo_t::GRADE;
156 }
157*/
165
167 const std::type_info&chart_type() const override
168 {
169 return typeid(Chart_t);
170 }
171/*
172 std::string chart_name() const override
173 {
174 return MemCore::Typename(chart_type() );
175 }
176
177
179 int chart_dimension() const override
180 {
181 return Dims;
182 }
183*/
184 int element_index(const int i[]) const override
185 {
187 }
188/*
190 unsigned mem_size() const override
191 {
192 return unsigned( SizeOf<T>::memsize() );
193 }
194*/
195
196 int indexing_scheme(int i) const override
197 {
199 }
200
201 const char*nontensor() const override
202 {
203 return 0;
204// return FiberInfoNonTensor<T>::object_name();
205 }
206};
207
208
212struct FIELD_API TypeList : public std::set<MemCore::WeakPtr<FiberTypeBase> >
213{
215 TypeList();
216
219
221 ~TypeList();
222
224 bool contains(const std::type_info&what) const;
225
231
232 std::string str(const std::string&delimiter = ", ") const
233 {
234 if (auto S = asText())
235 return S->collapse(delimiter);
236
237 return {};
238 }
239
241 void speak() const;
242};
243
244typedef TypeList TypeList_t;
245
249extern FIELD_API bool containsType(const TypeList_t&TL, const std::type_info&what);
250
265template <class T, class ...more>
266struct AcceptType : AcceptType<T>, AcceptType<more...>
267{
277 : AcceptType<T>(TL)
278 , AcceptType<more...>(TL)
279 {}
280
281static int accept(Fiber::TypeList_t&TL)
282 {
283 return AcceptType<T>::accept(TL) +
285 }
286};
287
288template <class T>
289struct AcceptType<T>
290{
292 {
294 }
295
296static int accept(Fiber::TypeList_t&TL)
297 {
299 return 1;
300 }
301};
302
303
304template <class ...Type>
305struct AcceptType<META::LIST<Type...> > : AcceptType<Type...>
306{
308 : AcceptType<Type...> (TL)
309 {}
310
311static int accept(Fiber::TypeList_t&TL)
312 {
313 return AcceptType<Type...>::accept( TL );
314 }
315};
316
317
318} /* namespace Fiber */
319
320namespace std
321{
322
324FIELD_API string to_string(const Fiber::FiberTypeBase&);
325
326}
327
328
329#endif /* __FIBERTYPE_HPP */
basic_string< char > string
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
Abstract procedural description of a data element which may be used to construct arrays and fields.
Definition FiberTypeBase.hpp:33
Description of types, which is meta-information like what is the number of elements of some array-lik...
Definition FiberType.hpp:61
const std::type_info & getType() const override
Type ID for this type.
Definition FiberType.hpp:100
static WeakPtr_t getFiberType()
Get the fiber type information for the current type.
Definition FiberType.hpp:126
std::string coordinate_component_name(int i) const override
The grade of this vector type, a multivector quantity from geometric algebra.
Definition FiberType.hpp:161
const std::type_info & chart_type() const override
Return the associated chart type.
Definition FiberType.hpp:167
int element_index(const int i[]) const override
Information about the organization of elements of a multi-ranked object.
Definition FiberType.hpp:184
MemCore::RefPtr< MemCore::ChunkBase > newChunk(size_t N) const override
Implement the virtual function to allocate chinks.
Definition FiberType.hpp:106
int indexing_scheme(int i) const override
Definition FiberType.hpp:196
MEMCORE_API std::string Typename(const std::type_info &t)
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
bool containsType(const TypeList_t &TL, const type_info &what)
Investigate if a certain type is contained in a given type list.
Definition FiberType.cpp:228
std::nullptr_t NullPtr
STL namespace.
A template helper class to provide an easier syntax for allowing certain field types to be accepted b...
Definition FiberType.hpp:267
AcceptType(Fiber::TypeList_t &TL)
Pseudo-constructor: The object itself here is not used at all.
Definition FiberType.hpp:276
Definition FiberTypeIndex.hpp:12
Definition FiberType.hpp:28
A set of types.
Definition FiberType.hpp:213