service-dir.h 889 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef DINIT_SERVICE_DIR_H
  2. #define DINIT_SERVICE_DIR_H 1
  3. #include <vector>
  4. // A service directory entry, tracking the directory as a nul-terminated string, which may either
  5. // be static or dynamically allocated (via new char[...]).
  6. class dir_entry
  7. {
  8. const char *dir;
  9. bool dir_dyn_allocd; // dynamically allocated?
  10. public:
  11. dir_entry(const char *dir_p, bool dir_dyn_allocd_p) :
  12. dir(dir_p), dir_dyn_allocd(dir_dyn_allocd_p)
  13. { }
  14. dir_entry(dir_entry &&other)
  15. {
  16. dir = other.dir;
  17. dir_dyn_allocd = other.dir_dyn_allocd;
  18. other.dir_dyn_allocd = false;
  19. }
  20. dir_entry(const dir_entry &other) = delete;
  21. ~dir_entry()
  22. {
  23. if (dir_dyn_allocd) {
  24. delete[] dir;
  25. }
  26. }
  27. const char *get_dir() const
  28. {
  29. return dir;
  30. }
  31. };
  32. using service_dir_pathlist = std::vector<dir_entry>;
  33. #endif