]> Dogcows Code - chaz/yoink/blobdiff - src/stlplus/portability/file_system.hpp
testing new non-autotools build system
[chaz/yoink] / src / stlplus / portability / file_system.hpp
diff --git a/src/stlplus/portability/file_system.hpp b/src/stlplus/portability/file_system.hpp
new file mode 100644 (file)
index 0000000..374e86d
--- /dev/null
@@ -0,0 +1,201 @@
+#ifndef STLPLUS_FILE_SYSTEM\r
+#define STLPLUS_FILE_SYSTEM\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+//   Author:    Andy Rushton\r
+//   Copyright: (c) Southampton University 1999-2004\r
+//              (c) Andy Rushton           2004-2009\r
+//   License:   BSD License, see ../docs/license.html\r
+\r
+//   Simplified access to the File system\r
+\r
+//   All file system access and filename manipulation should be done\r
+//   with this package. Then it is only necessary to port this package\r
+//   to port all file handling.\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+#include "portability_fixes.hpp"\r
+#include <string>\r
+#include <vector>\r
+#include <time.h>\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+namespace stlplus\r
+{\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // implement string comparison of paths - Unix is case-sensitive, Windows is case-insensitive\r
+\r
+  bool path_compare(const std::string& l, const std::string& r);\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // classifying functions\r
+\r
+  // test for whether there's something (i.e. folder or file) with this name\r
+  bool is_present(const std::string& thing);\r
+  // test for whether there's something present and its a folder\r
+  bool is_folder(const std::string& thing);\r
+  // test for whether there's something present and its a file\r
+  bool is_file(const std::string& thing);\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // file functions\r
+\r
+  // tests whether there's a file of this name\r
+  bool file_exists(const std::string& filespec);\r
+  // tests whether the file is readable - i.e. exists and has read mode set\r
+  bool file_readable(const std::string& filespec);\r
+  // tests whether file is writable - either it exists and is writable or doesn't exist but is in a writable folder\r
+  bool file_writable(const std::string& filespec);\r
+  // the size of the file in bytes - 0 if doesn't exist\r
+  size_t file_size(const std::string& filespec);\r
+  // delete the file - returns true if the delete succeeded\r
+  bool file_delete(const std::string& filespec);\r
+  // rename the file - returns true if the rename succeeded\r
+  bool file_rename (const std::string& old_filespec, const std::string& new_filespec);\r
+  // make an exact copy of the file - returns true if it succeeded\r
+  bool file_copy (const std::string& old_filespec, const std::string& new_filespec);\r
+  // move the file - tries to rename, if that fails, tries to copy - returns true if either of these succeeded\r
+  bool file_move (const std::string& old_filespec, const std::string& new_filespec);\r
+\r
+  // get the file's time stamps as a time_t - see the stlplus time.hpp package\r
+\r
+  // time the file was originally created\r
+  time_t file_created(const std::string& filespec);\r
+  // time the file was last modified\r
+  time_t file_modified(const std::string& filespec);\r
+  // time the file was accessed\r
+  time_t file_accessed(const std::string& filespec);\r
+\r
+  // platform-specific string handling to combine a directory and filename into a path\r
+\r
+  // combine a folder with a filename (basename.extension)\r
+  std::string create_filespec(const std::string& folder, const std::string& filename);\r
+  // combine a folder, a basename and an extension - extension does not need the .\r
+  std::string create_filespec(const std::string& folder, const std::string& basename, const std::string& extension);\r
+  // combine a basename and an extension - extension does not need the .\r
+  std::string create_filename(const std::string& basename, const std::string& extension);\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // folder functions\r
+\r
+  // craete a folder - returns true if successful\r
+  bool folder_create(const std::string& folder);\r
+  // tests for whether the folder exists, i.e. there is something of that name and its a folder\r
+  bool folder_exists(const std::string& folder);\r
+  // test whether the folder contents are readable\r
+  bool folder_readable(const std::string& folder);\r
+  // tests whether the folder can be written to - for example to create a new file\r
+  bool folder_writable(const std::string& folder);\r
+  // delete the folder, optionally deleting the contents first - only succeeds if everything could be deleted\r
+  bool folder_delete(const std::string& folder, bool recurse = false);\r
+  // rename the folder - this probably only works within a disk/partition\r
+  bool folder_rename (const std::string& old_directory, const std::string& new_directory);\r
+  // test whether the folder is empty (of files)\r
+  bool folder_empty(const std::string& folder);\r
+\r
+  // set the current folder\r
+  bool folder_set_current(const std::string& folder);\r
+\r
+  // platform-specific string handling to retrieve some special locations\r
+  // these do not check whether the folder exists, they just process strings\r
+\r
+  // get the current folder\r
+  std::string folder_current(void);\r
+  // get the current folder as a full path\r
+  std::string folder_current_full(void);\r
+  // get the home folder - $HOME or %HOMEDRIVE%%HOMEPATH%\r
+  std::string folder_home(void);\r
+  // go down a level in the folder hierarchy\r
+  std::string folder_down(const std::string& folder, const std::string& subfolder);\r
+  // go up a level in the folder hierarchy\r
+  std::string folder_up(const std::string& folder, unsigned levels = 1);\r
+\r
+  // get folder contents\r
+\r
+  // the set of all subdirectories\r
+  std::vector<std::string> folder_subdirectories(const std::string& folder);\r
+  // the set of all files\r
+  std::vector<std::string> folder_files(const std::string& folder);\r
+  // the set of all folders and files\r
+  std::vector<std::string> folder_all(const std::string& folder);\r
+  // the set of all folder contents matching a wildcard string\r
+  // if folders is true, include folders; if files is true, include files\r
+  std::vector<std::string> folder_wildcard(const std::string& folder,\r
+                                           const std::string& wildcard,\r
+                                           bool folders = true,\r
+                                           bool files = true);\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // path functions\r
+\r
+  // string manipulations of paths\r
+\r
+  // test whether a string represents a full path or a relative one\r
+  bool is_full_path(const std::string& path);\r
+  bool is_relative_path(const std::string& path);\r
+\r
+  // convert to a full path relative to the root path\r
+  std::string folder_to_path(const std::string& root, const std::string& folder);\r
+  std::string filespec_to_path(const std::string& root, const std::string& filespec);\r
+\r
+  // convert to a full path relative to the current working directory\r
+  std::string folder_to_path(const std::string& folder);\r
+  std::string filespec_to_path(const std::string& filespec);\r
+\r
+  // convert to a relative path relative to the root path\r
+  std::string folder_to_relative_path(const std::string& root, const std::string& folder);\r
+  std::string filespec_to_relative_path(const std::string& root, const std::string& filespec);\r
+\r
+  // convert to a relative path relative to the current working directory\r
+  std::string folder_to_relative_path(const std::string& folder);\r
+  std::string filespec_to_relative_path(const std::string& filespec);\r
+\r
+  // append a folder separator to the path to make it absolutely clear that it is a folder\r
+  std::string folder_append_separator(const std::string& folder);\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // access functions split a filespec into its elements\r
+\r
+  // get the basename - that is, the name of the file without folder or extension parts\r
+  std::string basename_part(const std::string& filespec);\r
+  // get the filename - that is, the name of the file without folder part but with extension\r
+  std::string filename_part(const std::string& filespec);\r
+  // get the extension - that is the part of the filename after the . (and excluding the .)\r
+  std::string extension_part(const std::string& filespec);\r
+  // get the folder part - that is the filespec with the filename removed\r
+  std::string folder_part(const std::string& filespec);\r
+\r
+  // split a path into a vector of elements - i.e. split at the folder separator\r
+  std::vector<std::string> folder_elements(const std::string& folder);\r
+  std::vector<std::string> filespec_elements(const std::string& filespec);\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // Path lookup functions\r
+\r
+#ifdef MSWINDOWS\r
+#define PATH_SPLITTER ";"\r
+#else\r
+#define PATH_SPLITTER ":"\r
+#endif\r
+\r
+  // The lookup normally carried out by the shell to find a command in a\r
+  // directory in the PATH. Give this function the name of a command and it\r
+  // will return the full path. It returns an empty string on failure.\r
+  std::string path_lookup (const std::string& command);\r
+\r
+  // Generalised form of the above, takes a second argument\r
+  // - the list to search. This can be used to do other path lookups,\r
+  // such as LD_LIBRARY_PATH. The third argument specifies the splitter -\r
+  // the default value of PATH_SPLITTER is appropriate for environment variables.\r
+  std::string lookup (const std::string& file, const std::string& path, const std::string& splitter = PATH_SPLITTER);\r
+\r
+  // utility function for finding the folder that contains the current executable\r
+  // the argument is the argv[0] parameter passed to main\r
+  std::string install_path(const std::string& argv0);\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+\r
+} // end namespace stlplus\r
+\r
+#endif\r
This page took 0.024425 seconds and 4 git commands to generate.