]> OCCT Git - occt-copy.git/commitdiff
0026890: Foundation Classes, TKernel - define OSD_OpenStream for std::ifstream
authorisk <isk@opencascade.com>
Wed, 18 Nov 2015 12:49:08 +0000 (15:49 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 19 Nov 2015 12:25:19 +0000 (15:25 +0300)
src/OSD/OSD_OpenFile.cxx
src/OSD/OSD_OpenFile.hxx

index c2e37cd7037ccda183ab6f2f911f499fba040ea1..938622b74c27af5996b0f1eb12673ae7ade4d1b2 100644 (file)
@@ -123,3 +123,36 @@ void OSD_OpenStream(std::ofstream& theStream,
 #endif
 }
 
+// ==============================================
+// function : OSD_OpenStream
+// purpose  : Opens file stream
+// ==============================================
+void OSD_OpenStream (std::ifstream&                theStream,
+                     const char*                   theName,
+                     const std::ios_base::openmode theMode)
+{
+#ifdef _WIN32
+  // file name is treated as UTF-8 string and converted to UTF-16 one
+  const TCollection_ExtendedString aFileNameW (theName, Standard_True);
+  theStream.open ((const wchar_t*)aFileNameW.ToExtString(), theMode);
+#else
+  theStream.open (theName, theMode);
+#endif
+}
+
+// ==============================================
+// function : OSD_OpenStream
+// purpose  : Opens file stream
+// ==============================================
+void OSD_OpenStream (std::ifstream&                    theStream,
+                     const TCollection_ExtendedString& theName,
+                     const std::ios_base::openmode     theMode)
+{
+#ifdef _WIN32
+  theStream.open ((const wchar_t*)theName.ToExtString(), theMode);
+#else
+  // conversion in UTF-8 for linux
+  NCollection_Utf8String aString ((const Standard_Utf16Char*)theName.ToExtString());
+  theStream.open (aString.ToCString(), theMode);
+#endif
+}
index 5c4a70aafd51eb3bc18962b5ec6bacfb1ad5a7c5..ca8bf7bf56b7b9ff808023eca0e80356ef41b392 100644 (file)
@@ -40,6 +40,22 @@ __Standard_API void OSD_OpenStream (std::ofstream& theStream,
                                     const TCollection_ExtendedString& theName,
                                     const std::ios_base::openmode theMode);
 
+//! Function opens the file stream.
+//! @param theStream stream to open
+//! @param theName name of file encoded in UTF-8
+//! @param theMode opening mode
+__Standard_API void OSD_OpenStream (std::ifstream&                theStream,
+                                    const char*                   theName,
+                                    const std::ios_base::openmode theMode);
+
+//! Function opens the file stream.
+//! @param theStream stream to open
+//! @param theName name of file encoded in UTF-16
+//! @param theMode opening mode
+__Standard_API void OSD_OpenStream (std::ifstream&                    theStream,
+                                    const TCollection_ExtendedString& theName,
+                                    const std::ios_base::openmode     theMode);
+
 //! Function opens the file buffer.
 //! @param theBuff file buffer to open
 //! @param theName name of file encoded in UTF-8