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