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.

88 lines
2.5 KiB

  1. /*
  2. Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. #include <vector>
  15. #include "buildvector.hpp"
  16. #include "fs.hpp"
  17. #include "policy.hpp"
  18. #define POLICY(X,PP) (Policy(Policy::Enum::X,#X,Policy::Func::X,PP))
  19. #define PRESERVES_PATH true
  20. #define DOESNT_PRESERVE_PATH false
  21. namespace mergerfs
  22. {
  23. const std::vector<Policy> Policy::_policies_ =
  24. buildvector<Policy,true>
  25. (POLICY(invalid,DOESNT_PRESERVE_PATH))
  26. (POLICY(all,DOESNT_PRESERVE_PATH))
  27. (POLICY(epall,PRESERVES_PATH))
  28. (POLICY(epff,PRESERVES_PATH))
  29. (POLICY(eplfs,PRESERVES_PATH))
  30. (POLICY(eplus,PRESERVES_PATH))
  31. (POLICY(epmfs,PRESERVES_PATH))
  32. (POLICY(eprand,PRESERVES_PATH))
  33. (POLICY(erofs,DOESNT_PRESERVE_PATH))
  34. (POLICY(ff,DOESNT_PRESERVE_PATH))
  35. (POLICY(lfs,DOESNT_PRESERVE_PATH))
  36. (POLICY(lus,DOESNT_PRESERVE_PATH))
  37. (POLICY(mfs,DOESNT_PRESERVE_PATH))
  38. (POLICY(newest,DOESNT_PRESERVE_PATH))
  39. (POLICY(rand,DOESNT_PRESERVE_PATH));
  40. const Policy * const Policy::policies = &_policies_[1];
  41. #define CONST_POLICY(X) const Policy &Policy::X = Policy::policies[Policy::Enum::X]
  42. CONST_POLICY(invalid);
  43. CONST_POLICY(all);
  44. CONST_POLICY(epall);
  45. CONST_POLICY(epff);
  46. CONST_POLICY(eplfs);
  47. CONST_POLICY(eplus);
  48. CONST_POLICY(epmfs);
  49. CONST_POLICY(eprand);
  50. CONST_POLICY(erofs);
  51. CONST_POLICY(ff);
  52. CONST_POLICY(lfs);
  53. CONST_POLICY(lus);
  54. CONST_POLICY(mfs);
  55. CONST_POLICY(newest);
  56. CONST_POLICY(rand);
  57. const Policy&
  58. Policy::find(const std::string &str)
  59. {
  60. for(int i = Enum::BEGIN; i != Enum::END; ++i)
  61. {
  62. if(policies[i] == str)
  63. return policies[i];
  64. }
  65. return invalid;
  66. }
  67. const Policy&
  68. Policy::find(const Policy::Enum::Type i)
  69. {
  70. if(i >= Policy::Enum::BEGIN &&
  71. i < Policy::Enum::END)
  72. return policies[i];
  73. return invalid;
  74. }
  75. }