SGL
privatefilelib.h
1 /*
2  * File: privatefilelib.h
3  * ----------------------
4  * This file exports a standardized set of tools for working with
5  * files. The library offers at least some portability across the
6  * file systems used in the three supported platforms: Mac OSX,
7  * Windows, and Linux. Directory and search paths are allowed to
8  * contain separators in any of the supported styles, which usually
9  * makes it possible to use the same code on different platforms.
10  * This functionality is considered "private" and not to be used by students.
11  *
12  * @version 2021/04/09
13  * - moved to private SGL namespace
14  * @version 2021/04/03
15  * - removed dependency on custom collections
16  * @version 2018/10/23
17  * - added getAbsolutePath
18  * @version 2018/09/25
19  * - added doc comments for new documentation generation
20  * @version 2016/11/12
21  * - added fileSize, readEntireStream
22  * @version 2015/04/12
23  * - added promptUserForFile overload without stream parameter
24  * @version 2014/10/19
25  * - alphabetized function declarations
26  * - converted many funcs to take const string& rather than string for efficiency
27  * - added listDirectory overload that returns a Vector
28  */
29 
30 
31 #ifndef _private_filelib_h
32 #define _private_filelib_h
33 
34 #include <iostream>
35 #include <fstream>
36 #include <string>
37 #include <vector>
38 
39 namespace sgl {
40 namespace priv {
41 namespace filelib {
42 
46 bool fileExists(const string& filename);
47 
52 string getAbsolutePath(const string& path);
53 
57 string getDirectoryPathSeparator();
58 
66 string getExtension(const string& filename);
67 
81 string getHead(const string& filename);
82 
87 string getTempDirectory();
88 
92 bool isDirectory(const string& filename);
93 
99 std::vector<string> listDirectory(const string& path);
100 
106 void readEntireFile(std::istream& is, std::vector<string>& lines);
107 
113 string readEntireFile(const string& filename);
114 
119 string readEntireStream(std::istream& input);
120 
129 bool writeEntireFile(const string& filename,
130  const string& text,
131  bool append = false);
132 
137 namespace platform {
138  void filelib_createDirectory(const string& path);
139  void filelib_deleteFile(const string& path);
140  string filelib_expandPathname(const string& filename);
141  bool filelib_fileExists(const string& filename);
142  string filelib_getAbsolutePath(const string& path);
143  string filelib_getCurrentDirectory();
144  string filelib_getDirectoryPathSeparator();
145  string filelib_getSearchPathSeparator();
146  string filelib_getTempDirectory();
147  bool filelib_isDirectory(const string& filename);
148  bool filelib_isFile(const string& filename);
149  bool filelib_isSymbolicLink(const string& filename);
150  void filelib_listDirectory(const string& path, std::vector<string>& list);
151  void filelib_setCurrentDirectory(const string& path);
152 } // namespace platform
153 
154 } // namespace filelib
155 } // namespace priv
156 } // namespace sgl
157 
158 #endif // _private_filelib_h
Definition: console.h:45