llvm.org GIT mirror llvm / a526192
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 Bill Wendling 12 years ago
1 changed file(s) with 42 addition(s) and 39 deletion(s). Raw diff Collapse all Expand all
2727 /// platform independent and eliminates many of the unix-specific fields.
2828 /// However, to support llvm-ar, the mode, user, and group fields are
2929 /// retained. These pertain to unix security and may not have a meaningful
30 /// value on non-Unix platforms. However, the other fields fields should
31 /// always be applicable on all platforms. The structure is filled in by
30 /// value on non-Unix platforms. However, the other fields fields should
31 /// always be applicable on all platforms. The structure is filled in by
3232 /// the PathWithStatus class.
3333 /// @brief File status structure
3434 class FileStatus {
4444
4545 FileStatus() : fileSize(0), modTime(0,0), mode(0777), user(999),
4646 group(999), uniqueID(0), isDir(false), isFile(false) { }
47
47
4848 TimeValue getTimestamp() const { return modTime; }
4949 uint64_t getSize() const { return fileSize; }
5050 uint32_t getMode() const { return mode; }
147147 /// constructor must provide the same result as GetRootDirectory.
148148 /// @brief Construct a path to the current user's "home" directory
149149 static Path GetUserHomeDirectory();
150
150
151151 /// Construct a path to the current directory for the current process.
152152 /// @returns The current working directory.
153153 /// @brief Returns the current working directory.
160160 /// @returns The dynamic link library suffix for the current platform.
161161 /// @brief Return the dynamic link library suffix.
162162 static std::string GetDLLSuffix();
163
163
164164 /// GetMainExecutable - Return the path to the main executable, given the
165165 /// value of argv[0] from program startup and the address of main itself.
166166 static Path GetMainExecutable(const char *argv0, void *MainAddr);
176176
177177 /// This constructor will accept a std::string as a path. No checking is
178178 /// done on this path to determine if it is valid. To determine validity
179 /// of the path, use the isValid method.
179 /// of the path, use the isValid method.
180180 /// @param p The path to assign.
181181 /// @brief Construct a Path from a string.
182182 explicit Path(const std::string& p) : path(p) {}
183183
184184 /// This constructor will accept a character range as a path. No checking
185185 /// is done on this path to determine if it is valid. To determine
186 /// validity of the path, use the isValid method.
186 /// validity of the path, use the isValid method.
187187 /// @param StrStart A pointer to the first character of the path name
188188 /// @param StrLen The length of the path name at StrStart
189189 /// @brief Construct a Path from a string.
190190 explicit Path(const char *StrStart, unsigned StrLen)
191191 : path(StrStart, StrStart+StrLen) {}
192
192
193193 /// @}
194194 /// @name Operators
195195 /// @{
239239 /// @brief Determine if a path is syntactically valid or not.
240240 bool isValid() const;
241241
242 /// This function determines if the contents of the path name are empty.
242 /// This function determines if the contents of the path name are empty.
243243 /// That is, the path name has a zero length. This does NOT determine if
244 /// if the file is empty. To get the length of the file itself, Use the
245 /// PathWithStatus::getFileStatus() method and then the getSize() method
244 /// if the file is empty. To get the length of the file itself, Use the
245 /// PathWithStatus::getFileStatus() method and then the getSize() method
246246 /// on the returned FileStatus object.
247247 /// @returns true iff the path is empty.
248248 /// @brief Determines if the path name is empty (invalid).
268268 /// @returns std::string containing the basename of the path
269269 /// @brief Get the base name of the path
270270 std::string getBasename() const;
271
271
272272 /// This function strips off the suffix of the path beginning with the
273273 /// path separator ('/' on Unix, '\' on Windows) and returns the result.
274274 std::string getDirname() const;
285285 /// @returns a 'C' string containing the path name.
286286 /// @brief Returns the path as a C string.
287287 const char *c_str() const { return path.c_str(); }
288
288
289289 /// size - Return the length in bytes of this path name.
290290 unsigned size() const { return path.size(); }
291
292 /// empty - Returns true if the path is empty.
293 unsigned empty() const { return path.empty(); }
291294
292295 /// @}
293296 /// @name Disk Accessors
302305 bool isRootDirectory() const;
303306
304307 /// This function determines if the path name is absolute, as opposed to
305 /// relative.
308 /// relative.
306309 /// @brief Determine if the path is absolute.
307310 bool isAbsolute() const;
308311
335338 /// bitcode files.
336339 /// @brief Determine if the path references a bitcode file.
337340 bool isBitcodeFile() const;
338
341
339342 /// This function determines if the path name in the object references a
340343 /// native Dynamic Library (shared library, shared object) by looking at
341344 /// the file's magic number. The Path object must reference a file, not a
344347 /// shared library.
345348 /// @brief Determine if the path reference a dynamic library.
346349 bool isDynamicLibrary() const;
347
350
348351 /// This function determines if the path name references an existing file
349352 /// or directory in the file system.
350353 /// @returns true if the pathname references an existing file or
353356 /// the file system.
354357 bool exists() const;
355358
356 /// This function determines if the path name refences an
359 /// This function determines if the path name refences an
357360 /// existing directory.
358361 /// @returns true if the pathname references an existing directory.
359362 /// @brief Determins if the path is a directory in the file system.
360363 bool isDirectory() const;
361
364
362365 /// This function determines if the path name references a readable file
363366 /// or directory in the file system. This function checks for
364367 /// the existence and readability (by the current program) of the file
493496 /// created. The created directory will have no entries.
494497 /// @returns true if the directory could not be created, false otherwise
495498 /// @brief Create the directory this Path refers to.
496 bool createDirectoryOnDisk(
497 bool create_parents = false, ///< Determines whether non-existent
498 ///< directory components other than the last one (the "parents")
499 bool createDirectoryOnDisk(
500 bool create_parents = false, ///< Determines whether non-existent
501 ///< directory components other than the last one (the "parents")
499502 ///< are created or not.
500503 std::string* ErrMsg = 0 ///< Optional place to put error messages.
501504 );
517520 /// file is created. Note that this will both change the Path object
518521 /// *and* create the corresponding file. This function will ensure that
519522 /// the newly generated temporary file name is unique in the file system.
520 /// @returns true if the file couldn't be created, false otherwise.
523 /// @returns true if the file couldn't be created, false otherwise.
521524 /// @brief Create a unique temporary file
522525 bool createTemporaryFileOnDisk(
523 bool reuse_current = false, ///< When set to true, this parameter
524 ///< indicates that if the current file name does not exist then
526 bool reuse_current = false, ///< When set to true, this parameter
527 ///< indicates that if the current file name does not exist then
525528 ///< it will be used without modification.
526529 std::string* ErrMsg = 0 ///< Optional place to put error messages
527530 );
547550 /// @brief Removes the file or directory from the filesystem.
548551 bool eraseFromDisk(bool destroy_contents = false,
549552 std::string *Err = 0) const;
550
551
553
554
552555 /// MapInFilePages - This is a low level system API to map in the file
553556 /// that is currently opened as FD into the current processes' address
554557 /// space for read only access. This function may return null on failure
559562 /// present.
560563 /// 3) The pages must be contiguous.
561564 ///
562 /// This API is not intended for general use, clients should use
565 /// This API is not intended for general use, clients should use
563566 /// MemoryBuffer::getFile instead.
564567 static const char *MapInFilePages(int FD, uint64_t FileSize);
565
568
566569 /// UnMapFilePages - Free pages mapped into the current process by
567570 /// MapInFilePages.
568 ///
569 /// This API is not intended for general use, clients should use
571 ///
572 /// This API is not intended for general use, clients should use
570573 /// MemoryBuffer::getFile instead.
571574 static void UnMapFilePages(const char *Base, uint64_t FileSize);
572
575
573576 /// @}
574577 /// @name Data
575578 /// @{
576579 protected:
577580 mutable std::string path; ///< Storage for the path name.
578
581
579582
580583 /// @}
581584 };
591594 class PathWithStatus : public Path {
592595 /// @name Constructors
593596 /// @{
594 public:
597 public:
595598 /// @brief Default constructor
596599 PathWithStatus() : Path(), status(), fsIsValid(false) {}
597600
598601 /// @brief Copy constructor
599 PathWithStatus(const PathWithStatus &that)
600 : Path(static_cast(that)), status(that.status),
602 PathWithStatus(const PathWithStatus &that)
603 : Path(static_cast(that)), status(that.status),
601604 fsIsValid(that.fsIsValid) {}
602605
603606 /// This constructor allows construction from a Path object
604607 /// @brief Path constructor
605 PathWithStatus(const Path &other)
608 PathWithStatus(const Path &other)
606609 : Path(other), status(), fsIsValid(false) {}
607610
608611 /// This constructor will accept a std::string as a path. No checking is
609612 /// done on this path to determine if it is valid. To determine validity
610 /// of the path, use the isValid method.
613 /// of the path, use the isValid method.
611614 /// @brief Construct a Path from a string.
612615 explicit PathWithStatus(
613616 const std::string& p ///< The path to assign.
615618
616619 /// This constructor will accept a character range as a path. No checking
617620 /// is done on this path to determine if it is valid. To determine
618 /// validity of the path, use the isValid method.
621 /// validity of the path, use the isValid method.
619622 /// @brief Construct a Path from a string.
620623 explicit PathWithStatus(
621624 const char *StrStart, ///< Pointer to the first character of the path
703706 }
704707
705708 std::ostream& operator<<(std::ostream& strm, const sys::Path& aPath);
706 inline std::ostream& operator<<(std::ostream& strm,
709 inline std::ostream& operator<<(std::ostream& strm,
707710 const sys::PathWithStatus& aPath) {
708711 strm << static_cast(aPath);
709712 return strm;