FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
TypeRegistry.hpp
1
2//
3// $Id: TypeRegistry.hpp,v 1.19 2008/03/19 21:21:45 werner Exp $
4//
6#ifndef __FIBER_HDF5_TYPEREGISTRY_HPP
7#define __FIBER_HDF5_TYPEREGISTRY_HPP "Created 27.02.2001 21:42:27 by werner"
8
9#include "FiberIOHDF5DllApi.h"
10#include <memcore/RefPtr.hpp>
11#include <memcore/typemap.hpp>
12#include <field/FiberType.hpp>
13#include <F5/F5Bchart.h>
14#include <F5/F5F.h>
15
16#include "H5Globals.hpp"
17#include "F5Domain.hpp"
18
19namespace Fiber
20{
21 using namespace MemCore;
22
31{
32public:
35
36static ChartNameMap_t&ChartMap()
37 {
38 return H5Globals::theGlobals().ChartMap;
39 }
40
41static ChartTypeMap_t&ChartType()
42 {
43 return H5Globals::theGlobals().ChartType;
44 }
45
46static H5Globals::TypeRegistry_t&TypeRegistry()
47 {
48 return H5Globals::theGlobals().TypeRegistry;
49 }
50
51static RefPtr<H5ID> find(const std::type_info&);
52
54 {
55 return TypeRegistry().find(FTI);
56 }
57
59 {
60 if (!FTB) return nullptr;
61 return find( FTB->getFiberTypeIndex() );
62 }
63
64static void insert(const char*chartname, const type_info&charttype)
65 {
66 ChartMap() [ charttype ] = chartname;
67 ChartType().insert(
68 ChartTypeMap_t::value_type(chartname,
70 }
71
72template <class ChartDomain>
73 struct Domain
74 {
75 static void associate(const char*chartname)
76 {
77 insert(chartname, typeid(ChartDomain) );
78 }
79
80 static string name()
81 {
82 ChartNameMap_t::const_iterator cit = ChartMap().find( typeid(ChartDomain) );
83 if (cit == ChartMap().end() )
84 return "void";
85
86 return cit->second;
87 }
88 };
89
90
91
92static TypeInfo getChartType(hid_t type_id);
93
94 H5ID(hid_t hid);
95 ~H5ID();
96
97 hid_t getId() const
98 {
99 return hid;
100 }
101
107
113
114
120static RefPtr<H5ID> retrieve(const RefPtr<FiberTypeBase>&FTB);
121
122
123//static void printTypeInfo(hid_t id);
124
125};
126
127
129{
130public:
132 : H5ID(hid)
133 {}
134
136};
137
142template <class Type>
144{
146
147static hid_t getId()
148 {
149 auto FTI = FiberType_t::getFiberTypeIndex();
150 RefPtr<H5ID> Hid = H5ID::find(FTI);
151 if (!Hid)
152 return -1;
153
154 return Hid->getId();
155 }
156
157static bool registerHID(hid_t type_id, const RefPtr<F5Domain>&f = NullPtr(), bool isNative = false )
158 {
159 RefPtr<FiberTypeBase> FTB = FiberType_t::getFiberType();
160 if (!FTB)
161 {
162 return false;
163 }
164
165 RefPtr<H5DataType>&theH5ID = H5ID::TypeRegistry()[ FTB->getFiberTypeIndex() ];
166 if (theH5ID)
167 {
168 Verbose(120) << "ALREADY REGISTERED TYPE "<< Typename(FTB->getType()) << " --> HDF5 ID " << type_id;
169 return true;
170 }
171
172 Verbose(120) << "TYPE "<< Typename(FTB->getType()) << " --> HDF5 ID " << type_id;
173
174 AppVerbose("HDF5Init", 12) << "TYPE "<< Typename(FTB->getType())
175 << " --> " << FTB->getFiberTypeIndex().description()
176 << " --> " << FTB->description();
177
178 Assert(type_id>0);
179 if ( H5Tget_size(type_id) != FTB->mem_size() )
180 {
181 printf("HDF5TypeAction<>::registerHID() ERROR ==> HDF5 is %d bytes, memory is %d bytes, %s\n",
182 int(H5Tget_size(type_id)), int(FTB->mem_size()), FTB->description().c_str() );
183 Assert ( H5Tget_size(type_id) == FTB->mem_size() );
184 }
185
186 if (!isNative)
187 theH5ID = new H5ID( type_id );
188 else
190
191 return true;
192 }
193
194static bool registerNativeHID(hid_t type_id)
195 {
196 return registerHID(type_id, nullptr, true);
197 }
198
199static RefPtr<F5Domain> makeDomainType(const vector<std::string>&ElementNames)
200 {
201 RefPtr<FiberTypeBase> FTB = FiberType_t::getFiberType();
202 if (!FTB) return nullptr;
203
204 RefPtr<H5DataType>&theH5ID = H5ID::TypeRegistry()[ FTB->getFiberTypeIndex() ];
205 if (theH5ID)
206 {
207 Verbose(0) << "makeDomainType() ALREADY REGISTERED TYPE "<< Typename(FTB->getType());
208 return nullptr;
209 }
210
211 enum { ELEMENTS = FiberType_t::FiberInfo_t::MULTIPLICITY };
212 enum { RANK = FiberType_t::FiberInfo_t::RANK };
213
214 Assert( ELEMENTS == ElementNames.size());
215
217 for(int i=0; i<ELEMENTS; i++)
218 coordnames[i] = ElementNames[i].c_str();
219
220 typedef typename FiberType_t::FiberInfo_t::Chart_t DomainType;
221 typedef typename FiberType_t::element_t element_t;
222
225
226 Verbose(120)
227 << "TYPEREGISTRY: fibertype: ELEMENTS: " << ELEMENTS << " RANK: " << RANK
228 << " Domain " << Domainname << " Element Type is " << ElementType << " TODO: Create only ONCE global domain here";
229
230/*
231 Need to revise F5 library to produce the same tensor element names
232 as the FiberLib in field/Cell.hpp and field/FiberType.cpp .
233 */
235 switch( H5Tget_class(ElementType) )
236 {
237 case H5T_INTEGER:
238 Verbose(120) << " new integer domain ";
240 break;
241
242 case H5T_FLOAT:
243 Verbose(120) << " new chart";
245 break;
246 default:
247 printf("having type class: %d\n", H5Tget_class(ElementType));
248 puts(__FILE__ " -> stuff not supported.");
249 assert(0);
250 }
251
253
254 Verbose(120) << (ElementTypeSize==8?"(double, 64bit precision)":"(single, 32bit or less precision)");
255
256 if (!CD) return nullptr;
257
258 AppVerbose("HDF5Init", 20)
259 << "makeDomainType() with points from "
260 << (ElementTypeSize==8?"(double, 64bit precision)":"(single, 32bit or less precision)");
261
262 hid_t type_id = (ElementTypeSize==8)?CD->DoublePrecision.Point_hid_t:CD->SinglePrecision.Point_hid_t;
263 RefPtr<H5ID> H = new H5ID( type_id );
264 theH5ID = H;
265
266 RefPtr<F5Domain> f = new F5Domain( CD );
267 H->addInterface( f );
268
269 return f;
270 }
271
272
273static RefPtr<F5Domain> makeDomainType()
274 {
275 enum { ELEMENTS = FiberType_t::FiberInfo_t::MULTIPLICITY };
276 Verbose(120) << "makeDomainType() ELEMENTS: " << ELEMENTS;
278 for(int i=0; i<ELEMENTS; i++)
279 {
280 coordnames[i] = Type::coordinate_name(i);
281 Verbose(121) << " " << i << " --> " << coordnames[i];
282 }
283 return makeDomainType(coordnames);
284 }
285
286static bool registerCellType(const char*F5DomainName)
287 {
289 return makeDomainType();
290 }
291};
292
293
294
295/*
296template <class PointType>
297struct HDF5DomainAction : TypeAction
298{
299 typedef FiberType<PointType> FiberPointType_t;
300
301 typedef typename PointType::Base_t Coordinates_t;
302
303 typedef typename Coordinates_t::Metric Metric_t;
304
305
306static RefPtr<F5Domain> makeDomainType(const char*coordnames[])
307 {
308 const FiberTypeBase&FTB = FiberPointType_t::getFiberType();
309
310 RefPtr<TypeAction> TA = TypeAction::create( FTB.self() );
311
312 if (!TA)
313 return NullPtr();
314
315 enum { ELEMENTS = FiberPointType_t::FiberInfo_t::MULTIPLICITY };
316 enum { RANK = FiberPointType_t::FiberInfo_t::RANK };
317
318 typedef typename FiberPointType_t::FiberInfo_t::Chart_t DomainType;
319
320 typedef typename FiberPointType_t::element_t element_t;
321
322 hid_t ElementType = HDF5TypeAction<element_t>::getId();
323
324 string Domainname = H5ID::Domain<DomainType>::name();
325
326//printf("TYPEREGISTRY: Domain [%s] Element Type is %x\n", Domainname.c_str(), (int)ElementType);
327
328 ChartDomain_IDs*CD = F5B_new_global_domain(coordnames, ELEMENTS, ElementType, Domainname.c_str(), F5_FORTRAN_ORDER, RANK);
329
330 hid_t type_id = CD->Point_hid_t;
331 TA->addInterface( new H5ID( type_id ) );
332
333 RefPtr<F5Domain> f = new F5Domain( CD );
334 TA->addInterface( f );
335
336 return f;
337 }
338
339
340static RefPtr<F5Domain> makeDomainType()
341 {
342 enum { ELEMENTS = FiberPointType_t::FiberInfo_t::MULTIPLICITY };
343
344 const char*coordnames[ELEMENTS];
345 for(int i=0; i<ELEMENTS; i++)
346 {
347 coordnames[i] = PointType::coordinate_name(i);
348 }
349 return makeDomainType(coordnames);
350 }
351};
352*/
353
354
355
356} /* namespace Fiber */
357
358#endif /* __FIBER_HDF5_TYPEREGISTRY_HPP */
constexpr _InputIterator find(_InputIterator __first, _InputIterator __last, const _Tp &__val)
constexpr auto end(_Container &__cont) -> decltype(__cont.end())
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
Definition F5Domain.hpp:16
A database for mapping HDF5 Type ID's to and from FiberType's.
Definition TypeRegistry.hpp:31
Definition TypeRegistry.hpp:129
Definition H++/H5DataType.hpp:10
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
std::nullptr_t NullPtr
Definition FiberTypeIndex.hpp:12
Definition TypeRegistry.hpp:74
Convenience class that registers some HDF5 type ID for an intrinsic C++ type.
Definition TypeRegistry.hpp:144