-
Notifications
You must be signed in to change notification settings - Fork 5
/
udf_template.cpp
78 lines (66 loc) · 1.89 KB
/
udf_template.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// HDF5-UDF: User-Defined Functions for HDF5
//
// File: udf_template.cpp
//
// HDF5 filter callbacks and main interface with the C++ API.
//
#include <sys/types.h>
#include <stdarg.h>
#include <math.h>
#include <string>
#include <vector>
// The following variables are populated by our HDF5 filter
std::vector<void *> hdf5_udf_data;
std::vector<const char *> hdf5_udf_names;
std::vector<const char *> hdf5_udf_types;
std::vector<std::vector<size_t> > hdf5_udf_dims;
const char *hdf5_file_path;
// compound_declarations_placeholder
// This is the API that user-defined-functions use to retrieve
// datasets they depend on.
class UserDefinedLibrary
{
public:
const char *getFilePath();
template <class T> T *getData(std::string name);
const char *getType(std::string name);
std::vector<size_t> getDims(std::string name);
const char *string(const char *element);
// methods_declaration_placeholder
};
const char *UserDefinedLibrary::getFilePath()
{
return hdf5_file_path;
}
template <class T>
T *UserDefinedLibrary::getData(std::string name)
{
for (size_t i=0; i<hdf5_udf_names.size(); ++i)
if (name.compare(hdf5_udf_names[i]) == 0)
return static_cast<T *>(hdf5_udf_data[i]);
return NULL;
}
const char *UserDefinedLibrary::getType(std::string name)
{
for (size_t i=0; i<hdf5_udf_names.size(); ++i)
if (name.compare(hdf5_udf_names[i]) == 0)
return hdf5_udf_types[i];
return NULL;
}
std::vector<size_t> UserDefinedLibrary::getDims(std::string name)
{
std::vector<size_t> dims;
for (size_t i=0; i<hdf5_udf_names.size(); ++i)
if (name.compare(hdf5_udf_names[i]) == 0)
return hdf5_udf_dims[i];
return dims;
}
const char *UserDefinedLibrary::string(const char *element)
{
return element;
}
// methods_implementation_placeholder
UserDefinedLibrary lib;
// User-Defined Function
// user_callback_placeholder