HdfFile.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // Created by patrik on 10.08.17.
  3. //
  4. #ifndef HDF4CPP_HDFFILE_H
  5. #define HDF4CPP_HDFFILE_H
  6. #include <string>
  7. #include <vector>
  8. #include <hdf4cpp/HdfObject.h>
  9. namespace hdf4cpp {
  10. class HdfItem;
  11. class HdfAttribute;
  12. /// Opens an hdf file and provides operations with it
  13. class HdfFile : public HdfObject {
  14. public:
  15. HdfFile(const std::string& path);
  16. HdfFile(const HdfFile& file) = delete;
  17. HdfFile(HdfFile&& file);
  18. HdfFile& operator=(const HdfFile& file) = delete;
  19. HdfFile& operator=(HdfFile&& file);
  20. ~HdfFile();
  21. int32 getSId() const;
  22. int32 getVId() const;
  23. /// \returns an item from the file with the given name
  24. /// \param name the name of the item
  25. /// \note: If there are multiple items with the same name then the first will be returned
  26. HdfItem get(const std::string& name) const;
  27. /// \returns all the items from the file with the given name
  28. /// \param name the name of the item(s)
  29. std::vector<HdfItem> getAll(const std::string& name) const;
  30. /// \returns the attribute with the given name
  31. /// \param name the name of the attribute
  32. HdfAttribute getAttribute(const std::string& name) const;
  33. class Iterator;
  34. Iterator begin() const;
  35. Iterator end() const;
  36. private:
  37. int32 getDatasetId(const std::string& name) const;
  38. int32 getGroupId(const std::string& name) const;
  39. int32 getDataId(const std::string& name) const;
  40. std::vector<int32> getDatasetIds(const std::string& name) const;
  41. std::vector<int32> getGroupDataIds(const std::string& name) const;
  42. int32 sId;
  43. int32 vId;
  44. std::vector<std::pair<int32, Type> > loneRefs;
  45. };
  46. /// HdfFile iterator, gives the possibility to iterate over the items in the file
  47. class HdfFile::Iterator : public HdfObject, public std::iterator<std::bidirectional_iterator_tag, HdfItem> {
  48. public:
  49. Iterator(const HdfFile* file, int32 index, const HdfDestroyerChain& chain) : HdfObject(HFILE, ITERATOR, chain),
  50. file(file),
  51. index(index) {}
  52. bool operator!=(const Iterator& it) { return index != it.index; }
  53. bool operator==(const Iterator& it) { return index == it.index; }
  54. Iterator& operator++() {
  55. ++index;
  56. return *this;
  57. }
  58. Iterator operator++(int) {
  59. Iterator it(*this);
  60. ++index;
  61. return it;
  62. }
  63. Iterator& operator--() {
  64. --index;
  65. return *this;
  66. }
  67. Iterator operator--(int) {
  68. Iterator it(*this);
  69. --index;
  70. return it;
  71. }
  72. HdfItem operator*();
  73. private:
  74. const HdfFile *file;
  75. int32 index;
  76. };
  77. }
  78. #endif //HDF4CPP_HDFFILE_H