Warning, file /include/opencascade/OSD_OpenFile.hxx was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef _OSD_OpenFile_HeaderFile
0018 #define _OSD_OpenFile_HeaderFile
0019
0020 #include <Standard_Macro.hxx>
0021
0022 #if defined(__cplusplus)
0023
0024 #include <fstream>
0025 #include <TCollection_ExtendedString.hxx>
0026 #include <NCollection_UtfString.hxx>
0027
0028 #if defined(_WIN32) && defined(__GLIBCXX__)
0029 #include <ext/stdio_filebuf.h> // __gnu_cxx::stdio_filebuf
0030 #endif
0031
0032
0033
0034
0035
0036 Standard_EXPORT FILE* OSD_OpenFile(const TCollection_ExtendedString& theName, const char* theMode);
0037
0038
0039
0040
0041 Standard_EXPORT std::time_t OSD_FileStatCTime(const char* theName);
0042
0043
0044
0045
0046
0047 Standard_EXPORT int OSD_OpenFileDescriptor(const TCollection_ExtendedString& theName,
0048 ::std::ios_base::openmode theMode);
0049
0050
0051
0052
0053
0054
0055 inline bool OSD_OpenStream(::std::filebuf& theFileBuf,
0056 const TCollection_ExtendedString& theName,
0057 const std::ios_base::openmode theMode)
0058 {
0059 #if defined(_WIN32)
0060 #if defined(__GLIBCXX__)
0061
0062 if (theFileBuf.is_open())
0063 return false;
0064
0065
0066
0067
0068
0069 const int aFileDesc = OSD_OpenFileDescriptor(theName.ToWideString(), theMode);
0070 __gnu_cxx::stdio_filebuf<char> aGccBuf(aFileDesc, theMode);
0071 if (aGccBuf.is_open())
0072 {
0073 theFileBuf.swap(aGccBuf);
0074 return true;
0075 }
0076 return false;
0077 #else
0078 return theFileBuf.open(theName.ToWideString(), theMode) != 0;
0079 #endif
0080 #else
0081
0082 NCollection_UtfString<char> aString(theName.ToExtString());
0083 return theFileBuf.open(aString.ToCString(), theMode) != nullptr;
0084 #endif
0085 }
0086
0087
0088
0089
0090
0091 template <typename T>
0092 inline void OSD_OpenStream(T& theStream,
0093 const TCollection_ExtendedString& theName,
0094 const std::ios_base::openmode theMode)
0095 {
0096 #if defined(_WIN32)
0097 #if defined(__GLIBCXX__)
0098
0099
0100
0101
0102 if (!OSD_OpenStream(*theStream.rdbuf(), theName, theMode))
0103 {
0104 theStream.setstate(std::ios_base::failbit);
0105 }
0106 else
0107 {
0108 theStream.clear();
0109 }
0110 #else
0111 theStream.open(theName.ToWideString(), theMode);
0112 #endif
0113 #else
0114
0115 NCollection_UtfString<char> aString(theName.ToExtString());
0116 theStream.open(aString.ToCString(), theMode);
0117 #endif
0118 }
0119
0120
0121
0122
0123
0124 template <typename T>
0125 inline void OSD_OpenStream(T& theStream, const char* theName, const std::ios_base::openmode theMode)
0126 {
0127 #if defined(_WIN32)
0128
0129 const TCollection_ExtendedString aFileNameW(theName, true);
0130 OSD_OpenStream(theStream, aFileNameW, theMode);
0131 #else
0132 theStream.open(theName, theMode);
0133 #endif
0134 }
0135
0136 extern "C"
0137 {
0138 #endif
0139
0140
0141
0142
0143
0144 Standard_EXPORT FILE* OSD_OpenFile(const char* theName, const char* theMode);
0145
0146 #if defined(__cplusplus)
0147 }
0148 #endif
0149
0150 #endif