|
@@ -4,10 +4,9 @@
|
|
|
|
|
|
#include <hdf4cpp/HdfItem.h>
|
|
#include <hdf4cpp/HdfItem.h>
|
|
#include <hdf/mfhdf.h>
|
|
#include <hdf/mfhdf.h>
|
|
-#include <algorithm>
|
|
+#include <sstream>
|
|
-#include <iostream>
|
|
|
|
|
|
|
|
-HdfDatasetItem::HdfDatasetItem(int32 id) : HdfItemBase(id) {
|
|
+hdf4cpp::HdfDatasetItem::HdfDatasetItem(int32 id) : HdfItemBase(id) {
|
|
if(id == FAIL) {
|
|
if(id == FAIL) {
|
|
_size = FAIL;
|
|
_size = FAIL;
|
|
} else {
|
|
} else {
|
|
@@ -23,119 +22,144 @@ HdfDatasetItem::HdfDatasetItem(int32 id) : HdfItemBase(id) {
|
|
name = std::string(_name);
|
|
name = std::string(_name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-std::vector<int32> HdfDatasetItem::getDims() {
|
|
+std::vector<int32> hdf4cpp::HdfDatasetItem::getDims() {
|
|
int32 dims[MAX_DIMENSION];
|
|
int32 dims[MAX_DIMENSION];
|
|
int32 size, dataType, nrAtt;
|
|
int32 size, dataType, nrAtt;
|
|
char name[MAX_NAME_LENGTH];
|
|
char name[MAX_NAME_LENGTH];
|
|
SDgetinfo(id, name, &size, dims, &dataType, &nrAtt);
|
|
SDgetinfo(id, name, &size, dims, &dataType, &nrAtt);
|
|
return std::vector<int32>(dims, dims + size);
|
|
return std::vector<int32>(dims, dims + size);
|
|
}
|
|
}
|
|
-bool HdfDatasetItem::read(void *dest, const std::vector<Range>& ranges) {
|
|
+hdf4cpp::HdfAttribute hdf4cpp::HdfDatasetItem::getAttribute(const std::string &name) {
|
|
- std::vector<int32> start, quantity, stride;
|
|
|
|
- for(const auto& range : ranges) {
|
|
|
|
- start.push_back(range.begin);
|
|
|
|
- quantity.push_back(range.quantity);
|
|
|
|
- stride.push_back(range.stride);
|
|
|
|
- }
|
|
|
|
- return SDreaddata(id, start.data(), stride.data(), quantity.data(), dest) != FAIL;
|
|
|
|
-}
|
|
|
|
-HdfAttribute HdfDatasetItem::getAttribute(const std::string &name) {
|
|
|
|
return HdfAttribute(new HdfDatasetAttribute(id, name));
|
|
return HdfAttribute(new HdfDatasetAttribute(id, name));
|
|
}
|
|
}
|
|
-Type HdfDatasetItem::getType() const {
|
|
+hdf4cpp::Type hdf4cpp::HdfDatasetItem::getType() const {
|
|
- return DATASET;
|
|
+ return SDATA;
|
|
}
|
|
}
|
|
-std::string HdfDatasetItem::getName() const {
|
|
+std::string hdf4cpp::HdfDatasetItem::getName() const {
|
|
return name;
|
|
return name;
|
|
}
|
|
}
|
|
-int32 HdfDatasetItem::getId() const {
|
|
+int32 hdf4cpp::HdfDatasetItem::getId() const {
|
|
return id;
|
|
return id;
|
|
}
|
|
}
|
|
-int32 HdfDatasetItem::getDataType() const {
|
|
+int32 hdf4cpp::HdfDatasetItem::getDataType() const {
|
|
return dataType;
|
|
return dataType;
|
|
}
|
|
}
|
|
-HdfDatasetItem::~HdfDatasetItem() {
|
|
+hdf4cpp::HdfDatasetItem::~HdfDatasetItem() {
|
|
if(isValid()) {
|
|
if(isValid()) {
|
|
SDendaccess(id);
|
|
SDendaccess(id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-intn HdfDatasetItem::size() const {
|
|
+intn hdf4cpp::HdfDatasetItem::size() const {
|
|
return _size;
|
|
return _size;
|
|
}
|
|
}
|
|
-HdfGroupItem::HdfGroupItem(int32 id) : HdfItemBase(id) {
|
|
+hdf4cpp::HdfGroupItem::HdfGroupItem(int32 id) : HdfItemBase(id) {
|
|
char _name[MAX_NAME_LENGTH];
|
|
char _name[MAX_NAME_LENGTH];
|
|
Vgetname(id, _name);
|
|
Vgetname(id, _name);
|
|
name = std::string(_name);
|
|
name = std::string(_name);
|
|
}
|
|
}
|
|
-std::vector<int32> HdfGroupItem::getDims() {
|
|
+std::vector<int32> hdf4cpp::HdfGroupItem::getDims() {
|
|
throw std::runtime_error("HDF4CPP: getDims not defined for HdfGroupItem");
|
|
throw std::runtime_error("HDF4CPP: getDims not defined for HdfGroupItem");
|
|
}
|
|
}
|
|
-bool HdfGroupItem::read(void *, const std::vector<Range>&) {
|
|
+hdf4cpp::HdfAttribute hdf4cpp::HdfGroupItem::getAttribute(const std::string &name) {
|
|
- throw std::runtime_error("HDF4CPP: read not defined for HdfGroupItem");
|
|
|
|
-}
|
|
|
|
-HdfAttribute HdfGroupItem::getAttribute(const std::string &name) {
|
|
|
|
return HdfAttribute(new HdfGroupAttribute(id, name));
|
|
return HdfAttribute(new HdfGroupAttribute(id, name));
|
|
}
|
|
}
|
|
-Type HdfGroupItem::getType() const {
|
|
+hdf4cpp::Type hdf4cpp::HdfGroupItem::getType() const {
|
|
- return GROUP;
|
|
+ return VGROUP;
|
|
}
|
|
}
|
|
-std::string HdfGroupItem::getName() const {
|
|
+std::string hdf4cpp::HdfGroupItem::getName() const {
|
|
return name;
|
|
return name;
|
|
}
|
|
}
|
|
-int32 HdfGroupItem::getId() const {
|
|
+int32 hdf4cpp::HdfGroupItem::getId() const {
|
|
return id;
|
|
return id;
|
|
}
|
|
}
|
|
-HdfGroupItem::~HdfGroupItem() {
|
|
+hdf4cpp::HdfGroupItem::~HdfGroupItem() {
|
|
if(isValid()) {
|
|
if(isValid()) {
|
|
Vdetach(id);
|
|
Vdetach(id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-intn HdfGroupItem::size() const {
|
|
+intn hdf4cpp::HdfGroupItem::size() const {
|
|
throw std::runtime_error("HdfFile: read not defined for HdfGroupItem");
|
|
throw std::runtime_error("HdfFile: read not defined for HdfGroupItem");
|
|
}
|
|
}
|
|
-int32 HdfGroupItem::getDataType() const {
|
|
+int32 hdf4cpp::HdfGroupItem::getDataType() const {
|
|
throw std::runtime_error("HDF4CPP: no data type for HdfGroup");
|
|
throw std::runtime_error("HDF4CPP: no data type for HdfGroup");
|
|
}
|
|
}
|
|
-HdfItem::HdfItem(HdfItem&& other) : item(std::move(other.item)), sId(other.sId), vId(other.vId) {
|
|
+hdf4cpp::HdfDataItem::HdfDataItem(int32 id) : HdfItemBase(id) {
|
|
|
|
+ char fieldNameList[MAX_NAME_LENGTH];
|
|
|
|
+ char _name[MAX_NAME_LENGTH];
|
|
|
|
+ VSinquire(id, &nrRecords, &interlace, fieldNameList, &recordSize, _name);
|
|
|
|
+ name = std::string(_name);
|
|
|
|
+ std::istringstream in(fieldNameList);
|
|
|
|
+ std::string token;
|
|
|
|
+ while(getline(in, token, ',')) {
|
|
|
|
+ fieldNames.push_back(token);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+hdf4cpp::HdfDataItem::~HdfDataItem() {
|
|
|
|
+ if(isValid()) {
|
|
|
|
+ Vdetach(id);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+hdf4cpp::Type hdf4cpp::HdfDataItem::getType() const {
|
|
|
|
+ return VDATA;
|
|
|
|
+}
|
|
|
|
+int32 hdf4cpp::HdfDataItem::getId() const {
|
|
|
|
+ return id;
|
|
|
|
+}
|
|
|
|
+std::string hdf4cpp::HdfDataItem::getName() const {
|
|
|
|
+ return name;
|
|
|
|
+}
|
|
|
|
+std::vector<int32> hdf4cpp::HdfDataItem::getDims() {
|
|
|
|
+ std::vector<int32> dims;
|
|
|
|
+ dims.push_back(nrRecords);
|
|
|
|
+ dims.push_back((int32) fieldNames.size());
|
|
|
|
+ return dims;
|
|
|
|
+}
|
|
|
|
+intn hdf4cpp::HdfDataItem::size() const {
|
|
|
|
+ return nrRecords * (int32) fieldNames.size();
|
|
|
|
+}
|
|
|
|
+int32 hdf4cpp::HdfDataItem::getDataType() const {
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+hdf4cpp::HdfItem::HdfItem(HdfItem&& other) : item(std::move(other.item)), sId(other.sId), vId(other.vId) {
|
|
}
|
|
}
|
|
-std::vector<int32> HdfItem::getDims() {
|
|
+std::vector<int32> hdf4cpp::HdfItem::getDims() {
|
|
if(isValid()) {
|
|
if(isValid()) {
|
|
return item->getDims();
|
|
return item->getDims();
|
|
} else {
|
|
} else {
|
|
return std::vector<int32>();
|
|
return std::vector<int32>();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-HdfAttribute HdfItem::getAttribute(const std::string &name) {
|
|
+hdf4cpp::HdfAttribute hdf4cpp::HdfItem::getAttribute(const std::string &name) {
|
|
return item->getAttribute(name);
|
|
return item->getAttribute(name);
|
|
}
|
|
}
|
|
-Type HdfItem::getType() const {
|
|
+hdf4cpp::Type hdf4cpp::HdfItem::getType() const {
|
|
if(isValid()) {
|
|
if(isValid()) {
|
|
return item->getType();
|
|
return item->getType();
|
|
} else {
|
|
} else {
|
|
return NONE;
|
|
return NONE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-std::string HdfItem::getName() const {
|
|
+std::string hdf4cpp::HdfItem::getName() const {
|
|
if(isValid()) {
|
|
if(isValid()) {
|
|
return item->getName();
|
|
return item->getName();
|
|
} else {
|
|
} else {
|
|
return std::string();
|
|
return std::string();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-bool HdfItem::isValid() const {
|
|
+bool hdf4cpp::HdfItem::isValid() const {
|
|
return item && item->isValid();
|
|
return item && item->isValid();
|
|
}
|
|
}
|
|
-intn HdfItem::size() const {
|
|
+intn hdf4cpp::HdfItem::size() const {
|
|
if(isValid()) {
|
|
if(isValid()) {
|
|
return item->size();
|
|
return item->size();
|
|
} else {
|
|
} else {
|
|
return FAIL;
|
|
return FAIL;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-HdfItem::Iterator HdfItem::begin() const {
|
|
+hdf4cpp::HdfItem::Iterator hdf4cpp::HdfItem::begin() const {
|
|
return Iterator(sId, vId, item->getId(), 0);
|
|
return Iterator(sId, vId, item->getId(), 0);
|
|
}
|
|
}
|
|
-HdfItem::Iterator HdfItem::end() const {
|
|
+hdf4cpp::HdfItem::Iterator hdf4cpp::HdfItem::end() const {
|
|
int32 size = Vntagrefs(item->getId());
|
|
int32 size = Vntagrefs(item->getId());
|
|
if(size == FAIL) {
|
|
if(size == FAIL) {
|
|
return Iterator(sId, vId, item->getId(), 0);
|
|
return Iterator(sId, vId, item->getId(), 0);
|