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 5 #ifndef __IRR_PATH_H_INCLUDED__ 6 #define __IRR_PATH_H_INCLUDED__ 7 8 #include "irrString.h" 9 10 namespace irr 11 { 12 namespace io 13 { 14 15 //! Type used for all file system related strings. 16 /** This type will transparently handle different file system encodings. */ 17 typedef core::string<fschar_t> path; 18 19 //! Used in places where we identify objects by a filename, but don't actually work with the real filename 20 /** Irrlicht is internally not case-sensitive when it comes to names. 21 Also this class is a first step towards support for correctly serializing renamed objects. 22 */ 23 struct SNamedPath 24 { 25 //! Constructor SNamedPathSNamedPath26 SNamedPath() {} 27 28 //! Constructor SNamedPathSNamedPath29 SNamedPath(const path& p) : Path(p), InternalName( PathToName(p) ) 30 { 31 } 32 33 //! Is smaller comparator 34 bool operator <(const SNamedPath& other) const 35 { 36 return InternalName < other.InternalName; 37 } 38 39 //! Set the path. setPathSNamedPath40 void setPath(const path& p) 41 { 42 Path = p; 43 InternalName = PathToName(p); 44 } 45 46 //! Get the path. getPathSNamedPath47 const path& getPath() const 48 { 49 return Path; 50 }; 51 52 //! Get the name which is used to identify the file. 53 //! This string is similar to the names and filenames used before Irrlicht 1.7 getInternalNameSNamedPath54 const path& getInternalName() const 55 { 56 return InternalName; 57 } 58 59 //! Implicit cast to io::path stringcSNamedPath60 operator core::stringc() const 61 { 62 return core::stringc(getPath()); 63 } 64 //! Implicit cast to io::path stringwSNamedPath65 operator core::stringw() const 66 { 67 return core::stringw(getPath()); 68 } 69 70 protected: 71 // convert the given path string to a name string. PathToNameSNamedPath72 path PathToName(const path& p) const 73 { 74 path name(p); 75 name.replace( '\\', '/' ); 76 name.make_lower(); 77 return name; 78 } 79 80 private: 81 path Path; 82 path InternalName; 83 }; 84 85 } // io 86 } // irr 87 88 #endif // __IRR_PATH_H_INCLUDED__ 89