HdfAttribute.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // Created by patrik on 24.08.17.
  3. //
  4. #ifndef HDF4CPP_HDFATTRIBUTE_H
  5. #define HDF4CPP_HDFATTRIBUTE_H
  6. #include "HdfObject.h"
  7. namespace hdf4cpp {
  8. class HdfAttributeBase;
  9. class HdfAttribute : public HdfObject {
  10. public:
  11. HdfAttribute(HdfAttributeBase *attribute);
  12. HdfAttribute(const HdfAttribute&) = delete;
  13. HdfAttribute(HdfAttribute&& attr);
  14. HdfAttribute& operator=(const HdfAttribute& attribute) = delete;
  15. HdfAttribute& operator=(HdfAttribute&& attribute);
  16. Type getType() const;
  17. intn size() const;
  18. template <class T> void get(std::vector<T> &dest) {
  19. intn length = size();
  20. auto it = typeSizeMap.find(getDataType());
  21. if (it != typeSizeMap.end()) {
  22. if ((size_t)it->second != sizeof(T)) {
  23. raiseException(BUFFER_SIZE_NOT_ENOUGH);
  24. }
  25. dest.resize(length);
  26. get_internal(dest.data());
  27. } else {
  28. raiseException(INVALID_DATA_TYPE);
  29. }
  30. }
  31. private:
  32. void get_internal(void *dest);
  33. int32 getDataType() const;
  34. std::unique_ptr<HdfAttributeBase> attribute;
  35. };
  36. }
  37. #endif //HDF4CPP_HDFATTRIBUTE_H