HdfItem.cpp 4.7 KB

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