HdfAttribute.cpp 3.4 KB

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