Add "empty()" method to sys::Path and remove unnecessary whitespace.

Patch by Mikhail Glushenkov!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49803 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling 2008-04-16 18:27:02 +00:00
parent 6f0ca06296
commit a5261923b4

View File

@ -28,8 +28,8 @@ namespace sys {
/// platform independent and eliminates many of the unix-specific fields. /// platform independent and eliminates many of the unix-specific fields.
/// However, to support llvm-ar, the mode, user, and group fields are /// However, to support llvm-ar, the mode, user, and group fields are
/// retained. These pertain to unix security and may not have a meaningful /// retained. These pertain to unix security and may not have a meaningful
/// value on non-Unix platforms. However, the other fields fields should /// value on non-Unix platforms. However, the other fields fields should
/// always be applicable on all platforms. The structure is filled in by /// always be applicable on all platforms. The structure is filled in by
/// the PathWithStatus class. /// the PathWithStatus class.
/// @brief File status structure /// @brief File status structure
class FileStatus { class FileStatus {
@ -45,7 +45,7 @@ namespace sys {
FileStatus() : fileSize(0), modTime(0,0), mode(0777), user(999), FileStatus() : fileSize(0), modTime(0,0), mode(0777), user(999),
group(999), uniqueID(0), isDir(false), isFile(false) { } group(999), uniqueID(0), isDir(false), isFile(false) { }
TimeValue getTimestamp() const { return modTime; } TimeValue getTimestamp() const { return modTime; }
uint64_t getSize() const { return fileSize; } uint64_t getSize() const { return fileSize; }
uint32_t getMode() const { return mode; } uint32_t getMode() const { return mode; }
@ -148,7 +148,7 @@ namespace sys {
/// constructor must provide the same result as GetRootDirectory. /// constructor must provide the same result as GetRootDirectory.
/// @brief Construct a path to the current user's "home" directory /// @brief Construct a path to the current user's "home" directory
static Path GetUserHomeDirectory(); static Path GetUserHomeDirectory();
/// Construct a path to the current directory for the current process. /// Construct a path to the current directory for the current process.
/// @returns The current working directory. /// @returns The current working directory.
/// @brief Returns the current working directory. /// @brief Returns the current working directory.
@ -161,7 +161,7 @@ namespace sys {
/// @returns The dynamic link library suffix for the current platform. /// @returns The dynamic link library suffix for the current platform.
/// @brief Return the dynamic link library suffix. /// @brief Return the dynamic link library suffix.
static std::string GetDLLSuffix(); static std::string GetDLLSuffix();
/// GetMainExecutable - Return the path to the main executable, given the /// GetMainExecutable - Return the path to the main executable, given the
/// value of argv[0] from program startup and the address of main itself. /// value of argv[0] from program startup and the address of main itself.
static Path GetMainExecutable(const char *argv0, void *MainAddr); static Path GetMainExecutable(const char *argv0, void *MainAddr);
@ -177,20 +177,20 @@ namespace sys {
/// This constructor will accept a std::string as a path. No checking is /// This constructor will accept a std::string as a path. No checking is
/// done on this path to determine if it is valid. To determine validity /// done on this path to determine if it is valid. To determine validity
/// of the path, use the isValid method. /// of the path, use the isValid method.
/// @param p The path to assign. /// @param p The path to assign.
/// @brief Construct a Path from a string. /// @brief Construct a Path from a string.
explicit Path(const std::string& p) : path(p) {} explicit Path(const std::string& p) : path(p) {}
/// This constructor will accept a character range as a path. No checking /// This constructor will accept a character range as a path. No checking
/// is done on this path to determine if it is valid. To determine /// is done on this path to determine if it is valid. To determine
/// validity of the path, use the isValid method. /// validity of the path, use the isValid method.
/// @param StrStart A pointer to the first character of the path name /// @param StrStart A pointer to the first character of the path name
/// @param StrLen The length of the path name at StrStart /// @param StrLen The length of the path name at StrStart
/// @brief Construct a Path from a string. /// @brief Construct a Path from a string.
explicit Path(const char *StrStart, unsigned StrLen) explicit Path(const char *StrStart, unsigned StrLen)
: path(StrStart, StrStart+StrLen) {} : path(StrStart, StrStart+StrLen) {}
/// @} /// @}
/// @name Operators /// @name Operators
/// @{ /// @{
@ -240,10 +240,10 @@ namespace sys {
/// @brief Determine if a path is syntactically valid or not. /// @brief Determine if a path is syntactically valid or not.
bool isValid() const; bool isValid() const;
/// This function determines if the contents of the path name are empty. /// This function determines if the contents of the path name are empty.
/// That is, the path name has a zero length. This does NOT determine if /// That is, the path name has a zero length. This does NOT determine if
/// if the file is empty. To get the length of the file itself, Use the /// if the file is empty. To get the length of the file itself, Use the
/// PathWithStatus::getFileStatus() method and then the getSize() method /// PathWithStatus::getFileStatus() method and then the getSize() method
/// on the returned FileStatus object. /// on the returned FileStatus object.
/// @returns true iff the path is empty. /// @returns true iff the path is empty.
/// @brief Determines if the path name is empty (invalid). /// @brief Determines if the path name is empty (invalid).
@ -269,7 +269,7 @@ namespace sys {
/// @returns std::string containing the basename of the path /// @returns std::string containing the basename of the path
/// @brief Get the base name of the path /// @brief Get the base name of the path
std::string getBasename() const; std::string getBasename() const;
/// This function strips off the suffix of the path beginning with the /// This function strips off the suffix of the path beginning with the
/// path separator ('/' on Unix, '\' on Windows) and returns the result. /// path separator ('/' on Unix, '\' on Windows) and returns the result.
std::string getDirname() const; std::string getDirname() const;
@ -286,10 +286,13 @@ namespace sys {
/// @returns a 'C' string containing the path name. /// @returns a 'C' string containing the path name.
/// @brief Returns the path as a C string. /// @brief Returns the path as a C string.
const char *c_str() const { return path.c_str(); } const char *c_str() const { return path.c_str(); }
/// size - Return the length in bytes of this path name. /// size - Return the length in bytes of this path name.
unsigned size() const { return path.size(); } unsigned size() const { return path.size(); }
/// empty - Returns true if the path is empty.
unsigned empty() const { return path.empty(); }
/// @} /// @}
/// @name Disk Accessors /// @name Disk Accessors
/// @{ /// @{
@ -303,7 +306,7 @@ namespace sys {
bool isRootDirectory() const; bool isRootDirectory() const;
/// This function determines if the path name is absolute, as opposed to /// This function determines if the path name is absolute, as opposed to
/// relative. /// relative.
/// @brief Determine if the path is absolute. /// @brief Determine if the path is absolute.
bool isAbsolute() const; bool isAbsolute() const;
@ -336,7 +339,7 @@ namespace sys {
/// bitcode files. /// bitcode files.
/// @brief Determine if the path references a bitcode file. /// @brief Determine if the path references a bitcode file.
bool isBitcodeFile() const; bool isBitcodeFile() const;
/// This function determines if the path name in the object references a /// This function determines if the path name in the object references a
/// native Dynamic Library (shared library, shared object) by looking at /// native Dynamic Library (shared library, shared object) by looking at
/// the file's magic number. The Path object must reference a file, not a /// the file's magic number. The Path object must reference a file, not a
@ -345,7 +348,7 @@ namespace sys {
/// shared library. /// shared library.
/// @brief Determine if the path reference a dynamic library. /// @brief Determine if the path reference a dynamic library.
bool isDynamicLibrary() const; bool isDynamicLibrary() const;
/// This function determines if the path name references an existing file /// This function determines if the path name references an existing file
/// or directory in the file system. /// or directory in the file system.
/// @returns true if the pathname references an existing file or /// @returns true if the pathname references an existing file or
@ -354,12 +357,12 @@ namespace sys {
/// the file system. /// the file system.
bool exists() const; bool exists() const;
/// This function determines if the path name refences an /// This function determines if the path name refences an
/// existing directory. /// existing directory.
/// @returns true if the pathname references an existing directory. /// @returns true if the pathname references an existing directory.
/// @brief Determins if the path is a directory in the file system. /// @brief Determins if the path is a directory in the file system.
bool isDirectory() const; bool isDirectory() const;
/// This function determines if the path name references a readable file /// This function determines if the path name references a readable file
/// or directory in the file system. This function checks for /// or directory in the file system. This function checks for
/// the existence and readability (by the current program) of the file /// the existence and readability (by the current program) of the file
@ -494,9 +497,9 @@ namespace sys {
/// created. The created directory will have no entries. /// created. The created directory will have no entries.
/// @returns true if the directory could not be created, false otherwise /// @returns true if the directory could not be created, false otherwise
/// @brief Create the directory this Path refers to. /// @brief Create the directory this Path refers to.
bool createDirectoryOnDisk( bool createDirectoryOnDisk(
bool create_parents = false, ///< Determines whether non-existent bool create_parents = false, ///< Determines whether non-existent
///< directory components other than the last one (the "parents") ///< directory components other than the last one (the "parents")
///< are created or not. ///< are created or not.
std::string* ErrMsg = 0 ///< Optional place to put error messages. std::string* ErrMsg = 0 ///< Optional place to put error messages.
); );
@ -518,11 +521,11 @@ namespace sys {
/// file is created. Note that this will both change the Path object /// file is created. Note that this will both change the Path object
/// *and* create the corresponding file. This function will ensure that /// *and* create the corresponding file. This function will ensure that
/// the newly generated temporary file name is unique in the file system. /// the newly generated temporary file name is unique in the file system.
/// @returns true if the file couldn't be created, false otherwise. /// @returns true if the file couldn't be created, false otherwise.
/// @brief Create a unique temporary file /// @brief Create a unique temporary file
bool createTemporaryFileOnDisk( bool createTemporaryFileOnDisk(
bool reuse_current = false, ///< When set to true, this parameter bool reuse_current = false, ///< When set to true, this parameter
///< indicates that if the current file name does not exist then ///< indicates that if the current file name does not exist then
///< it will be used without modification. ///< it will be used without modification.
std::string* ErrMsg = 0 ///< Optional place to put error messages std::string* ErrMsg = 0 ///< Optional place to put error messages
); );
@ -548,8 +551,8 @@ namespace sys {
/// @brief Removes the file or directory from the filesystem. /// @brief Removes the file or directory from the filesystem.
bool eraseFromDisk(bool destroy_contents = false, bool eraseFromDisk(bool destroy_contents = false,
std::string *Err = 0) const; std::string *Err = 0) const;
/// MapInFilePages - This is a low level system API to map in the file /// MapInFilePages - This is a low level system API to map in the file
/// that is currently opened as FD into the current processes' address /// that is currently opened as FD into the current processes' address
/// space for read only access. This function may return null on failure /// space for read only access. This function may return null on failure
@ -560,23 +563,23 @@ namespace sys {
/// present. /// present.
/// 3) The pages must be contiguous. /// 3) The pages must be contiguous.
/// ///
/// This API is not intended for general use, clients should use /// This API is not intended for general use, clients should use
/// MemoryBuffer::getFile instead. /// MemoryBuffer::getFile instead.
static const char *MapInFilePages(int FD, uint64_t FileSize); static const char *MapInFilePages(int FD, uint64_t FileSize);
/// UnMapFilePages - Free pages mapped into the current process by /// UnMapFilePages - Free pages mapped into the current process by
/// MapInFilePages. /// MapInFilePages.
/// ///
/// This API is not intended for general use, clients should use /// This API is not intended for general use, clients should use
/// MemoryBuffer::getFile instead. /// MemoryBuffer::getFile instead.
static void UnMapFilePages(const char *Base, uint64_t FileSize); static void UnMapFilePages(const char *Base, uint64_t FileSize);
/// @} /// @}
/// @name Data /// @name Data
/// @{ /// @{
protected: protected:
mutable std::string path; ///< Storage for the path name. mutable std::string path; ///< Storage for the path name.
/// @} /// @}
}; };
@ -592,23 +595,23 @@ namespace sys {
class PathWithStatus : public Path { class PathWithStatus : public Path {
/// @name Constructors /// @name Constructors
/// @{ /// @{
public: public:
/// @brief Default constructor /// @brief Default constructor
PathWithStatus() : Path(), status(), fsIsValid(false) {} PathWithStatus() : Path(), status(), fsIsValid(false) {}
/// @brief Copy constructor /// @brief Copy constructor
PathWithStatus(const PathWithStatus &that) PathWithStatus(const PathWithStatus &that)
: Path(static_cast<const Path&>(that)), status(that.status), : Path(static_cast<const Path&>(that)), status(that.status),
fsIsValid(that.fsIsValid) {} fsIsValid(that.fsIsValid) {}
/// This constructor allows construction from a Path object /// This constructor allows construction from a Path object
/// @brief Path constructor /// @brief Path constructor
PathWithStatus(const Path &other) PathWithStatus(const Path &other)
: Path(other), status(), fsIsValid(false) {} : Path(other), status(), fsIsValid(false) {}
/// This constructor will accept a std::string as a path. No checking is /// This constructor will accept a std::string as a path. No checking is
/// done on this path to determine if it is valid. To determine validity /// done on this path to determine if it is valid. To determine validity
/// of the path, use the isValid method. /// of the path, use the isValid method.
/// @brief Construct a Path from a string. /// @brief Construct a Path from a string.
explicit PathWithStatus( explicit PathWithStatus(
const std::string& p ///< The path to assign. const std::string& p ///< The path to assign.
@ -616,7 +619,7 @@ namespace sys {
/// This constructor will accept a character range as a path. No checking /// This constructor will accept a character range as a path. No checking
/// is done on this path to determine if it is valid. To determine /// is done on this path to determine if it is valid. To determine
/// validity of the path, use the isValid method. /// validity of the path, use the isValid method.
/// @brief Construct a Path from a string. /// @brief Construct a Path from a string.
explicit PathWithStatus( explicit PathWithStatus(
const char *StrStart, ///< Pointer to the first character of the path const char *StrStart, ///< Pointer to the first character of the path
@ -704,7 +707,7 @@ namespace sys {
} }
std::ostream& operator<<(std::ostream& strm, const sys::Path& aPath); std::ostream& operator<<(std::ostream& strm, const sys::Path& aPath);
inline std::ostream& operator<<(std::ostream& strm, inline std::ostream& operator<<(std::ostream& strm,
const sys::PathWithStatus& aPath) { const sys::PathWithStatus& aPath) {
strm << static_cast<const sys::Path&>(aPath); strm << static_cast<const sys::Path&>(aPath);
return strm; return strm;