SGL
privatefilelib.h
1 /*
2  * File: filelib.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  *
11  * @version 2021/04/03
12  * - removed dependency on custom collections
13  * @version 2018/10/23
14  * - added getAbsolutePath
15  * @version 2018/09/25
16  * - added doc comments for new documentation generation
17  * @version 2016/11/12
18  * - added fileSize, readEntireStream
19  * @version 2016/08/12
20  * - added second overload of openFileDialog that accepts path parameter
21  * @version 2015/04/12
22  * - added promptUserForFile overload without stream parameter
23  * @version 2014/10/19
24  * - alphabetized function declarations
25  * - converted many funcs to take const string& rather than string for efficiency
26  * - added listDirectory overload that returns a Vector
27  */
28 
29 
30 #ifndef _filelib_h
31 #define _filelib_h
32 
33 #include <iostream>
34 #include <fstream>
35 #include <string>
36 #include <vector>
37 
41 bool fileExists(const string& filename);
42 
47 string getAbsolutePath(const string& path);
48 
52 string getDirectoryPathSeparator();
53 
61 string getExtension(const string& filename);
62 
76 string getHead(const string& filename);
77 
82 string getTempDirectory();
83 
87 bool isDirectory(const string& filename);
88 
94 std::vector<string> listDirectory(const string& path);
95 
101 void readEntireFile(std::istream& is, std::vector<string>& lines);
102 
108 string readEntireFile(const string& filename);
109 
114 string readEntireStream(std::istream& input);
115 
124 bool writeEntireFile(const string& filename,
125  const string& text,
126  bool append = false);
127 
132 namespace platform {
133  string file_openFileDialog(const string& title, const string& mode, const string& path);
134  void filelib_createDirectory(const string& path);
135  void filelib_deleteFile(const string& path);
136  string filelib_expandPathname(const string& filename);
137  bool filelib_fileExists(const string& filename);
138  string filelib_getAbsolutePath(const string& path);
142  string filelib_getTempDirectory();
143  bool filelib_isDirectory(const string& filename);
144  bool filelib_isFile(const string& filename);
145  bool filelib_isSymbolicLink(const string& filename);
146  void filelib_listDirectory(const string& path, std::vector<string>& list);
147  void filelib_setCurrentDirectory(const string& path);
148 }
149 
150 #endif // _filelib_h
Platform-dependent functions that differ by operating system.
Definition: privatefilelib.cpp:190
string filelib_expandPathname(string filename)
Definition: privatefilelib.cpp:211
void filelib_setCurrentDirectory(string path)
Definition: privatefilelib.cpp:341
string filelib_getCurrentDirectory()
Definition: privatefilelib.cpp:259
string file_openFileDialog(string , string , string )
Definition: privatefilelib.cpp:334
string filelib_getSearchPathSeparator()
Definition: privatefilelib.cpp:275
void filelib_deleteFile(string path)
Definition: privatefilelib.cpp:207
bool filelib_fileExists(string filename)
Definition: privatefilelib.cpp:247
string filelib_getAbsolutePath(string path)
Definition: privatefilelib.cpp:252
bool filelib_isFile(string filename)
Definition: privatefilelib.cpp:298
void filelib_createDirectory(string path)
Definition: privatefilelib.cpp:192
void filelib_listDirectory(string path, std::vector< string > &list)
Definition: privatefilelib.cpp:314
string filelib_getDirectoryPathSeparator()
Definition: privatefilelib.cpp:271
bool filelib_isSymbolicLink(string filename)
Definition: privatefilelib.cpp:306
bool filelib_isDirectory(string filename)
Definition: privatefilelib.cpp:290
string filelib_getTempDirectory()
Definition: privatefilelib.cpp:281