2
0

path.h 1.9 KB

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