HdfItem.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /// \copyright Copyright (c) Catalysts GmbH
  2. /// \author Patrik Kovacs, Catalysts GmbH
  3. #include <hdf4cpp/HdfFile.h>
  4. #include <hdf4cpp/HdfItem.h>
  5. #include <hdf4cpp/HdfAttribute_priv.h>
  6. #include <hdf/mfhdf.h>
  7. #include <sstream>
  8. hdf4cpp::HdfItem::HdfDatasetItem::HdfDatasetItem(int32 id, const HdfDestroyerChain& chain) : HdfItemBase(id, SDATA, chain) {
  9. _size = 1;
  10. std::for_each(dims.begin(), dims.end(), [this](const int32 &t) {
  11. _size *= t;
  12. });
  13. int32 dim[MAX_DIMENSION];
  14. int32 size;
  15. char _name[MAX_NAME_LENGTH];
  16. SDgetinfo(id, _name, &size, dim, &dataType, nullptr);
  17. dims = std::vector<int32>(dim, dim + size);
  18. name = std::string(_name);
  19. this->chain.pushBack(new HdfDestroyer(&SDendaccess, id));
  20. }
  21. std::vector<int32> hdf4cpp::HdfItem::HdfDatasetItem::getDims() {
  22. return dims;
  23. }
  24. hdf4cpp::HdfAttribute hdf4cpp::HdfItem::HdfDatasetItem::getAttribute(const std::string &name) const {
  25. return HdfAttribute(new HdfAttribute::HdfDatasetAttribute(id, name, chain));
  26. }
  27. std::string hdf4cpp::HdfItem::HdfDatasetItem::getName() const {
  28. return name;
  29. }
  30. int32 hdf4cpp::HdfItem::HdfDatasetItem::getId() const {
  31. return id;
  32. }
  33. int32 hdf4cpp::HdfItem::HdfDatasetItem::getDataType() const {
  34. return dataType;
  35. }
  36. hdf4cpp::HdfItem::HdfDatasetItem::~HdfDatasetItem() {
  37. }
  38. intn hdf4cpp::HdfItem::HdfDatasetItem::size() const {
  39. return _size;
  40. }
  41. hdf4cpp::HdfItem::HdfGroupItem::HdfGroupItem(int32 id, const HdfDestroyerChain& chain) : HdfItemBase(id, VGROUP, chain) {
  42. char _name[MAX_NAME_LENGTH];
  43. Vgetname(id, _name);
  44. name = std::string(_name);
  45. this->chain.pushBack(new HdfDestroyer(&Vdetach, id));
  46. }
  47. std::vector<int32> hdf4cpp::HdfItem::HdfGroupItem::getDims() {
  48. raiseException(INVALID_OPERATION);
  49. }
  50. hdf4cpp::HdfAttribute hdf4cpp::HdfItem::HdfGroupItem::getAttribute(const std::string &name) const {
  51. return HdfAttribute(new HdfAttribute::HdfGroupAttribute(id, name, chain));
  52. }
  53. std::string hdf4cpp::HdfItem::HdfGroupItem::getName() const {
  54. return name;
  55. }
  56. int32 hdf4cpp::HdfItem::HdfGroupItem::getId() const {
  57. return id;
  58. }
  59. hdf4cpp::HdfItem::HdfGroupItem::~HdfGroupItem() {
  60. }
  61. intn hdf4cpp::HdfItem::HdfGroupItem::size() const {
  62. raiseException(INVALID_OPERATION);
  63. }
  64. int32 hdf4cpp::HdfItem::HdfGroupItem::getDataType() const {
  65. raiseException(INVALID_OPERATION);
  66. }
  67. hdf4cpp::HdfItem::HdfDataItem::HdfDataItem(int32 id, const HdfDestroyerChain& chain) : HdfItemBase(id, VDATA, chain) {
  68. this->chain.pushBack(new HdfDestroyer(&VSdetach, id));
  69. char _name[MAX_NAME_LENGTH];
  70. VSinquire(id, &nrRecords, &interlace, nullptr, &recordSize, _name);
  71. name = std::string(_name);
  72. }
  73. hdf4cpp::HdfItem::HdfDataItem::~HdfDataItem() {
  74. }
  75. hdf4cpp::HdfAttribute hdf4cpp::HdfItem::HdfDataItem::getAttribute(const std::string &name) const {
  76. return HdfAttribute(new HdfAttribute::HdfDataAttribute(id, name, chain));
  77. }
  78. int32 hdf4cpp::HdfItem::HdfDataItem::getId() const {
  79. return id;
  80. }
  81. std::string hdf4cpp::HdfItem::HdfDataItem::getName() const {
  82. return name;
  83. }
  84. std::vector<int32> hdf4cpp::HdfItem::HdfDataItem::getDims() {
  85. raiseException(INVALID_OPERATION);
  86. }
  87. intn hdf4cpp::HdfItem::HdfDataItem::size() const {
  88. raiseException(INVALID_OPERATION);
  89. }
  90. int32 hdf4cpp::HdfItem::HdfDataItem::getDataType() const {
  91. return 0;
  92. }
  93. hdf4cpp::HdfItem::HdfItem(HdfItemBase *item, int32 sId, int32 vId) : HdfObject(item),
  94. item(item),
  95. sId(sId),
  96. vId(vId) {}
  97. hdf4cpp::HdfItem::HdfItem(HdfItem&& other) : HdfObject(other.getType(), other.getClassType(), std::move(other.chain)),
  98. item(std::move(other.item)),
  99. sId(other.sId),
  100. vId(other.vId) {}
  101. hdf4cpp::HdfItem& hdf4cpp::HdfItem::operator=(HdfItem&& it) {
  102. item = std::move(it.item);
  103. return *this;
  104. }
  105. std::vector<int32> hdf4cpp::HdfItem::getDims() {
  106. return item->getDims();
  107. }
  108. hdf4cpp::HdfAttribute hdf4cpp::HdfItem::getAttribute(const std::string &name) const {
  109. return item->getAttribute(name);
  110. }
  111. std::string hdf4cpp::HdfItem::getName() const {
  112. return item->getName();
  113. }
  114. intn hdf4cpp::HdfItem::size() const {
  115. return item->size();
  116. }
  117. hdf4cpp::HdfItem::Iterator hdf4cpp::HdfItem::begin() const {
  118. return Iterator(sId, vId, item->getId(), 0, getType(), chain);
  119. }
  120. hdf4cpp::HdfItem::Iterator hdf4cpp::HdfItem::end() const {
  121. switch(item->getType()) {
  122. case VGROUP: {
  123. int32 size = Vntagrefs(item->getId());
  124. return Iterator(sId, vId, item->getId(), size, getType(), chain);
  125. }
  126. default: {
  127. return Iterator(sId, vId, item->getId(), 0, getType(), chain);
  128. }
  129. }
  130. }