Skip to content

Commit

Permalink
add read attributes support
Browse files Browse the repository at this point in the history
  • Loading branch information
weilewei committed Jun 6, 2019
1 parent 2baa5a0 commit 55f3e71
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
9 changes: 8 additions & 1 deletion test_attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ void my_create_dataset(char* arrayName)

short shortint = 42;
z5writeAttributesshort(arrayName, "short", &shortint);


// testing read all attributes
z5readAttributes(arrayName);

// testing read attributes by providing keys
char *keysinput[2] = {"uint", "double"};
z5readAttributesWithKeys(arrayName, keysinput, 2);

printf("after assert\n");
}

Expand Down
36 changes: 36 additions & 0 deletions z5wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,43 @@ namespace z5 {
fs::path filename(path_s);
fs::remove_all(filename);
}

// read attributes //
void z5readAttributesWithKeys(char *path, char *keys[], int keys_sz)
{
std::string path_s(path);
bool asZarr = true;
handle::Handle cHandle(path_s);
nlohmann::json j;
std::vector<std::string> keys_s;
for (size_t i = 0; i < keys_sz; i++)
{
std::string keys_tmp(keys[i]);
keys_s.push_back(keys_tmp);
}
readAttributes(cHandle, keys_s, j);
#ifdef _JASON_OUTPUT_
for (auto it = j.begin(); it != j.end(); ++it)
{
std::cout << "key: " << it.key() << ", value:" << it.value() << '\n';
}
#endif
}

void z5readAttributes(char *path)
{
std::string path_s(path);
bool asZarr = true;
handle::Handle cHandle(path_s);
nlohmann::json j;
readAttributes(cHandle, j);
#ifdef _JASON_OUTPUT_
for (auto it = j.begin(); it != j.end(); ++it)
{
std::cout << "key: " << it.key() << ", value:" << it.value() << '\n';
}
#endif
}
}

}
10 changes: 8 additions & 2 deletions z5wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ namespace z5 {

size_t z5GetFileSize(char *path);

void z5Delete(char *path );

void z5writeAttributesString(char *path, const char *name, const char *value);

void z5writeAttributesshort(char *path, const char *name, const short *value);
Expand All @@ -61,8 +63,12 @@ namespace z5 {
void z5writeAttributesulonglong(char *path, const char *name, const unsigned long long *value);

void z5writeAttributesuint(char *path, const char *name, const unsigned int *value);

void z5Delete(char *path );

// read attributes //

void z5readAttributesWithKeys(char *path, char *keys[], int keys_sz);

void z5readAttributes(char *path);
#ifdef __cplusplus
}
}
Expand Down

0 comments on commit 55f3e71

Please sign in to comment.