fileResolver.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * @author Alexis Maiquez Murcia <almamu@almamu.com>
  3. */
  4. #ifndef WALLENGINE_RESOLVER_H
  5. #define WALLENGINE_RESOLVER_H
  6. #include <string>
  7. #include <vector>
  8. #include <irrlicht/path.h>
  9. #include <nlohmann/json.hpp>
  10. namespace wp
  11. {
  12. using json = nlohmann::json;
  13. namespace fs
  14. {
  15. /**
  16. * Custom file resolver to limit our searches to specific folders
  17. */
  18. class fileResolver
  19. {
  20. public:
  21. /**
  22. * Basic constructor, uses current path as base folder
  23. */
  24. fileResolver ();
  25. /**
  26. * Creates a file resolver using a list as environment folders
  27. *
  28. * @param environment List of directories to use for finding files
  29. */
  30. fileResolver (std::vector<irr::io::path> environment);
  31. /**
  32. * Adds a new folder to the environment list
  33. *
  34. * @param path
  35. */
  36. void appendEnvironment (irr::io::path path);
  37. /**
  38. * Removes the given folder from the environment list
  39. *
  40. * @param path
  41. */
  42. void removeEnvironment (irr::io::path path);
  43. /**
  44. * Updates the current working directory
  45. *
  46. * @param newpath
  47. */
  48. void changeWorkingDirectory (irr::io::path newpath);
  49. /**
  50. * @return The current working directory
  51. */
  52. irr::io::path getWorkingDirectory ();
  53. /**
  54. * @return A clone of this fileResolver
  55. */
  56. fileResolver clone ();
  57. /**
  58. * Resolves the given filename or relative path
  59. * on the current working directory or any of the registered
  60. * environment folders
  61. *
  62. * @param name The filename/relative path to resolve
  63. *
  64. * @return The full path to the file
  65. */
  66. irr::io::path resolve (irr::io::path name);
  67. /**
  68. * Resolves the given filename or relative path
  69. * on the current working directory only
  70. *
  71. * @param name The filename/relative path to resolve
  72. *
  73. * @return The full path to the file
  74. */
  75. irr::io::path resolveOnWorkingDirectory (irr::io::path name);
  76. irr::io::path resolve (json name);
  77. irr::io::path resolveOnWorkingDirectory (json name);
  78. irr::io::path resolve (const char* name);
  79. irr::io::path resolveOnWorkingDirectory (const char* name);
  80. protected:
  81. void prependEnvironment (irr::io::path path);
  82. private:
  83. /**
  84. * List of environment paths in which the resolver will look for
  85. * files in when trying to resolve them
  86. */
  87. std::vector<irr::io::path> m_environment;
  88. };
  89. /**
  90. * Static resolver used trough most of the application
  91. */
  92. extern fileResolver resolver;
  93. };
  94. }
  95. #endif //WALLENGINE_RESOLVER_H