HdfFile.h 2.7 KB

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