Skip to content

Commit

Permalink
added handling reference attributes. Beginning handling enum datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
rimmartin committed Jun 20, 2018
1 parent 48b6916 commit a7793cc
Show file tree
Hide file tree
Showing 16 changed files with 288 additions and 53 deletions.
15 changes: 12 additions & 3 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'src/methods.cc',
'src/h5_file.cc',
'src/h5_group.cc',
'src/reference.cc'
],
'link_settings': {
'libraries': [
Expand Down Expand Up @@ -57,6 +58,7 @@
'src/methods.cc',
'src/h5_file.cc',
'src/h5_group.cc',
'src/reference.cc'
],
'msbuild_toolset': 'v120',
"configurations": {
Expand Down Expand Up @@ -109,6 +111,7 @@
'src/methods.cc',
'src/h5_file.cc',
'src/h5_group.cc',
'src/reference.cc'
],
'link_settings': {
'libraries': [
Expand Down Expand Up @@ -137,7 +140,9 @@
"/usr/include/hdf5/serial"
],
'sources': [
'src/h5lt.cc'
'src/int64.cc',
'src/h5lt.cc',
'src/reference.cc'
],
'link_settings': {
'libraries': [
Expand All @@ -161,7 +166,9 @@
'C:/Program Files/Microsoft SDKs/Windows/v7.1/Include'
],
'sources': [
'src/h5lt.cc'
'src/int64.cc',
'src/h5lt.cc',
'src/reference.cc'
],
'msbuild_toolset': 'v120',
"configurations": {
Expand Down Expand Up @@ -205,7 +212,9 @@
'<(hdf5_home_mac)/include'
],
'sources': [
'src/h5lt.cc'
'src/int64.cc',
'src/h5lt.cc',
'src/reference.cc'
],
'link_settings': {
'libraries': [
Expand Down
10 changes: 9 additions & 1 deletion lib/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,15 @@ export declare enum H5Type {
H5T_NATIVE_UINT8,
}

export declare enum H5RType {
H5R_BADTYPE = -1, /*invalid Reference Type */
H5R_OBJECT = 0, /*Object reference */
H5R_DATASET_REGION = 1, /*Dataset Region Reference */
H5R_MAXTYPE = 2 /*highest type (Invalid as true type) */
}


export declare enum Interlace {
INTERLACE_PIXEL,
INTERLACE_PLANE
}
}
7 changes: 7 additions & 0 deletions lib/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ module.exports.H5Type = {
H5T_NATIVE_UINT8 : 315
}

module.exports.H5RType ={
H5R_BADTYPE : (-1), /*invalid Reference Type */
H5R_OBJECT : 0, /*Object reference */
H5R_DATASET_REGION : 1, /*Dataset Region Reference */
H5R_MAXTYPE : 2 /*highest type (Invalid as true type) */
}

module.exports.Interlace = {
INTERLACE_PIXEL : "INTERLACE_PIXEL",
INTERLACE_PLANE : "INTERLACE_PLANE"
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var group = file.openGroup('bar');
### Notes on Recent Releases

* Note: Release v0.3.4
* Reference attributes on datasets and groups are now available properties.
* Reserved propeties such as type, rank, rows etc. are now settable in options for dataset functions.
* Typescript definition files now available.
* For static native linkng, link_type command line switch is provided in binding.gyp(darwin,win untested).
Expand Down
1 change: 1 addition & 0 deletions src/attributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "hdf5.h"
#include "hdf5_hl.h"

#include "reference.hpp"
#include "attributes.hpp"

namespace NodeHDF5 {
Expand Down
9 changes: 9 additions & 0 deletions src/attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cstring>
#include <vector>
#include <memory>

#include "H5Tpublic.h"
#include "int64.hpp"
#include "uint64.hpp"
Expand Down Expand Up @@ -39,6 +40,14 @@ namespace NodeHDF5 {
hssize_t numberOfElements = H5Sget_simple_extent_npoints(space);
H5T_class_t class_id = H5Tget_class(attr_type);
switch (class_id) {
case H5T_REFERENCE:{
std::unique_ptr<char[]> buf(new char[H5Aget_storage_size(attr_id)]);
H5Aread(attr_id, attr_type, buf.get());
hid_t objectId=((hid_t*)buf.get())[0];
v8::Local<v8::Object>&& ref = Reference::Instantiate(objectId, 1);
focus->Set(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), holder[index].c_str()), ref);
}
break;
case H5T_ARRAY: {
hid_t basetype_id = H5Tget_super(attr_type);
if (H5Tis_variable_str(basetype_id)>0) {
Expand Down
1 change: 1 addition & 0 deletions src/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "hdf5_hl.h"

#include "exceptions.hpp"
#include "reference.hpp"
#include "attributes.hpp"
#include "methods.hpp"

Expand Down
72 changes: 24 additions & 48 deletions src/h5_lt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ namespace NodeHDF5 {
}
H5Tclose(t);
H5Dclose(h);
} else if (class_id == H5T_INTEGER && bufSize == 2) {
} else if ((class_id == H5T_INTEGER || class_id == H5T_ENUM) && bufSize == 2) {
hid_t h = H5Dopen(idWrap->Value(), *dset_name, H5P_DEFAULT);
hid_t t = H5Dget_type(h);
if (H5Tget_sign(H5Dget_type(h)) == H5T_SGN_2) {
Expand Down Expand Up @@ -1458,6 +1458,27 @@ namespace NodeHDF5 {
options->Set(String::NewFromUtf8(v8::Isolate::GetCurrent(), "rows"), Number::New(v8::Isolate::GetCurrent(), values_dim.get()[0]));
break;
}
if(class_id == H5T_ENUM){
v8::Local<v8::Object> enumeration = v8::Object::New(v8::Isolate::GetCurrent());

hid_t h = H5Dopen(idWrap->Value(), *dset_name, H5P_DEFAULT);
hid_t t = H5Dget_type(h);
int n=H5Tget_nmembers( t );
for(unsigned int i=0;i<(unsigned int)n;i++){
char * mname=H5Tget_member_name( t, i );
int idx=H5Tget_member_index(t, (const char *) mname );
unsigned int value;
H5Tget_member_value( t, idx, (void *)&value );
//std::cout<<i<<" "<<value<<std::endl;
hsize_t dvalue=value;
enumeration->Set(String::NewFromUtf8(v8::Isolate::GetCurrent(), mname), Number::New(v8::Isolate::GetCurrent(), dvalue));
H5free_memory((void *)mname);
}
H5Tclose(t);
H5Dclose(h);
options->Set(String::NewFromUtf8(v8::Isolate::GetCurrent(), "enumeration"), enumeration);

}
v8::Local<v8::Value> argv[1] = {options};
v8::Local<v8::Function>::New(v8::Isolate::GetCurrent(), callback)
->Call(v8::Isolate::GetCurrent()->GetCurrentContext()->Global(), argc, argv);
Expand Down Expand Up @@ -1709,56 +1730,11 @@ namespace NodeHDF5 {
}
H5Tclose( type_id);
v8::Local<v8::Object> focus=buffer->ToObject();
// Attributes
refreshAttributes(focus, did);
H5Dclose(did);

// Attributes
/* uint32_t index = 0;
hsize_t idx = 0;
std::vector<std::string> holder;
H5Aiterate_by_name(idWrap->Value(),
*dset_name,
H5_INDEX_CRT_ORDER,
H5_ITER_INC,
&idx,
[](hid_t location_id, const char* attr_name, const H5A_info_t* ainfo, void* operator_data) {
if (ainfo->data_size > 0)
((std::vector<std::string>*)operator_data)->push_back(std::string(attr_name));
return (herr_t)((std::vector<std::string>*)operator_data)->size();
},
(void*)&holder,
H5P_DEFAULT);
for (index = 0; index < (uint32_t)holder.size(); index++) {
hsize_t values_dim[1] = {1};
size_t bufSize = 0;
H5T_class_t class_id;
err = H5LTget_attribute_info(idWrap->Value(), *dset_name, holder[index].c_str(), values_dim, &class_id, &bufSize);
if (err >= 0) {
switch (class_id) {
case H5T_INTEGER:
long long intValue;
H5LTget_attribute_int(idWrap->Value(), *dset_name, holder[index].c_str(), (int*)&intValue);
buffer->Set(String::NewFromUtf8(v8::Isolate::GetCurrent(), holder[index].c_str()),
Int32::New(v8::Isolate::GetCurrent(), intValue));
break;
case H5T_FLOAT:
double value;
H5LTget_attribute_double(idWrap->Value(), *dset_name, holder[index].c_str(), &value);
buffer->Set(String::NewFromUtf8(v8::Isolate::GetCurrent(), holder[index].c_str()),
Number::New(v8::Isolate::GetCurrent(), value));
break;
case H5T_STRING: {
std::string strValue(bufSize + 1, '\0');
H5LTget_attribute_string(idWrap->Value(), *dset_name, holder[index].c_str(), (char*)strValue.c_str());
buffer->Set(String::NewFromUtf8(v8::Isolate::GetCurrent(), holder[index].c_str()),
String::NewFromUtf8(v8::Isolate::GetCurrent(), strValue.c_str()));
} break;
case H5T_NO_CLASS:
default: break;
}
}
}
*/

args.GetReturnValue().Set(buffer);
} break;
default:
Expand Down
3 changes: 3 additions & 0 deletions src/h5lt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "file.h"
#include "group.h"
#include "h5_lt.hpp"
#include "reference.hpp"

using namespace v8;
using namespace NodeHDF5;
Expand All @@ -14,7 +15,9 @@ static void init_lt(Handle<Object> target) {
HandleScope scope(v8::Isolate::GetCurrent());

// initialize wrapped objects
Int64::Initialize(target);
H5lt::Initialize(target);
Reference::Init(target);
}

NODE_MODULE(h5lt, init_lt)
Expand Down
2 changes: 2 additions & 0 deletions src/hdf5.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "file.h"
#include "group.h"
#include "filters.hpp"
#include "reference.hpp"
#include "hdf5node.hpp"

using namespace v8;
Expand All @@ -20,6 +21,7 @@ static void init(Handle<Object> target) {
// initialize wrapped objects
File::Initialize(target);
Filters::Init(target);
Reference::Init(target);
Int64::Initialize(target);
Uint64::Initialize(target);

Expand Down
1 change: 1 addition & 0 deletions src/int64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace NodeHDF5 {
friend class Group;
friend class Filters;
friend class Attributes;
friend class Reference;
friend class PacketTable;

protected:
Expand Down
12 changes: 11 additions & 1 deletion src/methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#include "hdf5.h"
#include "hdf5_hl.h"

#include "reference.hpp"
#include "attributes.hpp"
#include "methods.hpp"
#include "filters.hpp"

#include "H5LTpublic.h"
#include "H5PTpublic.h"
#include "H5Lpublic.h"
Expand Down Expand Up @@ -343,7 +345,15 @@ namespace NodeHDF5 {
switch (H5Tget_class(attr_type)) {
case H5T_BITFIELD:
case H5T_OPAQUE:
case H5T_REFERENCE:
break;
case H5T_REFERENCE:{
std::unique_ptr<char[]> buf(new char[H5Aget_storage_size(attr_id)]);
H5Aread(attr_id, attr_type, buf.get());
hid_t objectId=((hid_t*)buf.get())[0];
v8::Local<v8::Object>&& ref = Reference::Instantiate(objectId, 1);
attrs->Set(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), attrName.c_str()), ref);
}
break;
case H5T_ARRAY:
case H5T_ENUM: break;
case H5T_COMPOUND: {
Expand Down
9 changes: 9 additions & 0 deletions src/reference.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <v8.h>
#include <node.h>

#include "reference.hpp"

namespace NodeHDF5 {
v8::Persistent<v8::Function> Reference::Constructor;
}

Loading

0 comments on commit a7793cc

Please sign in to comment.