HdfItem.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /// \copyright Copyright (c) Catalysts GmbH
  2. /// \author Patrik Kovacs, Catalysts GmbH
  3. #include <hdf/mfhdf.h>
  4. #include <hdf4cpp/HdfAttribute_priv.h>
  5. #include <hdf4cpp/HdfFile.h>
  6. #include <hdf4cpp/HdfItem.h>
  7. #include <sstream>
  8. hdf4cpp::HdfItem::HdfDatasetItem::HdfDatasetItem(int32 id, const HdfDestroyerChain &chain)
  9. : HdfItemBase(id, SDATA, chain) {
  10. _size = 1;
  11. std::for_each(dims.begin(), dims.end(), [this](const int32 &t) { _size *= t; });
  12. int32 dim[MAX_DIMENSION];
  13. int32 size;
  14. char _name[MAX_NAME_LENGTH];
  15. SDgetinfo(id, _name, &size, dim, &dataType, nullptr);
  16. dims = std::vector<int32>(dim, dim + size);
  17. name = std::string(_name);
  18. this->chain.pushBack(new HdfDestroyer(&SDendaccess, id));
  19. }
  20. std::vector<int32> hdf4cpp::HdfItem::HdfDatasetItem::getDims() {
  21. return dims;
  22. }
  23. hdf4cpp::HdfAttribute hdf4cpp::HdfItem::HdfDatasetItem::getAttribute(const std::string &name) const {
  24. return HdfAttribute(new HdfAttribute::HdfDatasetAttribute(id, name, chain));
  25. }
  26. std::string hdf4cpp::HdfItem::HdfDatasetItem::getName() const {
  27. return name;
  28. }
  29. int32 hdf4cpp::HdfItem::HdfDatasetItem::getId() const {
  30. return id;
  31. }
  32. int32 hdf4cpp::HdfItem::HdfDatasetItem::getDataType() const {
  33. return dataType;
  34. }
  35. hdf4cpp::HdfItem::HdfDatasetItem::~HdfDatasetItem() {
  36. }
  37. intn hdf4cpp::HdfItem::HdfDatasetItem::size() const {
  38. return _size;
  39. }
  40. hdf4cpp::HdfItem::HdfGroupItem::HdfGroupItem(int32 id, const HdfDestroyerChain &chain)
  41. : 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)
  68. : 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)
  95. : HdfObject(item)
  96. , item(item)
  97. , sId(sId)
  98. , vId(vId) {
  99. }
  100. hdf4cpp::HdfItem::HdfItem(HdfItem &&other)
  101. : HdfObject(other.getType(), other.getClassType(), std::move(other.chain))
  102. , item(std::move(other.item))
  103. , sId(other.sId)
  104. , vId(other.vId) {
  105. }
  106. hdf4cpp::HdfItem &hdf4cpp::HdfItem::operator=(HdfItem &&it) {
  107. item = std::move(it.item);
  108. return *this;
  109. }
  110. std::vector<int32> hdf4cpp::HdfItem::getDims() {
  111. return item->getDims();
  112. }
  113. hdf4cpp::HdfAttribute hdf4cpp::HdfItem::getAttribute(const std::string &name) const {
  114. return item->getAttribute(name);
  115. }
  116. std::string hdf4cpp::HdfItem::getName() const {
  117. return item->getName();
  118. }
  119. intn hdf4cpp::HdfItem::size() const {
  120. return item->size();
  121. }
  122. hdf4cpp::HdfItem::Iterator hdf4cpp::HdfItem::begin() const {
  123. return Iterator(sId, vId, item->getId(), 0, getType(), chain);
  124. }
  125. hdf4cpp::HdfItem::Iterator hdf4cpp::HdfItem::end() const {
  126. switch (item->getType()) {
  127. case VGROUP: {
  128. int32 size = Vntagrefs(item->getId());
  129. return Iterator(sId, vId, item->getId(), size, getType(), chain);
  130. }
  131. default: { return Iterator(sId, vId, item->getId(), 0, getType(), chain); }
  132. }
  133. }