path.h
Engine/source/core/util/path.h
Classes:
class
FileSystem filename representation.
Namespaces:
namespace
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _PATH_H_ 25#define _PATH_H_ 26 27#ifndef _TORQUE_STRING_H_ 28#include "core/util/str.h" 29#endif 30 31namespace Torque 32{ 33 34//----------------------------------------------------------------------------- 35 36/// FileSystem filename representation. 37/// Filenames has the following form: "root:path/file.ext" 38/// @ingroup UtilString 39class Path 40{ 41public: 42 enum Separator 43 { 44#if defined(TORQUE_OS_WIN) 45 OsSeparator = '\\' 46#else 47 OsSeparator = '/' 48#endif 49 }; 50 51 Path() 52 : mIsDirtyFileName( true ), 53 mIsDirtyPath( true ) 54 { 55 } 56 57 Path( const char *file ) 58 : mIsDirtyFileName( true ), 59 mIsDirtyPath( true ) 60 { 61 _split(file); 62 } 63 64 Path( const String &file ) 65 : mIsDirtyFileName( true ), 66 mIsDirtyPath( true ) 67 { 68 _split(file); 69 } 70 71 Path& operator =( const String &file ) { _split(file); mIsDirtyPath = mIsDirtyFileName = true; return *this; } 72 operator String() const { return getFullPath(); } 73 74 bool operator ==(const Path& path) const { return getFullPath().equal(path.getFullPath()); } 75 bool operator !=(const Path& path) const { return !(*this == path); } 76 77 bool isEmpty() const { return getFullPath().isEmpty(); } 78 79 /// Join two path or file name components together. 80 static String Join(const String&,String::ValueType,const String&); 81 82 /// Replace all '\' with '/' 83 static String CleanSeparators( String path ); 84 85 /// Remove "." and ".." relative paths. 86 static String CompressPath( String path ); 87 88 /// Take two paths and return the relative path between them. 89 static Path MakeRelativePath( const Path &makeRelative, const Path &relativeTo, U32 mode = String::NoCase ); 90 91 const String& getRoot() const { return mRoot; } 92 const String& getPath() const { return mPath; } 93 const String& getFileName() const { return mFile; } 94 const String& getExtension() const { return mExt; } 95 96 const String& getFullFileName() const; 97 const String& getFullPath() const; 98 99 /// Returns the full file path without the volume root. 100 String getFullPathWithoutRoot() const; 101 102 /// Returns the root and path. 103 String getRootAndPath() const; 104 105 const String& setRoot(const String &s); 106 const String& setPath(const String &s); 107 const String& setFileName(const String &s); 108 const String& setExtension(const String &s); 109 110 U32 getDirectoryCount() const; 111 String getDirectory(U32) const; 112 113 bool isDirectory() const; 114 bool isRelative() const; 115 bool isAbsolute() const; 116 117 /// Appends the argument's path component to the object's 118 /// path component. The object's root, filename and 119 /// extension are unaffected. 120 bool appendPath(const Path &path); 121 122private: 123 String mRoot; 124 String mPath; 125 String mFile; 126 String mExt; 127 128 mutable String mFullFileName; 129 mutable String mFullPath; 130 131 mutable bool mIsDirtyFileName; 132 mutable bool mIsDirtyPath; 133 134 void _split(String name); 135 String _join() const; 136}; 137 138/// Convert file/path name to use platform standard path separator 139///@ingroup VolumeSystem 140String PathToPlatform(String file); 141 142/// Convert file/path name to use OS standard path separator 143///@ingroup VolumeSystem 144String PathToOS(String file); 145 146} // Namespace 147#endif 148 149