HdfAttribute.cpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // Created by patrik on 11.08.17.
  3. //
  4. #include <hdf4cpp/HdfDefines.h>
  5. #include <hdf4cpp/HdfAttribute_priv.h>
  6. #include <stdexcept>
  7. using namespace hdf4cpp;
  8. hdf4cpp::HdfAttribute::HdfDatasetAttribute::HdfDatasetAttribute(int32 id, const std::string& name, const HdfDestroyerChain& chain) : HdfAttributeBase(id, SDfindattr(id, name.c_str()), SDATA, chain) {
  9. char waste[MAX_NAME_LENGTH];
  10. if(SDattrinfo(id, index, waste, &dataType, &_size) == FAIL) {
  11. raiseException(STATUS_RETURN_FAIL);
  12. }
  13. }
  14. intn hdf4cpp::HdfAttribute::HdfDatasetAttribute::size() const {
  15. return _size;
  16. }
  17. int32 hdf4cpp::HdfAttribute::HdfDatasetAttribute::getDataType() const {
  18. return dataType;
  19. }
  20. void hdf4cpp::HdfAttribute::HdfDatasetAttribute::get(void *dest) {
  21. int32 nrValues;
  22. char nameRet[MAX_NAME_LENGTH];
  23. int32 status = SDattrinfo(id, index, nameRet, &dataType, &nrValues);
  24. if(status == FAIL) {
  25. raiseException(STATUS_RETURN_FAIL);
  26. }
  27. if(SDreadattr(id, index, dest) == FAIL) {
  28. raiseException(STATUS_RETURN_FAIL);
  29. }
  30. }
  31. hdf4cpp::HdfAttribute::HdfGroupAttribute::HdfGroupAttribute(int32 id, const std::string& name, const HdfDestroyerChain& chain) : HdfAttributeBase(id, 0, VGROUP, chain) {
  32. int32 nrAtts = Vnattrs2(id);
  33. for(intn i = 0; i < nrAtts; ++i) {
  34. char names[MAX_NAME_LENGTH];
  35. int32 type, count, size, nFields;
  36. uint16 refNum;
  37. Vattrinfo2(id, i, names, &type, &count, &size, &nFields, &refNum);
  38. if(name == std::string(names)) {
  39. index = i;
  40. _size = count;
  41. dataType = type;
  42. return;
  43. }
  44. }
  45. raiseException(INVALID_NAME);
  46. }
  47. intn hdf4cpp::HdfAttribute::HdfGroupAttribute::size() const {
  48. return _size;
  49. }
  50. int32 hdf4cpp::HdfAttribute::HdfGroupAttribute::getDataType() const {
  51. return dataType;
  52. }
  53. void hdf4cpp::HdfAttribute::HdfGroupAttribute::get(void *dest) {
  54. if(Vgetattr2(id, index, dest) == FAIL) {
  55. raiseException(STATUS_RETURN_FAIL);
  56. }
  57. }
  58. hdf4cpp::HdfAttribute::HdfDataAttribute::HdfDataAttribute(int32 id, const std::string &name, const HdfDestroyerChain& chain) : HdfAttributeBase(id, VSfindattr(id, _HDF_VDATA, name.c_str()), VDATA, chain) {
  59. if(VSattrinfo(id, _HDF_VDATA, index, nullptr, &dataType, &_size, nullptr) == FAIL) {
  60. raiseException(STATUS_RETURN_FAIL);
  61. }
  62. }
  63. intn hdf4cpp::HdfAttribute::HdfDataAttribute::size() const {
  64. return _size;
  65. }
  66. void hdf4cpp::HdfAttribute::HdfDataAttribute::get(void *dest) {
  67. if(VSgetattr(id, _HDF_VDATA, index, dest) == FAIL) {
  68. raiseException(STATUS_RETURN_FAIL);
  69. }
  70. }
  71. int32 hdf4cpp::HdfAttribute::HdfDataAttribute::getDataType() const {
  72. return dataType;
  73. }
  74. hdf4cpp::HdfAttribute::HdfAttribute(HdfAttribute &&other) : HdfObject(other.getType(), other.getClassType(), std::move(other.chain)), attribute(std::move(other.attribute)) {
  75. }
  76. hdf4cpp::HdfAttribute& hdf4cpp::HdfAttribute::operator=(HdfAttribute&& attr) {
  77. attribute = std::move(attr.attribute);
  78. setType(attribute->getType());
  79. setClassType(attribute->getClassType());
  80. return *this;
  81. }
  82. intn hdf4cpp::HdfAttribute::size() const {
  83. return attribute->size();
  84. }
  85. HdfAttribute::HdfAttribute(HdfAttributeBase* attribute) : HdfObject(attribute), attribute(attribute) {
  86. }
  87. int32 HdfAttribute::getDataType() const {
  88. return attribute->getDataType();
  89. }
  90. void HdfAttribute::getInternal(void* dest) {
  91. attribute->get(dest);
  92. }