ug4
file_util.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2014: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter, Torbjörn Klatt
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
41 #ifndef __H__UG__FILE_UTIL__
42 #define __H__UG__FILE_UTIL__
43 
44 #include <fstream>
45 #include <vector>
46 #include <string>
47 #include "common/ug_config.h"
48 
49 namespace ug
50 {
51 
54 
67 UG_API bool GetDirectoriesInDirectory(std::vector<std::string>& dirsOut, const char* dir);
68 
78 UG_API bool GetFilesInDirectory(std::vector<std::string>& filesOut, const char* dir);
79 
86 UG_API bool DirectoryExists(const char* dirname);
87 static inline bool DirectoryExists( std::string filename)
88 {
89  return DirectoryExists(filename.c_str());
90 }
97 UG_API bool FileExists( const char *filename );
98 static inline bool FileExists( std::string filename)
99 {
100  return FileExists(filename.c_str());
101 }
102 
111 UG_API size_t FileSize( const char *filename );
112 static inline size_t FileSize( std::string filename)
113 {
114  return FileSize(filename.c_str());
115 }
116 
124 UG_API bool FileTypeIs( const char *filename, const char *extension );
125 
137 UG_API bool CreateDirectoryTMP(const char *directory);
138 
147 UG_API bool CreateDirectory(const char *directory);
148 
157 UG_API bool CreateDirectory(const char *directory, int mode);
158 
165 static inline bool CreateDirectory(std::string directory)
166 {
167  return CreateDirectoryTMP(directory.c_str());
168 }
169 
184 UG_API bool FileCompare( const char *file1, const char *file2 );
185 
192 UG_API std::string GetTmpPath();
193 
200 UG_API bool ReadFile(const char* filename, std::vector<char> &file, bool bText);
201 
202 
210 UG_API std::string MakeTmpFile(std::string filename, const std::string &extension,
211  bool &bSuccess);
212 
214 UG_API void ChangeDirectory(std::string dir);
215 
216 
219 
226 std::string FindFileInStandardPaths(const char* filename);
227 
230 
237 std::string FindDirInStandardPaths(const char* dirname);
238 
243 std::string CurrentWorkingDirectory();
244 
245 // end group ugbase_common_io
247 
248 } // namespace ug
249 
250 #endif // __H__UG__FILE_UTIL__
251 
252 // EOF
UG_API bool FileCompare(const char *file1, const char *file2)
!!! Serial i/o version !!!
Definition: file_util.cpp:95
UG_API bool FileExists(const char *filename)
!!! Serial i/o version !!!
Definition: file_util.cpp:53
UG_API void ChangeDirectory(std::string dir)
Changes the current directory.
Definition: file_util_posix.cpp:164
UG_API bool CreateDirectory(const char *directory)
Creates a directory.
Definition: file_util_posix.cpp:149
bool FileTypeIs(const char *filename, const char *extension)
!!! Serial i/o version !!!
Definition: file_util.cpp:86
UG_API bool CreateDirectoryTMP(const char *directory)
Creates a directory.
Definition: file_util_posix.cpp:144
UG_API bool GetFilesInDirectory(std::vector< std::string > &filesOut, const char *dir)
Returns a list of all files in a directory.
Definition: file_util_posix.cpp:115
UG_API size_t FileSize(const char *filename)
Returns size of the specified file in bytes.
Definition: file_util_posix.cpp:54
UG_API std::string GetTmpPath()
Returns a path to which an application may write temporary files.
Definition: file_util_posix.cpp:159
std::string FindDirInStandardPaths(const char *dirname)
searches the directory in the standard paths.
Definition: file_util.cpp:218
std::string FindFileInStandardPaths(const char *filename)
searches the file in the standard paths.
Definition: file_util.cpp:196
std::string CurrentWorkingDirectory()
Definition: file_util_posix.cpp:171
UG_API bool DirectoryExists(const char *dirname)
Checks the existence of a given directory.
Definition: file_util_posix.cpp:74
UG_API bool GetDirectoriesInDirectory(std::vector< std::string > &dirsOut, const char *dir)
Returns a list of all directories in a directory.
Definition: file_util_posix.cpp:86
bool ReadFile(const char *filename, vector< char > &file, bool bText)
Definition: file_util.cpp:151
#define UG_API
Definition: ug_config.h:65
the ug namespace
string MakeTmpFile(string filename, const string &extension, bool &bSuccess)
!!! Serial i/o version !!!
Definition: file_util.cpp:177