C++ Utilities  4.6.1
Common C++ classes and routines used by my applications 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 <string>
7 #include <list>
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
27 {
28  None = 0,
29  File = 1,
30  Directory = 2,
31  Symlink = 4,
32  All = 0xFF
33 };
34 
36 {
37  return static_cast<DirectoryEntryType>(static_cast<unsigned char>(lhs) | static_cast<unsigned char>(rhs));
38 }
39 
41 {
42  return (lhs = static_cast<DirectoryEntryType>(static_cast<unsigned char>(lhs) | static_cast<unsigned char>(rhs)));
43 }
44 
46 {
47  return static_cast<DirectoryEntryType>(static_cast<unsigned char>(lhs) & static_cast<unsigned char>(rhs));
48 }
49 
50 CPP_UTILITIES_EXPORT std::string fileName(const std::string &path);
51 CPP_UTILITIES_EXPORT std::string directory(const std::string &path);
52 CPP_UTILITIES_EXPORT void removeInvalidChars(std::string &fileName);
53 CPP_UTILITIES_EXPORT bool settingsDirectory(std::string &result, std::string applicationDirectoryName = std::string(), bool createApplicationDirectory = false);
54 CPP_UTILITIES_EXPORT std::list<std::string> directoryEntries(const char *path, DirectoryEntryType types = DirectoryEntryType::All);
55 
56 }
57 
58 #endif // IOUTILITIES_PATHHELPER_H
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:35
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:40
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
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
constexpr DirectoryEntryType operator &(DirectoryEntryType lhs, DirectoryEntryType rhs)
Definition: path.h:45