GlobalObjects
Loading...
Searching...
No Matches
EuFileHelper.h
Go to the documentation of this file.
1#ifndef INC_EuFILEHELPER_H
2#define INC_EuFILEHELPER_H
3//-----------------------------------------------------------------------------
51//-----------------------------------------------------------------------------
52#include <EuToolTypes.h>
53#include <string>
54#include <fstream>
55#include <vector>
56
57#if defined(_MSC_VER)
58# if _HAS_CXX17
59# include <filesystem>
60 namespace fs = std::filesystem;
61# define _HAS_FILESYSTEM
62# endif // _HAS_CXX17
63#elif defined(__MINGW32__) || defined(__MINGW64__)
64# if defined __has_include
65# if __has_include (<filesystem>)
66# include <filesystem>
67 namespace fs = std::filesystem;
68# define _HAS_FILESYSTEM
69# elif __has_include (<experimental/filesystem>)
70# include <experimental/filesystem>
71 namespace fs = std::experimental::filesystem;
72# define _HAS_FILESYSTEM
73# endif
74# endif
75# include <windows.h>
76#elif defined(__GNUC__)
77# if (__cplusplus >= 201103L && __cplusplus < 202102)
78# include <experimental/filesystem>
79 namespace fs = std::experimental::filesystem;
80# define _HAS_FILESYSTEM
81# endif
82#endif
83//-----------------------------------------------------------------------------
84namespace eut
85{
86 //---------------------------------------------------------------------------
87 // Forwards
88 #ifdef __EUFILEHELPER_WITH_EUBLOB
89 class Blob;
90 #endif //__EUFILEHELPER_WITH_EUBLOB
91 //---------------------------------------------------------------------------
127 namespace FileHelper
128 {
129 //============= Static-Methoden
130 //-------------------------------------------------------------------------
132
150 __tool_export_dll int storeFile( char * pszData,
151 std::streamsize nSize,
152 const std::string & rsFileName );
153 //#if defined(_MSC_VER) || defined(__MINGW32__)
154 __tool_export_dll int storeFile( char * pszData,
155 std::streamsize nSize,
156 const std::wstring & rsFileName );
157 //#endif // defined(_MSC_VER) || defined(__MINGW32__)
159 //-------------------------------------------------------------------------
176 __tool_export_dll int storeFile( const std::string & rsStr,
177 const std::string & rsFileName );
178 //-------------------------------------------------------------------------
179 #if defined(_MSC_VER)
180 //-------------------------------------------------------------------------
199 __tool_export_dll int lockFile( std::ofstream *& prLockFile,
200 const std::string & rsLockFileName );
201 //-------------------------------------------------------------------------
202 #elif defined(__MINGW32__) || defined(__MINGW64__)
203 //-------------------------------------------------------------------------
223 __tool_export_dll int lockFile( void *& prLockFileHandle,
224 const std::string & rsLockFileName );
225 //-------------------------------------------------------------------------
226 #elif defined(__GNUC__)
227 //-------------------------------------------------------------------------
254 __tool_export_dll int lockFile( int & riLockFileHandle,
255 const std::string & rsLockFileName );
256 //-------------------------------------------------------------------------
257 #endif // defined(_MSC_VER) <> defined(__MINGW32__) || defined(__MINGW64__) <> defined(__GNUC__)
258 //-------------------------------------------------------------------------
259 #ifdef __EUFILEHELPER_WITH_EUBLOB
260 //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
262
282 __tool_export_dll int storeFile( const Blob * pBlob,
283 const std::string & rsFileName );
284 //#if defined(_MSC_VER) || defined(__MINGW32__)
285 __tool_export_dll int storeFile( const Blob * pBlob,
286 const std::wstring & rsFileName );
287 //#endif // defined(_MSC_VER) || defined(__MINGW32__)
289 //-------------------------------------------------------------------------
291
311 __tool_export_dll int storeFile( const Blob & rBlob,
312 const std::string & rsFileName );
313 //#if defined(_MSC_VER) || defined(__MINGW32__)
314 __tool_export_dll int storeFile( const Blob & rBlob,
315 const std::wstring & rsFileName );
316 //#endif // defined(_MSC_VER) || defined(__MINGW32__)
318 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
319 #endif // __EUFILEHELPER_WITH_EUBLOB
320 //-------------------------------------------------------------------------
322
347 __tool_export_dll int loadFile( char *& prszData,
348 std::streamsize & rnSize,
349 const std::string & rsFileName,
350 bool bText = false );
351 //#if defined(_MSC_VER) || defined(__MINGW32__)
352 __tool_export_dll int loadFile( char *& prszData,
353 std::streamsize & rnSize,
354 const std::wstring & rsFileName,
355 bool bText = false );
356 //#endif // defined(_MSC_VER) || defined(__MINGW32__)
358 //-------------------------------------------------------------------------
374 __tool_export_dll int loadFile( std::string & rstr,
375 const std::string & rsFileName );
376 //-------------------------------------------------------------------------
377 #ifdef __EUFILEHELPER_WITH_EUBLOB
378 //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
380
406 const std::string & rsFileName );
407 //#if defined(_MSC_VER) || defined(__MINGW32__)
409 const std::wstring & rsFileName );
410 //#endif // defined(_MSC_VER) || defined(__MINGW32__)
412 //-------------------------------------------------------------------------
414
438 const std::string & rsFileName );
439 //#if defined(_MSC_VER) || defined(__MINGW32__)
441 const std::wstring & rsFileName );
442 //#endif // defined(_MSC_VER) || defined(__MINGW32__)
444 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
445 #endif // __EUFILEHELPER_WITH_EUBLOB
446 //-------------------------------------------------------------------------
448
477 __tool_export_dll int openInputFile( std::ifstream *& pInputFileStream,
478 const std::string & rsFileName );
479 //#if defined(_MSC_VER) || defined(__MINGW32__)
480 __tool_export_dll int openInputFile( std::ifstream *& pInputFileStream,
481 const std::wstring & rsFileName );
482 //#endif // defined(_MSC_VER) || defined(__MINGW32__)
484 //-------------------------------------------------------------------------
486
515 __tool_export_dll int openInputFile( std::wifstream *& pInputFileStream,
516 const std::string & rsFileName );
517 //#if defined(_MSC_VER) || defined(__MINGW32__)
518 __tool_export_dll int openInputFile( std::wifstream *& pInputFileStream,
519 const std::wstring & rsFileName );
520 //#endif // defined(_MSC_VER) || defined(__MINGW32__)
522 //-------------------------------------------------------------------------
524
551 __tool_export_dll int openOutputFile( std::ofstream *& pOutputFileStream,
552 const std::string & rsFileName );
553 //#if defined(_MSC_VER) || defined(__MINGW32__)
554 __tool_export_dll int openOutputFile( std::ofstream *& pOutputFileStream,
555 const std::wstring & rsFileName );
556 //#endif // defined(_MSC_VER) || defined(__MINGW32__)
558 //-------------------------------------------------------------------------
560
587 __tool_export_dll int openOutputFile( std::wofstream *& pOutputFileStream,
588 const std::string & rsFileName );
589 //#if defined(_MSC_VER) || defined(__MINGW32__)
590 __tool_export_dll int openOutputFile( std::wofstream *& pOutputFileStream,
591 const std::wstring & rsFileName );
592 //#endif // defined(_MSC_VER) || defined(__MINGW32__)
594 //-------------------------------------------------------------------------
614 __tool_export_dll int closeInputFile( std::ifstream *& pFileStream );
615 //-------------------------------------------------------------------------
635 __tool_export_dll int closeInputFile( std::wifstream *& pFileStream );
636 //-------------------------------------------------------------------------
656 __tool_export_dll int closeOutputFile( std::ofstream *& pFileStream );
657 //-------------------------------------------------------------------------
677 __tool_export_dll int closeOutputFile( std::wofstream *& pFileStream );
678 //-------------------------------------------------------------------------
680
697 __tool_export_dll int makeDir( const std::string & rsNewPath );
698 #ifdef _HAS_FILESYSTEM
699 __tool_export_dll int makeDir( const std::wstring & rsNewPath );
700 #endif //_HAS_FILESYSTEM
702 //-------------------------------------------------------------------------
704
719 __tool_export_dll int makePath( const std::string & rsNewPath );
720 #ifdef _HAS_FILESYSTEM
721 __tool_export_dll int makePath( const std::wstring & rsNewPath );
722 #endif //_HAS_FILESYSTEM
724 //-------------------------------------------------------------------------
743 __tool_export_dll int dirExist( const std::string & rsCheckPath );
744 //-------------------------------------------------------------------------
761 __tool_export_dll int dirExist( const std::wstring & rsCheckPath );
762 //-------------------------------------------------------------------------
775 //-------------------------------------------------------------------------
788 //-------------------------------------------------------------------------
804 __tool_export_dll int fileExist( const std::string & rsFullFileName );
805 //-------------------------------------------------------------------------
821 __tool_export_dll int fileExist( const std::wstring & rsFullFileName );
822 //-------------------------------------------------------------------------
848 __tool_export_dll int copyFile( const std::string & rsSourceFileName,
849 const std::string & rsTargetFileName );
850 //-------------------------------------------------------------------------
852
877 __tool_export_dll void splitPath( const std::string & rsFullFileName,
878 std::string & rsDrive,
879 std::string & rsPath,
880 std::string & rsFileName,
881 std::string & rsFileExtension );
882 #ifdef _HAS_FILESYSTEM
883 __tool_export_dll void splitPath( const std::wstring & rsFullFileName,
884 std::wstring & rsDrive,
885 std::wstring & rsPath,
886 std::wstring & rsFileName,
887 std::wstring & rsFileExtension );
888 #endif //_HAS_FILESYSTEM
890 //-------------------------------------------------------------------------
891 #ifndef _HAS_FILESYSTEM
892 //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
936 __tool_export_dll void splitPath( const char * pszFullFileName,
937 char * pszDrive,
938 char * pszPath,
939 char * pszFileName,
940 char * pszFileExtension );
941 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
942 #endif // _HAS_FILESYSTEM
943 //-------------------------------------------------------------------------
944 #ifdef _HAS_FILESYSTEM
945 //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
965 typedef void (*PROCESSING_FILE_MEMBERPTR)( const fs::path & rFullFileName );
966 //-------------------------------------------------------------------------
984 typedef void (*PROCESSING_DIR_MEMBERPTR)( const fs::path & rFullPathName );
985 //-------------------------------------------------------------------------
986 #ifdef _MSC_VER
987 // warning C4100: "rFullFileName": Unreferenzierter formaler Parameter
988 #pragma warning( disable : 4100 )
989 #endif
990 //-------------------------------------------------------------------------
991 #if defined(__GNUC__)
992 // Warnung: unused parameter 'rFullFileName' [-Wunused-parameter]
993 #pragma GCC diagnostic push
994 #pragma GCC diagnostic ignored "-Wunused-parameter"
995 #endif
996 //-------------------------------------------------------------------------
1014 {
1015 public:
1016 //-----------------------------------------------------------------------
1032 virtual void processFileFount( const fs::path & rFullFileName ){};
1033 //-----------------------------------------------------------------------
1047 virtual void processDirFount( const fs::path & rFullPathName ){};
1048 //-----------------------------------------------------------------------
1049 };
1050 //-------------------------------------------------------------------------
1051 #if defined(__GNUC__)
1052 // Warnung: unused parameter 'rFullFileName' [-Wunused-parameter]
1053 #pragma GCC diagnostic pop
1054 #endif
1055 //-------------------------------------------------------------------------
1056 #ifdef _MSC_VER
1057 // warning C4100: "rFullFileName": Unreferenzierter formaler Parameter
1058 #pragma warning( default : 4100 )
1059 #endif
1060 //-------------------------------------------------------------------------
1061 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1062 #endif // _HAS_FILESYSTEM
1063 //-------------------------------------------------------------------------
1080 __tool_export_dll int deleteFile( const std::string & rsFullFileName );
1081 //-------------------------------------------------------------------------
1082 #ifdef _HAS_FILESYSTEM
1083 //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
1084 //-------------------------------------------------------------------------
1105 __tool_export_dll int deleteFile( const fs::path & rFullFileName );
1106 //-------------------------------------------------------------------------
1152 __tool_export_dll void deleteFileForIterateDirectory( const fs::path & rFullFileName );
1153 //-------------------------------------------------------------------------
1194 int _iterateDirectory( const fs::path & rIterPath,
1195 bool bRecursive,
1196 PROCESSING_FILE_MEMBERPTR ProcessingFileFunction,
1197 PROCESSING_DIR_MEMBERPTR ProcessingDirFunction,
1198 CallBackFileDirFount * pProcessingObject );
1199 //-------------------------------------------------------------------------
1233 __tool_export_dll int iterateDirectory( const fs::path & rIterPath,
1234 bool bRecursive,
1235 PROCESSING_FILE_MEMBERPTR ProcessingFileFunction,
1236 PROCESSING_DIR_MEMBERPTR ProcessingDirFunction );
1237 //---------------------------------------------------------------------------
1268 __tool_export_dll int iterateDirectory( const fs::path & rIterPath,
1269 bool bRecursive,
1270 CallBackFileDirFount & rProcessingObject );
1271 //-------------------------------------------------------------------------
1273
1299 __tool_export_dll void getFullFileName( std::string & rsFullFileName,
1300 const fs::path & rFileSystemPath,
1301 const char & rSeparator = '/' );
1302 __tool_export_dll void getFullFileName( std::wstring & rsFullFileName,
1303 const fs::path & rFileSystemPath,
1304 const std::wstring & rSeparator = L"/" );
1306 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1307 #endif // _HAS_FILESYSTEM
1308 //-------------------------------------------------------------------------
1309 #ifdef __EUFILEHELPER_WITH_EUBLOB
1310 //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
1312
1337 int _getswapDatavalue( std::string & sOutText,
1338 const std::string & sInText,
1339 const std::string & sTextOrFile );
1340 int _getswapDatavalue( std::string & sOutText,
1341 const std::wstring & sInText,
1342 const std::string & sTextOrFile );
1344 //-------------------------------------------------------------------------
1346
1454 __tool_export_dll int swapDataInFile( std::vector< std::string > & rParamVector, bool bSimulate = false );
1455 //#if ( defined(_MSC_VER) || defined(__MINGW32__) ) && (__cplusplus >= 201103L) && defined(_HAS_FILESYSTEM)
1456 #if (__cplusplus >= 201103L) && defined(_HAS_FILESYSTEM)
1457 __tool_export_dll int swapDataInFile( std::vector< std::wstring > & rParamVector, bool bSimulate = false );
1458 //#endif // ( defined(_MSC_VER) || defined(__MINGW32__) ) && (d__cplusplus >= 201103L) && defined(_HAS_FILESYSTEM)
1459 #endif // (d__cplusplus >= 201103L) && defined(_HAS_FILESYSTEM)
1461 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1462 #endif // __EUFILEHELPER_WITH_EUBLOB
1463 //-------------------------------------------------------------------------
1464 };
1465 //---------------------------------------------------------------------------
1466} // namespace eut
1467#endif
For each library, here 'EuTools' there is a type file.
#define __tool_export_dll
Definition EuToolTypes.h:77
This class allows to edit a blob (insert, copy, search etc.).
Definition EuBlob.h:75
Definition EuFileHelper.h:1014
virtual void processDirFount(const fs::path &rFullPathName)
Definition EuFileHelper.h:1047
virtual void processFileFount(const fs::path &rFullFileName)
Definition EuFileHelper.h:1032
__tool_export_dll int closeOutputFile(std::ofstream *&pFileStream)
void(* PROCESSING_DIR_MEMBERPTR)(const fs::path &rFullPathName)
Definition EuFileHelper.h:984
__tool_export_dll int copyFile(const std::string &rsSourceFileName, const std::string &rsTargetFileName)
__tool_export_dll int lockFile(std::ofstream *&prLockFile, const std::string &rsLockFileName)
__tool_export_dll int closeInputFile(std::ifstream *&pFileStream)
__tool_export_dll int loadFile(char *&prszData, std::streamsize &rnSize, const std::string &rsFileName, bool bText=false)
Returns the content and size of a file from the file system.
void(* PROCESSING_FILE_MEMBERPTR)(const fs::path &rFullFileName)
Definition EuFileHelper.h:965
__tool_export_dll void splitPath(const std::string &rsFullFileName, std::string &rsDrive, std::string &rsPath, std::string &rsFileName, std::string &rsFileExtension)
Expects a file name including path (e.g.
__tool_export_dll void deleteFileForIterateDirectory(const fs::path &rFullFileName)
__tool_export_dll std::string getCurrentWorkingDirAsString()
__tool_export_dll std::wstring getCurrentWorkingDirAsWString()
int _iterateDirectory(const fs::path &rIterPath, bool bRecursive, PROCESSING_FILE_MEMBERPTR ProcessingFileFunction, PROCESSING_DIR_MEMBERPTR ProcessingDirFunction, CallBackFileDirFount *pProcessingObject)
int _getswapDatavalue(std::string &sOutText, const std::string &sInText, const std::string &sTextOrFile)
Helper function for swapDataInFile (...) which contains a value in a std::string which either comes f...
__tool_export_dll int dirExist(const std::string &rsCheckPath)
__tool_export_dll int iterateDirectory(const fs::path &rIterPath, bool bRecursive, PROCESSING_FILE_MEMBERPTR ProcessingFileFunction, PROCESSING_DIR_MEMBERPTR ProcessingDirFunction)
__tool_export_dll int openInputFile(std::ifstream *&pInputFileStream, const std::string &rsFileName)
Returns an open file of type std::ifstream for writing to the File system.
__tool_export_dll void getFullFileName(std::string &rsFullFileName, const fs::path &rFileSystemPath, const char &rSeparator='/')
Sets the full file name in the passed string from the passed fs::path, even if it is only relative.
__tool_export_dll int fileExist(const std::string &rsFullFileName)
__tool_export_dll int makeDir(const std::string &rsNewPath)
Creates passed directory(s).
__tool_export_dll int deleteFile(const std::string &rsFullFileName)
__tool_export_dll int openOutputFile(std::ofstream *&pOutputFileStream, const std::string &rsFileName)
Returns an open file of type std::ofstream for reading in the file system.
__tool_export_dll int swapDataInFile(std::vector< std::string > &rParamVector, bool bSimulate=false)
Searches and replaces contents in files and saves them under a different name if desired.
__tool_export_dll int makePath(const std::string &rsNewPath)
Creates passed directory(s).
__tool_export_dll int storeFile(char *pszData, std::streamsize nSize, const std::string &rsFileName)
Saves data to a file in the file system.
Definition IniFile.h:62