From 55f3e713f23165d49be093d4c412b28ebfbdeaf2 Mon Sep 17 00:00:00 2001 From: Weile Wei Date: Thu, 6 Jun 2019 14:12:54 -0600 Subject: [PATCH] add read attributes support --- test_attributes.c | 9 ++++++++- z5wrapper.cc | 36 ++++++++++++++++++++++++++++++++++++ z5wrapper.h | 10 ++++++++-- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/test_attributes.c b/test_attributes.c index 43f6808..06d220c 100644 --- a/test_attributes.c +++ b/test_attributes.c @@ -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"); } diff --git a/z5wrapper.cc b/z5wrapper.cc index fd0f7b9..ce536e7 100644 --- a/z5wrapper.cc +++ b/z5wrapper.cc @@ -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 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 + } } } diff --git a/z5wrapper.h b/z5wrapper.h index 71cc6d5..27367f9 100644 --- a/z5wrapper.h +++ b/z5wrapper.h @@ -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); @@ -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 } }