HdfItem.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /// \copyright Copyright (c) Catalysts GmbH
  2. /// \author Patrik Kovacs, Catalysts GmbH
  3. #include <hdf4cpp/HdfAttribute.h>
  4. #include <hdf4cpp/HdfFile.h>
  5. #include <hdf4cpp/HdfItem.h>
  6. #include <mfhdf.h>
  7. #include <numeric>
  8. #include <sstream>
  9. hdf4cpp::HdfItem::HdfDatasetItem::HdfDatasetItem(int32 id, const HdfDestroyerChain &chain)
  10. : HdfItemBase(id, SDATA, chain) {
  11. int32 dim[MAX_DIMENSION];
  12. int32 size;
  13. char _name[MAX_NAME_LENGTH];
  14. SDgetinfo(id, _name, &size, dim, &dataType, nullptr);
  15. dims = std::vector<int32>(dim, dim + size);
  16. _size = std::accumulate(dims.begin(), dims.end(), 1, std::multiplies<int32>());
  17. name = std::string(_name);
  18. this->chain.emplaceBack(&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. hdf4cpp::HdfItem::HdfDatasetItem::~HdfDatasetItem() = default;
  33. hdf4cpp::HdfItem::HdfGroupItem::HdfGroupItem(int32 id, const HdfDestroyerChain &chain)
  34. : HdfItemBase(id, VGROUP, chain) {
  35. char _name[MAX_NAME_LENGTH];
  36. Vgetname(id, _name);
  37. name = std::string(_name);
  38. this->chain.emplaceBack(&Vdetach, id);
  39. }
  40. std::vector<int32> hdf4cpp::HdfItem::HdfGroupItem::getDims() {
  41. raiseException(INVALID_OPERATION);
  42. }
  43. hdf4cpp::HdfAttribute hdf4cpp::HdfItem::HdfGroupItem::getAttribute(const std::string &name) const {
  44. return HdfAttribute(new HdfAttribute::HdfGroupAttribute(id, name, chain));
  45. }
  46. std::string hdf4cpp::HdfItem::HdfGroupItem::getName() const {
  47. return name;
  48. }
  49. int32 hdf4cpp::HdfItem::HdfGroupItem::getId() const {
  50. return id;
  51. }
  52. hdf4cpp::HdfItem::HdfGroupItem::~HdfGroupItem() = default;
  53. hdf4cpp::HdfItem::HdfDataItem::HdfDataItem(int32 id, const HdfDestroyerChain &chain)
  54. : HdfItemBase(id, VDATA, chain) {
  55. this->chain.emplaceBack(&VSdetach, id);
  56. char _name[MAX_NAME_LENGTH];
  57. VSinquire(id, &nrRecords, &interlace, nullptr, &recordSize, _name);
  58. name = std::string(_name);
  59. }
  60. hdf4cpp::HdfItem::HdfDataItem::~HdfDataItem() = default;
  61. hdf4cpp::HdfAttribute hdf4cpp::HdfItem::HdfDataItem::getAttribute(const std::string &name) const {
  62. return HdfAttribute(new HdfAttribute::HdfDataAttribute(id, name, chain));
  63. }
  64. int32 hdf4cpp::HdfItem::HdfDataItem::getId() const {
  65. return id;
  66. }
  67. std::string hdf4cpp::HdfItem::HdfDataItem::getName() const {
  68. return name;
  69. }
  70. std::vector<int32> hdf4cpp::HdfItem::HdfDataItem::getDims() {
  71. raiseException(INVALID_OPERATION);
  72. }
  73. hdf4cpp::HdfItem::HdfItem(HdfItemBase *item, int32 sId, int32 vId)
  74. : HdfObject(item)
  75. , item(item)
  76. , sId(sId)
  77. , vId(vId) {
  78. }
  79. hdf4cpp::HdfItem::HdfItem(HdfItem &&other) noexcept
  80. : HdfObject(other.getType(), other.getClassType(), std::move(other.chain))
  81. , item(std::move(other.item))
  82. , sId(other.sId)
  83. , vId(other.vId) {
  84. }
  85. hdf4cpp::HdfItem &hdf4cpp::HdfItem::operator=(HdfItem &&it) noexcept {
  86. setType(it.getType());
  87. setClassType(it.getClassType());
  88. chain = std::move(it.chain);
  89. item = std::move(it.item);
  90. return *this;
  91. }
  92. std::vector<int32> hdf4cpp::HdfItem::getDims() {
  93. return item->getDims();
  94. }
  95. hdf4cpp::HdfAttribute hdf4cpp::HdfItem::getAttribute(const std::string &name) const {
  96. return item->getAttribute(name);
  97. }
  98. std::string hdf4cpp::HdfItem::getName() const {
  99. return item->getName();
  100. }
  101. hdf4cpp::HdfItem::Iterator hdf4cpp::HdfItem::begin() const {
  102. return Iterator(sId, vId, item->getId(), 0, getType(), chain);
  103. }
  104. hdf4cpp::HdfItem::Iterator hdf4cpp::HdfItem::end() const {
  105. switch (item->getType()) {
  106. case VGROUP: {
  107. int32 size = Vntagrefs(item->getId());
  108. return Iterator(sId, vId, item->getId(), size, getType(), chain);
  109. }
  110. default: { return Iterator(sId, vId, item->getId(), 0, getType(), chain); }
  111. }
  112. }