Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add read attributes support #2

Merged
merged 1 commit into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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