HdfItem.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.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. hdf4cpp::HdfItem::HdfDatasetItem::~HdfDatasetItem() {
  33. }
  34. hdf4cpp::HdfItem::HdfGroupItem::HdfGroupItem(int32 id, const HdfDestroyerChain &chain)
  35. : HdfItemBase(id, VGROUP, chain) {
  36. char _name[MAX_NAME_LENGTH];
  37. Vgetname(id, _name);
  38. name = std::string(_name);
  39. this->chain.pushBack(new HdfDestroyer(&Vdetach, id));
  40. }
  41. std::vector<int32> hdf4cpp::HdfItem::HdfGroupItem::getDims() {
  42. raiseException(INVALID_OPERATION);
  43. }
  44. hdf4cpp::HdfAttribute hdf4cpp::HdfItem::HdfGroupItem::getAttribute(const std::string &name) const {
  45. return HdfAttribute(new HdfAttribute::HdfGroupAttribute(id, name, chain));
  46. }
  47. std::string hdf4cpp::HdfItem::HdfGroupItem::getName() const {
  48. return name;
  49. }
  50. int32 hdf4cpp::HdfItem::HdfGroupItem::getId() const {
  51. return id;
  52. }
  53. hdf4cpp::HdfItem::HdfGroupItem::~HdfGroupItem() {
  54. }
  55. hdf4cpp::HdfItem::HdfDataItem::HdfDataItem(int32 id, const HdfDestroyerChain &chain)
  56. : HdfItemBase(id, VDATA, chain) {
  57. this->chain.pushBack(new HdfDestroyer(&VSdetach, id));
  58. char _name[MAX_NAME_LENGTH];
  59. VSinquire(id, &nrRecords, &interlace, nullptr, &recordSize, _name);
  60. name = std::string(_name);
  61. }
  62. hdf4cpp::HdfItem::HdfDataItem::~HdfDataItem() {
  63. }
  64. hdf4cpp::HdfAttribute hdf4cpp::HdfItem::HdfDataItem::getAttribute(const std::string &name) const {
  65. return HdfAttribute(new HdfAttribute::HdfDataAttribute(id, name, chain));
  66. }
  67. int32 hdf4cpp::HdfItem::HdfDataItem::getId() const {
  68. return id;
  69. }
  70. std::string hdf4cpp::HdfItem::HdfDataItem::getName() const {
  71. return name;
  72. }
  73. std::vector<int32> hdf4cpp::HdfItem::HdfDataItem::getDims() {
  74. raiseException(INVALID_OPERATION);
  75. }
  76. hdf4cpp::HdfItem::HdfItem(HdfItemBase *item, int32 sId, int32 vId)
  77. : HdfObject(item)
  78. , item(item)
  79. , sId(sId)
  80. , vId(vId) {
  81. }
  82. hdf4cpp::HdfItem::HdfItem(HdfItem &&other)
  83. : HdfObject(other.getType(), other.getClassType(), std::move(other.chain))
  84. , item(std::move(other.item))
  85. , sId(other.sId)
  86. , vId(other.vId) {
  87. }
  88. hdf4cpp::HdfItem &hdf4cpp::HdfItem::operator=(HdfItem &&it) {
  89. setType(it.getType());
  90. setClassType(it.getClassType());
  91. chain = std::move(it.chain);
  92. item = std::move(it.item);
  93. return *this;
  94. }
  95. std::vector<int32> hdf4cpp::HdfItem::getDims() {
  96. return item->getDims();
  97. }
  98. hdf4cpp::HdfAttribute hdf4cpp::HdfItem::getAttribute(const std::string &name) const {
  99. return item->getAttribute(name);
  100. }
  101. std::string hdf4cpp::HdfItem::getName() const {
  102. return item->getName();
  103. }
  104. hdf4cpp::HdfItem::Iterator hdf4cpp::HdfItem::begin() const {
  105. return Iterator(sId, vId, item->getId(), 0, getType(), chain);
  106. }
  107. hdf4cpp::HdfItem::Iterator hdf4cpp::HdfItem::end() const {
  108. switch (item->getType()) {
  109. case VGROUP: {
  110. int32 size = Vntagrefs(item->getId());
  111. return Iterator(sId, vId, item->getId(), size, getType(), chain);
  112. }
  113. default: { return Iterator(sId, vId, item->getId(), 0, getType(), chain); }
  114. }
  115. }