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

94 lines
2.3 KiB

  1. /*
  2. ISC License
  3. Copyright (c) 2021, Antonio SJ Musumeci <trapexit@spawn.link>
  4. Permission to use, copy, modify, and/or distribute this software for any
  5. purpose with or without fee is hereby granted, provided that the above
  6. copyright notice and this permission notice appear in all copies.
  7. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. */
  15. #pragma once
  16. #include "branch.hpp"
  17. #include "nonstd/optional.hpp"
  18. #include "strvec.hpp"
  19. #include "tofrom_string.hpp"
  20. #include <cstdint>
  21. #include <memory>
  22. #include <mutex>
  23. #include <string>
  24. #include <vector>
  25. class Branches final : public ToFromString
  26. {
  27. public:
  28. class Impl final : public ToFromString, public Branch::Vector
  29. {
  30. public:
  31. typedef std::shared_ptr<Impl> Ptr;
  32. typedef std::shared_ptr<const Impl> CPtr;
  33. public:
  34. Impl(const uint64_t &default_minfreespace_);
  35. public:
  36. int from_string(const std::string &str) final;
  37. std::string to_string(void) const final;
  38. public:
  39. const uint64_t& minfreespace(void) const;
  40. void to_paths(StrVec &strvec) const;
  41. public:
  42. Impl& operator=(Impl &impl_);
  43. Impl& operator=(Impl &&impl_);
  44. private:
  45. const uint64_t &_default_minfreespace;
  46. };
  47. public:
  48. typedef Branches::Impl::Ptr Ptr;
  49. typedef Branches::Impl::CPtr CPtr;
  50. public:
  51. Branches(const uint64_t &default_minfreespace_)
  52. : _impl(std::make_shared<Impl>(default_minfreespace_))
  53. {}
  54. public:
  55. int from_string(const std::string &str) final;
  56. std::string to_string(void) const final;
  57. public:
  58. operator CPtr() const { std::lock_guard<std::mutex> lg(_mutex); return _impl; }
  59. CPtr operator->() const { std::lock_guard<std::mutex> lg(_mutex); return _impl; }
  60. private:
  61. mutable std::mutex _mutex;
  62. Ptr _impl;
  63. };
  64. class SrcMounts : public ToFromString
  65. {
  66. public:
  67. SrcMounts(Branches &b_);
  68. public:
  69. int from_string(const std::string &str) final;
  70. std::string to_string(void) const final;
  71. private:
  72. Branches &_branches;
  73. };