HdfAttribute.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // Created by patrik on 11.08.17.
  3. //
  4. #include <hdf4cpp/HdfDefines.h>
  5. #include <hdf4cpp/HdfAttribute.h>
  6. #include <stdexcept>
  7. hdf4cpp::HdfDatasetAttribute::HdfDatasetAttribute(int32 id, const std::string& name, const HdfDestroyerChain& chain) : HdfAttributeBase(id, SDfindattr(id, name.c_str()), SDATA, chain) {
  8. char waste[MAX_NAME_LENGTH];
  9. if(SDattrinfo(id, index, waste, &dataType, &_size) == FAIL) {
  10. raiseException(STATUS_RETURN_FAIL);
  11. }
  12. }
  13. intn hdf4cpp::HdfDatasetAttribute::size() const {
  14. return _size;
  15. }
  16. int32 hdf4cpp::HdfDatasetAttribute::getDataType() const {
  17. return dataType;
  18. }
  19. void hdf4cpp::HdfDatasetAttribute::get(void *dest) {
  20. int32 nrValues;
  21. char nameRet[MAX_NAME_LENGTH];
  22. int32 status = SDattrinfo(id, index, nameRet, &dataType, &nrValues);
  23. if(status == FAIL) {
  24. raiseException(STATUS_RETURN_FAIL);
  25. }
  26. if(SDreadattr(id, index, dest) == FAIL) {
  27. raiseException(STATUS_RETURN_FAIL);
  28. }
  29. }
  30. hdf4cpp::HdfGroupAttribute::HdfGroupAttribute(int32 id, const std::string& name, const HdfDestroyerChain& chain) : HdfAttributeBase(id, 0, VGROUP, chain) {
  31. int32 nrAtts = Vnattrs2(id);
  32. for(intn i = 0; i < nrAtts; ++i) {
  33. char names[MAX_NAME_LENGTH];
  34. int32 type, count, size, nFields;
  35. uint16 refNum;
  36. Vattrinfo2(id, i, names, &type, &count, &size, &nFields, &refNum);
  37. if(name == std::string(names)) {
  38. index = i;
  39. _size = count;
  40. dataType = type;
  41. return;
  42. }
  43. }
  44. raiseException(INVALID_NAME);
  45. }
  46. intn hdf4cpp::HdfGroupAttribute::size() const {
  47. return _size;
  48. }
  49. int32 hdf4cpp::HdfGroupAttribute::getDataType() const {
  50. return dataType;
  51. }
  52. void hdf4cpp::HdfGroupAttribute::get(void *dest) {
  53. if(Vgetattr2(id, index, dest) == FAIL) {
  54. raiseException(STATUS_RETURN_FAIL);
  55. }
  56. }
  57. hdf4cpp::HdfDataAttribute::HdfDataAttribute(int32 id, const std::string &name, const HdfDestroyerChain& chain) : HdfAttributeBase(id, VSfindattr(id, _HDF_VDATA, name.c_str()), VDATA, chain) {
  58. if(VSattrinfo(id, _HDF_VDATA, index, nullptr, &dataType, &_size, nullptr) == FAIL) {
  59. raiseException(STATUS_RETURN_FAIL);
  60. }
  61. }
  62. intn hdf4cpp::HdfDataAttribute::size() const {
  63. return _size;
  64. }
  65. void hdf4cpp::HdfDataAttribute::get(void *dest) {
  66. if(VSgetattr(id, _HDF_VDATA, index, dest) == FAIL) {
  67. raiseException(STATUS_RETURN_FAIL);
  68. }
  69. }
  70. int32 hdf4cpp::HdfDataAttribute::getDataType() const {
  71. return dataType;
  72. }
  73. hdf4cpp::HdfAttribute::HdfAttribute(HdfAttribute &&other) : HdfObject(other.getType(), other.getClassType()), attribute(std::move(other.attribute)) {
  74. }
  75. hdf4cpp::HdfAttribute& hdf4cpp::HdfAttribute::operator=(HdfAttribute&& attr) {
  76. attribute = std::move(attr.attribute);
  77. setType(attribute->getType());
  78. setClassType(attribute->getClassType());
  79. return *this;
  80. }
  81. hdf4cpp::Type hdf4cpp::HdfAttribute::getType() const {
  82. return attribute->getType();
  83. }
  84. intn hdf4cpp::HdfAttribute::size() const {
  85. return attribute->size();
  86. }