path.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine" and the "irrXML" project.
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #ifndef IRR_PATH_H_INCLUDED
  5. #define IRR_PATH_H_INCLUDED
  6. #include "irrString.h"
  7. namespace irr
  8. {
  9. namespace io
  10. {
  11. //! Type used for all file system related strings.
  12. /** This type will transparently handle different file system encodings.
  13. NOTE: For historical reasons the tool-functions using io::path are all in coreutil.h
  14. */
  15. typedef core::string<fschar_t> path;
  16. //! Used in places where we identify objects by a filename, but don't actually work with the real filename
  17. /** Irrlicht is internally not case-sensitive when it comes to names.
  18. Also this class is a first step towards support for correctly serializing renamed objects.
  19. */
  20. struct SNamedPath
  21. {
  22. //! Constructor
  23. SNamedPath() {}
  24. //! Constructor
  25. SNamedPath(const path& p) : Path(p), InternalName( PathToName(p) )
  26. {
  27. }
  28. //! Is smaller comparator
  29. bool operator <(const SNamedPath& other) const
  30. {
  31. return InternalName < other.InternalName;
  32. }
  33. //! Set the path.
  34. void setPath(const path& p)
  35. {
  36. Path = p;
  37. InternalName = PathToName(p);
  38. }
  39. //! Get the path.
  40. const path& getPath() const
  41. {
  42. return Path;
  43. };
  44. //! Get the name which is used to identify the file.
  45. //! This string is similar to the names and filenames used before Irrlicht 1.7
  46. const path& getInternalName() const
  47. {
  48. return InternalName;
  49. }
  50. //! Implicit cast to io::path
  51. operator core::stringc() const
  52. {
  53. return core::stringc(getPath());
  54. }
  55. //! Implicit cast to io::path
  56. operator core::stringw() const
  57. {
  58. return core::stringw(getPath());
  59. }
  60. protected:
  61. // convert the given path string to a name string.
  62. path PathToName(const path& p) const
  63. {
  64. path name(p);
  65. name.replace( '\\', '/' );
  66. name.make_lower();
  67. return name;
  68. }
  69. private:
  70. path Path;
  71. path InternalName;
  72. };
  73. } // io
  74. } // irr
  75. #endif // IRR_PATH_H_INCLUDED