AGXDynamics  2.31.1.0
FileSystem.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
19 #include <agx/agx.h>
20 #include <agx/agxCore_export.h>
21 #include <agx/Callback.h>
22 #include <agx/String.h>
23 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
24 #include <sys/stat.h>
25 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
26 
30 namespace agxIO
31 {
32  struct FileSystem {
33 
34  #ifdef _MSC_VER
35  typedef struct _stat64 StatStruct;
36  #else
37  typedef struct stat StatStruct;
38  #endif
39 
40 #ifndef SWIG
41  AGXCORE_EXPORT static const char* PATH_SEPARATOR;
43 
45  AGXCORE_EXPORT static const char* UNIX_PATH_SEPARATOR;
46 
49 
51  AGXCORE_EXPORT static const char* PATH_DELIMITER;
52 
54  AGXCORE_EXPORT static const char* DLL_SUFFIX;
55 #endif
56 
60  AGXCORE_EXPORT static FILE* openFile( const char* file, const char* mode );
61 
65  AGXCORE_EXPORT static FILE* openFile( const agx::String& str, const char* mode );
66 
71  AGXCORE_EXPORT static bool closeFile( FILE* stream );
72 
76  static AGXCORE_EXPORT agx::String readFile( const agx::String& filename );
77 
84  static AGXCORE_EXPORT bool mkdir(const agx::String& path, bool recursive = false);
85 
90  static AGXCORE_EXPORT bool scan(const agx::String& path, ScanCallback callback);
91 
95  static AGXCORE_EXPORT bool isDir(const agx::String& path);
96 
100  static AGXCORE_EXPORT bool isAbsolute(const agx::String& path);
101 
105  static AGXCORE_EXPORT bool isLink( const agx::String& path );
106 
110  static AGXCORE_EXPORT size_t size( const agx::String& path );
111 
116  static AGXCORE_EXPORT bool exists(const agx::String& path);
117 
122  static AGXCORE_EXPORT bool readable(const agx::String& path);
123 
128  static AGXCORE_EXPORT bool writeable(const agx::String& path);
129 
134 
139  static AGXCORE_EXPORT agx::String mkTmpDirectory(const agx::String& prefix = "");
140  static AGXCORE_EXPORT agx::String mkTmpDirectory(const agx::String& parentDirectory, const agx::String& prefix);
141 
147  static AGXCORE_EXPORT time_t compareDate(const agx::String& path1, const agx::String& path2);
148 
149  static AGXCORE_EXPORT bool rename(const agx::String& oldPath, const agx::String& newPath);
150 
151  static AGXCORE_EXPORT bool copy(const agx::String& source, const agx::String& destination);
152 
153  static AGXCORE_EXPORT bool remove(const agx::String& path, bool recursive = false);
154 
160 
166 
169 
181 
183  static AGXCORE_EXPORT agx::String getFileExtension(const agx::String& filePath);
184 
187 
190 
192  static AGXCORE_EXPORT agx::String getDirectory(const agx::String& filePath);
193 
201  static AGXCORE_EXPORT size_t getFilesInDirectory(agx::StringVector& result, const agx::String& path, bool recursive = false);
202 
211  static AGXCORE_EXPORT agx::String combinePath(const agx::String& path1, const agx::String& path2);
212 
213 
215  static agx::String AGXCORE_EXPORT getPath(const agx::String& path);
216 
222  static agx::String AGXCORE_EXPORT getAbsolutePath( const agx::String& relativePath );
223 
228 
232  static bool AGXCORE_EXPORT setCurrentWorkingDirectory(const agx::String& path);
233 
240  static AGXCORE_EXPORT int stat(const agx::String& path, StatStruct* buf);
241 
246 
247  }; // struct FileSystem
248 } // Namespace agxIO
static AGXCORE_EXPORT agx::String convertUnixFilePathToWindows(const agx::String &unixStyle)
static AGXCORE_EXPORT agx::String convertToNativeFilePath(const agx::String &filePath)
static AGXCORE_EXPORT time_t compareDate(const agx::String &path1, const agx::String &path2)
The agxIO namespace contains classes for reading, writing and finding files.
Definition: Material.h:41
static AGXCORE_EXPORT agx::String convertWindowsFilePathToUnix(const agx::String &windowsStyle)
static AGXCORE_EXPORT bool rename(const agx::String &oldPath, const agx::String &newPath)
static AGXCORE_EXPORT bool scan(const agx::String &path, ScanCallback callback)
static AGXCORE_EXPORT bool isLink(const agx::String &path)
static AGXCORE_EXPORT agx::String readFile(const agx::String &filename)
Read the contents of filename and return it as a String.
static agx::String AGXCORE_EXPORT getAbsolutePath(const agx::String &relativePath)
If is a relative path (isabsolute() returns false), the path will be expanded into a full path using ...
static AGXCORE_EXPORT agx::String getFileWithoutExtension(const agx::String &filePath)
static AGXCORE_EXPORT agx::String convertToColladaFilePath(const agx::String &filePath)
Take a filepath, convert it to Unix format (using UNIX_PATH_SEPARATOR) and finally convert it to a fo...
static AGXCORE_EXPORT const char * PATH_SEPARATOR
Separator between directories in a file path: on unix "/", on windows "\\".
Definition: FileSystem.h:42
static AGXCORE_EXPORT size_t getFilesInDirectory(agx::StringVector &result, const agx::String &path, bool recursive=false)
Returns a list of all files in a directory.
static AGXCORE_EXPORT bool exists(const agx::String &path)
Test if a path exists.
static AGXCORE_EXPORT const char * PATH_DELIMITER
Separator between paths in a list of paths, on unix: ":", on windows ";".
Definition: FileSystem.h:51
static AGXCORE_EXPORT agx::String combinePath(const agx::String &path1, const agx::String &path2)
Combine two paths with a separator.
static AGXCORE_EXPORT bool readable(const agx::String &path)
Test if a path exists and is readable.
static AGXCORE_EXPORT const char * UNIX_PATH_SEPARATOR
Path separator under UNIX "/".
Definition: FileSystem.h:45
static AGXCORE_EXPORT agx::String mkTmpDirectory(const agx::String &prefix="")
Create a temporary directory.
static AGXCORE_EXPORT const char * WINDOWS_PATH_SEPARATOR
Path separator under Windows "\\".
Definition: FileSystem.h:48
static AGXCORE_EXPORT const char * DLL_SUFFIX
Filetype for dynamically loaded libraries (dll / so / dylib)
Definition: FileSystem.h:54
static AGXCORE_EXPORT size_t size(const agx::String &path)
/return The size of the file.
static agx::String AGXCORE_EXPORT getCurrentWorkingDirectory()
static AGXCORE_EXPORT bool isAbsolute(const agx::String &path)
static AGXCORE_EXPORT agx::String getSystemTmpDirectory()
static AGXCORE_EXPORT bool isDir(const agx::String &path)
Test if a path is a directory.
static AGXCORE_EXPORT agx::String getFileWithExtension(const agx::String &filePath)
static AGXCORE_EXPORT bool mkdir(const agx::String &path, bool recursive=false)
Creates a directory on the host file system.
static AGXCORE_EXPORT int stat(const agx::String &path, StatStruct *buf)
Wrapper around the stat-function to work around a bug in Visual Studio when passing an empty string t...
agx::Callback1< const agx::String & > ScanCallback
Scan a directory.
Definition: FileSystem.h:89
static bool AGXCORE_EXPORT setCurrentWorkingDirectory(const agx::String &path)
Set the current working directory.
static AGXCORE_EXPORT agx::String getFileExtension(const agx::String &filePath)
static AGXCORE_EXPORT FILE * openFile(const char *file, const char *mode)
Open a file.
static AGXCORE_EXPORT bool copy(const agx::String &source, const agx::String &destination)
static AGXCORE_EXPORT agx::String getDirectory(const agx::String &filePath)
static agx::String AGXCORE_EXPORT getPath(const agx::String &path)
\ return the path without any ending filename (only the directory/disk) in native format ...
#define AGXCORE_EXPORT
static AGXCORE_EXPORT agx::String getTmpFilename()
static AGXCORE_EXPORT bool closeFile(FILE *stream)
Close the FILE* stream.
static AGXCORE_EXPORT bool writeable(const agx::String &path)
Test if a path exists and is writeable.