HdfAttribute.cpp 3.8 KB

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