You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

path.h 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef DATASET_UTIL_PATH_H_
  17. #define DATASET_UTIL_PATH_H_
  18. #include <dirent.h>
  19. #include <memory>
  20. #include <string>
  21. #include "dataset/util/status.h"
  22. namespace mindspore {
  23. namespace dataset {
  24. class Path {
  25. public:
  26. class DirIterator {
  27. public:
  28. static std::shared_ptr<DirIterator> OpenDirectory(Path *f);
  29. ~DirIterator();
  30. bool hasNext();
  31. Path next();
  32. private:
  33. explicit DirIterator(Path *f);
  34. Path *dir_;
  35. DIR *dp_;
  36. struct dirent *entry_;
  37. };
  38. explicit Path(const std::string &);
  39. explicit Path(const char *);
  40. ~Path() = default;
  41. Path(const Path &);
  42. Path &operator=(const Path &);
  43. Path(Path &&) noexcept;
  44. Path &operator=(Path &&) noexcept;
  45. std::string toString() const { return path_; }
  46. Path operator+(const Path &);
  47. Path operator+(const std::string &);
  48. Path operator+(const char *);
  49. Path &operator+=(const Path &rhs);
  50. Path &operator+=(const std::string &);
  51. Path &operator+=(const char *);
  52. Path operator/(const Path &);
  53. Path operator/(const std::string &);
  54. Path operator/(const char *);
  55. bool Exists();
  56. bool IsDirectory();
  57. Status CreateDirectory();
  58. Status CreateDirectories();
  59. std::string Extension() const;
  60. std::string ParentPath();
  61. private:
  62. static char separator_;
  63. std::string path_;
  64. };
  65. } // namespace dataset
  66. } // namespace mindspore
  67. #endif // DATASET_UTIL_PATH_H_