HdfAttribute.h 1.9 KB

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