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.

107 lines
2.5 KiB

  1. /*
  2. Copyright (c) 2020, 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. #pragma once
  15. #include "tofrom_string.hpp"
  16. #include "funcs.hpp"
  17. #include "func.hpp"
  18. #include <string>
  19. namespace Category
  20. {
  21. class Base : public ToFromString
  22. {
  23. public:
  24. int from_string(const std::string &s) final;
  25. std::string to_string() const final;
  26. protected:
  27. std::vector<ToFromString*> funcs;
  28. };
  29. class Action final : public Base
  30. {
  31. private:
  32. Action();
  33. public:
  34. Action(Funcs &funcs_)
  35. {
  36. funcs.push_back(&funcs_.chmod);
  37. funcs.push_back(&funcs_.chown);
  38. funcs.push_back(&funcs_.link);
  39. funcs.push_back(&funcs_.removexattr);
  40. funcs.push_back(&funcs_.rename);
  41. funcs.push_back(&funcs_.rmdir);
  42. funcs.push_back(&funcs_.setxattr);
  43. funcs.push_back(&funcs_.truncate);
  44. funcs.push_back(&funcs_.unlink);
  45. funcs.push_back(&funcs_.utimens);
  46. }
  47. };
  48. class Create final : public Base
  49. {
  50. private:
  51. Create();
  52. public:
  53. Create(Funcs &funcs_)
  54. {
  55. funcs.push_back(&funcs_.create);
  56. funcs.push_back(&funcs_.mkdir);
  57. funcs.push_back(&funcs_.mknod);
  58. funcs.push_back(&funcs_.symlink);
  59. }
  60. };
  61. class Search final : public Base
  62. {
  63. private:
  64. Search();
  65. public:
  66. Search(Funcs &funcs_)
  67. {
  68. funcs.push_back(&funcs_.access);
  69. funcs.push_back(&funcs_.getattr);
  70. funcs.push_back(&funcs_.getxattr);
  71. funcs.push_back(&funcs_.listxattr);
  72. funcs.push_back(&funcs_.open);
  73. funcs.push_back(&funcs_.readlink);
  74. }
  75. };
  76. }
  77. class Categories final
  78. {
  79. private:
  80. Categories();
  81. public:
  82. Categories(Funcs &funcs_)
  83. : action(funcs_),
  84. create(funcs_),
  85. search(funcs_)
  86. {}
  87. public:
  88. Category::Action action;
  89. Category::Create create;
  90. Category::Search search;
  91. };