AGXDynamics  2.35.0.2
FileSystem.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 
27 namespace agxIO
28 {
29  struct FileSystem {
30 
31  #ifdef _MSC_VER
32  typedef struct _stat64 StatStruct;
33  #else
34  typedef struct stat StatStruct;
35  #endif
36 
37 #ifndef SWIG
38  AGXCORE_EXPORT static const char* PATH_SEPARATOR;
40 
42  AGXCORE_EXPORT static const char* UNIX_PATH_SEPARATOR;
43 
46 
48  AGXCORE_EXPORT static const char* PATH_DELIMITER;
49 
51  AGXCORE_EXPORT static const char* DLL_SUFFIX;
52 #endif
53 
57  AGXCORE_EXPORT static FILE* openFile( const char* file, const char* mode );
58 
62  AGXCORE_EXPORT static FILE* openFile( const agx::String& str, const char* mode );
63 
68  AGXCORE_EXPORT static bool closeFile( FILE* stream );
69 
73  static AGXCORE_EXPORT agx::String readFile( const agx::String& filename );
74 
81  static AGXCORE_EXPORT bool mkdir(const agx::String& path, bool recursive = false);
82 
87  static AGXCORE_EXPORT bool scan(const agx::String& path, ScanCallback callback);
88 
92  static AGXCORE_EXPORT bool isDir(const agx::String& path);
93 
97  static AGXCORE_EXPORT bool isAbsolute(const agx::String& path);
98 
102  static AGXCORE_EXPORT bool isLink( const agx::String& path );
103 
107  static AGXCORE_EXPORT size_t size( const agx::String& path );
108 
113  static AGXCORE_EXPORT bool exists(const agx::String& path);
114 
119  static AGXCORE_EXPORT bool readable(const agx::String& path);
120 
125  static AGXCORE_EXPORT bool writeable(const agx::String& path);
126 
131 
136  static AGXCORE_EXPORT agx::String mkTmpDirectory(const agx::String& prefix = "");
137  static AGXCORE_EXPORT agx::String mkTmpDirectory(const agx::String& parentDirectory, const agx::String& prefix);
138 
144  static AGXCORE_EXPORT time_t compareDate(const agx::String& path1, const agx::String& path2);
145 
146  static AGXCORE_EXPORT bool rename(const agx::String& oldPath, const agx::String& newPath);
147 
148  static AGXCORE_EXPORT bool copy(const agx::String& source, const agx::String& destination);
149 
150  static AGXCORE_EXPORT bool remove(const agx::String& path, bool recursive = false);
151 
157 
163 
166 
178 
180  static AGXCORE_EXPORT agx::String getFileExtension(const agx::String& filePath);
181 
184 
187 
189  static AGXCORE_EXPORT agx::String getDirectory(const agx::String& filePath);
190 
198  static AGXCORE_EXPORT size_t getFilesInDirectory(agx::StringVector& result, const agx::String& path, bool recursive = false);
199 
208  static AGXCORE_EXPORT agx::String combinePath(const agx::String& path1, const agx::String& path2);
209 
210 
212  static agx::String AGXCORE_EXPORT getPath(const agx::String& path);
213 
219  static agx::String AGXCORE_EXPORT getAbsolutePath( const agx::String& relativePath );
220 
225 
229  static bool AGXCORE_EXPORT setCurrentWorkingDirectory(const agx::String& path);
230 
237  static AGXCORE_EXPORT int stat(const agx::String& path, StatStruct* buf);
238 
243 
244  }; // struct FileSystem
245 } // Namespace agxIO
AGXCORE_EXPORT
#define AGXCORE_EXPORT
agxIO::FileSystem::isAbsolute
static AGXCORE_EXPORT bool isAbsolute(const agx::String &path)
agxIO::FileSystem::mkdir
static AGXCORE_EXPORT bool mkdir(const agx::String &path, bool recursive=false)
Creates a directory on the host file system.
agxIO::FileSystem::combinePath
static AGXCORE_EXPORT agx::String combinePath(const agx::String &path1, const agx::String &path2)
Combine two paths with a separator.
agxIO::FileSystem::PATH_DELIMITER
static const AGXCORE_EXPORT char * PATH_DELIMITER
Separator between paths in a list of paths, on unix: ":", on windows ";".
Definition: FileSystem.h:48
agx::Vector< AgXString< std::string > >
agxIO::FileSystem::openFile
static AGXCORE_EXPORT FILE * openFile(const char *file, const char *mode)
Open a file.
agxIO::FileSystem::PATH_SEPARATOR
static const AGXCORE_EXPORT char * PATH_SEPARATOR
Separator between directories in a file path: on unix "/", on windows "\\".
Definition: FileSystem.h:39
agxIO::FileSystem::getSystemTmpDirectory
static AGXCORE_EXPORT agx::String getSystemTmpDirectory()
agxIO::FileSystem::mkTmpDirectory
static AGXCORE_EXPORT agx::String mkTmpDirectory(const agx::String &prefix="")
Create a temporary directory.
agxIO::FileSystem::getAbsolutePath
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 ...
agxIO::FileSystem::copy
static AGXCORE_EXPORT bool copy(const agx::String &source, const agx::String &destination)
agxIO::FileSystem::convertToNativeFilePath
static AGXCORE_EXPORT agx::String convertToNativeFilePath(const agx::String &filePath)
agxIO::FileSystem::WINDOWS_PATH_SEPARATOR
static const AGXCORE_EXPORT char * WINDOWS_PATH_SEPARATOR
Path separator under Windows "\\".
Definition: FileSystem.h:45
agxIO::FileSystem::ScanCallback
agx::Callback1< const agx::String & > ScanCallback
Scan a directory.
Definition: FileSystem.h:86
agxIO::FileSystem::remove
static AGXCORE_EXPORT bool remove(const agx::String &path, bool recursive=false)
agxIO::FileSystem::getDirectory
static AGXCORE_EXPORT agx::String getDirectory(const agx::String &filePath)
agxIO::FileSystem::StatStruct
struct stat StatStruct
Definition: FileSystem.h:34
agxIO::FileSystem::UNIX_PATH_SEPARATOR
static const AGXCORE_EXPORT char * UNIX_PATH_SEPARATOR
Path separator under UNIX "/".
Definition: FileSystem.h:42
Callback.h
agxIO::FileSystem::stat
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...
agxIO::FileSystem::readFile
static AGXCORE_EXPORT agx::String readFile(const agx::String &filename)
Read the contents of filename and return it as a String.
agxIO::FileSystem::writeable
static AGXCORE_EXPORT bool writeable(const agx::String &path)
Test if a path exists and is writeable.
PushDisableWarnings.h
agxIO::FileSystem::compareDate
static AGXCORE_EXPORT time_t compareDate(const agx::String &path1, const agx::String &path2)
agxIO::FileSystem::convertToColladaFilePath
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...
agxIO::FileSystem::getTmpFilename
static AGXCORE_EXPORT agx::String getTmpFilename()
agxIO::FileSystem::getFileWithoutExtension
static AGXCORE_EXPORT agx::String getFileWithoutExtension(const agx::String &filePath)
agxCore_export.h
agxIO::FileSystem::size
static AGXCORE_EXPORT size_t size(const agx::String &path)
/return The size of the file.
agxIO::FileSystem::convertUnixFilePathToWindows
static AGXCORE_EXPORT agx::String convertUnixFilePathToWindows(const agx::String &unixStyle)
agxIO::FileSystem::convertWindowsFilePathToUnix
static AGXCORE_EXPORT agx::String convertWindowsFilePathToUnix(const agx::String &windowsStyle)
agxIO::FileSystem::getPath
static agx::String AGXCORE_EXPORT getPath(const agx::String &path)
\ return the path without any ending filename (only the directory/disk) in native format
agx.h
agxIO::FileSystem::closeFile
static AGXCORE_EXPORT bool closeFile(FILE *stream)
Close the FILE* stream.
agx::Callback1< const agx::String & >
agxIO::FileSystem::scan
static AGXCORE_EXPORT bool scan(const agx::String &path, ScanCallback callback)
agxIO::FileSystem::getFileExtension
static AGXCORE_EXPORT agx::String getFileExtension(const agx::String &filePath)
agxIO::FileSystem::isDir
static AGXCORE_EXPORT bool isDir(const agx::String &path)
Test if a path is a directory.
agxIO::FileSystem::exists
static AGXCORE_EXPORT bool exists(const agx::String &path)
Test if a path exists.
agxIO::FileSystem::getFileWithExtension
static AGXCORE_EXPORT agx::String getFileWithExtension(const agx::String &filePath)
agxIO::FileSystem::getFilesInDirectory
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.
agxIO::FileSystem::getCurrentWorkingDirectory
static agx::String AGXCORE_EXPORT getCurrentWorkingDirectory()
agxIO::FileSystem::setCurrentWorkingDirectory
static bool AGXCORE_EXPORT setCurrentWorkingDirectory(const agx::String &path)
Set the current working directory.
String.h
agxIO::FileSystem::readable
static AGXCORE_EXPORT bool readable(const agx::String &path)
Test if a path exists and is readable.
agx::AgXString< std::string >
agxIO::FileSystem::isLink
static AGXCORE_EXPORT bool isLink(const agx::String &path)
agxIO::FileSystem::rename
static AGXCORE_EXPORT bool rename(const agx::String &oldPath, const agx::String &newPath)
agxIO::FileSystem
Definition: FileSystem.h:29
agxIO
The agxIO namespace contains classes for reading, writing and finding files.
Definition: Material.h:41
agxIO::FileSystem::DLL_SUFFIX
static const AGXCORE_EXPORT char * DLL_SUFFIX
Filetype for dynamically loaded libraries (dll / so / dylib)
Definition: FileSystem.h:51
PopDisableWarnings.h