1 //===- llvm/System/Path.h ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the llvm::sys::Path class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SYSTEM_PATH_H
15 #define LLVM_SYSTEM_PATH_H
22 /// This class provides an abstraction for the name of a path
23 /// to a file or directory in the filesystem and various basic operations
26 /// @brief An abstraction for operating system paths.
27 class Path : public std::string {
28 /// @name Constructors
31 /// Creates a null (empty) path
32 /// @brief Default Constructor
33 Path () : std::string() {}
35 /// Creates a path from char*
36 /// @brief char* converter
37 Path ( const char * name ) : std::string(name) {
41 /// @brief std::string converter
42 Path ( const std::string& name ) : std::string(name){
46 /// Copies the path with copy-on-write semantics. The \p this Path
47 /// will reference \p the that Path until one of them is modified
48 /// at which point a full copy is taken before the write.
49 /// @brief Copy Constructor
50 Path ( const Path & that ) : std::string(that) {}
52 /// Releases storage associated with the Path object
60 /// Makes a copy of \p that to \p this with copy-on-write semantics.
62 /// @brief Assignment Operator
63 Path & operator = ( const Path & that ) {
68 /// Comparies \p this Path with \p that Path for equality.
69 /// @returns true if \p this and \p that refer to the same item.
70 /// @brief Equality Operator
71 bool operator ==( const Path & that ) const {
72 return 0 == this->compare( that ) ;
75 /// Comparies \p this Path with \p that Path for inequality.
76 /// @returns true if \p this and \p that refer to different items.
77 /// @brief Inequality Operator
78 bool operator !=( const Path & that ) const {
79 return 0 != this->compare( that );
86 /// @returns true if the path is valid
87 /// @brief Determines if the path is valid (properly formed) or not.
88 bool is_valid() const;
90 /// @returns true if the path could reference a file
91 /// @brief Determines if the path is valid for a file reference.
94 /// @returns true if the path could reference a directory
95 /// @brief Determines if the path is valid for a directory reference.
96 bool is_directory() const;
98 /// @brief Fills and zero terminates a buffer with the path
99 void fill( char* buffer, unsigned len ) const;
105 /// This ensures that the pathname is terminated with a /
106 /// @brief Make the path reference a directory.
107 void make_directory();
109 /// This ensures that the pathname is not terminated with a /
110 /// @brief Makes the path reference a file.
114 /// @returns true if the pathname references an existing file.
115 /// @brief Determines if the path is a file or directory in
118 /// The \p dirname is added to the end of the Path.
119 /// @param dirname A string providing the directory name to
120 /// be appended to the path.
121 /// @brief Appends the name of a directory.
122 void append_directory( const std::string& dirname ) {
123 this->append( dirname );
127 /// The \p filename is added to the end of the Path.
128 /// @brief Appends the name of a file.
129 void append_file( const std::string& filename ) {
130 this->append( filename );
133 /// Directories will have no entries. Files will be zero length. If
134 /// the file or directory already exists, no error results.
135 /// @throws SystemException if any error occurs.
136 /// @brief Causes the file or directory to exist in the filesystem.
137 void create( bool create_parents = false );
139 void create_directory( void );
140 void create_directories( void );
141 void create_file( void );
143 /// Directories must be empty before they can be removed. If not,
144 /// an error will result. Files will be unlinked, even if another
145 /// process is using them.
146 /// @brief Removes the file or directory from the filesystem.
148 void remove_directory( void );
149 void remove_file( void );
152 void find_lib( const char * file );