C++ Utilities  4.17.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
path.h
Go to the documentation of this file.
1 #ifndef IOUTILITIES_PATHHELPER_H
2 #define IOUTILITIES_PATHHELPER_H
3 
4 #include "../global.h"
5 
6 #include <list>
7 #include <string>
8 
9 #ifdef PLATFORM_WINDOWS
10 #define PATH_SEP_CHAR '\\'
11 #define SEARCH_PATH_SEP_CHAR ';'
12 #define PATH_SEP_STR "\\"
13 #define SEARCH_PATH_SEP_STR ";"
14 #else
15 #define PATH_SEP_CHAR '/'
16 #define SEARCH_PATH_SEP_CHAR ':'
17 #define PATH_SEP_STR "/"
18 #define SEARCH_PATH_SEP_STR ":"
19 #endif
20 
21 namespace IoUtilities {
22 
26 enum class DirectoryEntryType : unsigned char { None = 0, File = 1, Directory = 2, Symlink = 4, All = 0xFF };
27 
29 {
30  return static_cast<DirectoryEntryType>(static_cast<unsigned char>(lhs) | static_cast<unsigned char>(rhs));
31 }
32 
34 {
35  return (lhs = static_cast<DirectoryEntryType>(static_cast<unsigned char>(lhs) | static_cast<unsigned char>(rhs)));
36 }
37 
39 {
40  return static_cast<DirectoryEntryType>(static_cast<unsigned char>(lhs) & static_cast<unsigned char>(rhs));
41 }
42 
43 CPP_UTILITIES_EXPORT std::string fileName(const std::string &path);
44 CPP_UTILITIES_EXPORT std::string directory(const std::string &path);
47  std::string &result, std::string applicationDirectoryName = std::string(), bool createApplicationDirectory = false);
48 CPP_UTILITIES_EXPORT std::list<std::string> directoryEntries(const char *path, DirectoryEntryType types = DirectoryEntryType::All);
49 } // namespace IoUtilities
50 
51 #endif // IOUTILITIES_PATHHELPER_H
#define CPP_UTILITIES_EXPORT
CPP_UTILITIES_EXPORT std::list< std::string > directoryEntries(const char *path, DirectoryEntryType types=DirectoryEntryType::All)
Returns the names of the directory entries in the specified path with the specified types.
Definition: path.cpp:181
constexpr DirectoryEntryType operator|(DirectoryEntryType lhs, DirectoryEntryType rhs)
Definition: path.h:28
constexpr DirectoryEntryType operator &(DirectoryEntryType lhs, DirectoryEntryType rhs)
Definition: path.h:38
CPP_UTILITIES_EXPORT bool settingsDirectory(std::string &result, std::string applicationDirectoryName=std::string(), bool createApplicationDirectory=false)
Locates a directory meant to store application settings.
Definition: path.cpp:95
Contains utility classes helping to read and write streams.
Definition: binaryreader.h:10
DirectoryEntryType & operator|=(DirectoryEntryType &lhs, DirectoryEntryType rhs)
Definition: path.h:33
CPP_UTILITIES_EXPORT std::string directory(const std::string &path)
Returns the directory of the specified path string (including trailing slash).
Definition: path.cpp:52
CPP_UTILITIES_EXPORT std::string fileName(const std::string &path)
Returns the file name and extension of the specified path string.
Definition: path.cpp:32
CPP_UTILITIES_EXPORT void removeInvalidChars(std::string &fileName)
Removes invalid characters from the specified fileName.
Definition: path.cpp:74
DirectoryEntryType
The DirectoryEntryType enum specifies the type of a directory entry (file, directory or symlink).
Definition: path.h:26