HdfAttribute.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // Created by patrik on 24.08.17.
  3. //
  4. #ifndef HDF4CPP_HDFATTRIBUTE_H
  5. #define HDF4CPP_HDFATTRIBUTE_H
  6. #include <hdf/hdfi.h>
  7. #include <hdf4cpp/HdfObject.h>
  8. #include <hdf4cpp/HdfItem.h>
  9. namespace hdf4cpp {
  10. /// Represents an hdf attribute
  11. class HdfAttribute : public HdfObject {
  12. public:
  13. HdfAttribute(const HdfAttribute&) = delete;
  14. HdfAttribute(HdfAttribute&& attr);
  15. HdfAttribute& operator=(const HdfAttribute& attribute) = delete;
  16. HdfAttribute& operator=(HdfAttribute&& attribute);
  17. /// \returns the number of elements of the attribute data
  18. intn size() const;
  19. /// Reads the data from the attribute
  20. /// \param dest the vector in which the data will be stored
  21. template <class T> void get(std::vector<T> &dest) {
  22. intn length = size();
  23. auto it = typeSizeMap.find(getDataType());
  24. if (it != typeSizeMap.end()) {
  25. if ((size_t)it->second != sizeof(T)) {
  26. raiseException(BUFFER_SIZE_NOT_ENOUGH);
  27. }
  28. dest.resize(length);
  29. getInternal(dest.data());
  30. } else {
  31. raiseException(INVALID_DATA_TYPE);
  32. }
  33. }
  34. friend HdfAttribute HdfFile::getAttribute(const std::string &name) const;
  35. friend HdfAttribute HdfItem::HdfDatasetItem::getAttribute(const std::string &name) const;
  36. friend HdfAttribute HdfItem::HdfGroupItem::getAttribute(const std::string &name) const;
  37. friend HdfAttribute HdfItem::HdfDataItem::getAttribute(const std::string &name) const;
  38. private:
  39. class HdfAttributeBase;
  40. class HdfDatasetAttribute;
  41. class HdfGroupAttribute;
  42. class HdfDataAttribute;
  43. HdfAttribute(HdfAttributeBase *attribute);
  44. /// An internal get function
  45. /// \param dest The destination buffer
  46. void getInternal(void *dest);
  47. int32 getDataType() const;
  48. /// Holds an attribute object address
  49. std::unique_ptr<HdfAttributeBase> attribute;
  50. };
  51. }
  52. #endif //HDF4CPP_HDFATTRIBUTE_H