94708556 |
1 | // Copyright (c) 2014 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | //! Auxiulary file to provide Unicode compatibility for file open functionality |
15 | //! Names of files are encoded as UTF-16 strings |
16 | |
17 | #ifndef _OSD_OpenFile_HeaderFile |
18 | #define _OSD_OpenFile_HeaderFile |
19 | |
20 | #include <Standard_Macro.hxx> |
21 | |
22 | #if defined(__cplusplus) |
23 | |
24 | #include <fstream> |
25 | #include <TCollection_ExtendedString.hxx> |
fb0b0531 |
26 | #include <NCollection_UtfString.hxx> |
94708556 |
27 | |
fb0b0531 |
28 | //! Function opens the file. |
94708556 |
29 | //! @param theName name of file encoded in UTF-16 |
30 | //! @param theMode opening mode |
fb0b0531 |
31 | //! @return file handle of opened file |
32 | __Standard_API FILE* OSD_OpenFile (const TCollection_ExtendedString& theName, |
33 | const char* theMode); |
94708556 |
34 | |
fb0b0531 |
35 | //! Function retrieves file timestamp. |
b40693b0 |
36 | //! @param theName name of file encoded in UTF-8 |
fb0b0531 |
37 | //! @return stat.st_ctime value |
38 | __Standard_API Standard_Time OSD_FileStatCTime (const char* theName); |
b40693b0 |
39 | |
40 | //! Function opens the file stream. |
41 | //! @param theStream stream to open |
94708556 |
42 | //! @param theName name of file encoded in UTF-8 |
43 | //! @param theMode opening mode |
fb0b0531 |
44 | template <typename T> |
45 | inline void OSD_OpenStream (T& theStream, |
46 | const char* theName, |
47 | const std::ios_base::openmode theMode) |
48 | { |
49 | #if defined(_WIN32) && defined(_MSC_VER) |
50 | // file name is treated as UTF-8 string and converted to UTF-16 one |
51 | const TCollection_ExtendedString aFileNameW (theName, Standard_True); |
52 | theStream.open (aFileNameW.ToWideString(), theMode); |
53 | #else |
54 | theStream.open (theName, theMode); |
55 | #endif |
56 | } |
94708556 |
57 | |
fb0b0531 |
58 | //! Function opens the file stream. |
59 | //! @param theStream stream to open |
94708556 |
60 | //! @param theName name of file encoded in UTF-16 |
61 | //! @param theMode opening mode |
fb0b0531 |
62 | template <typename T> |
63 | inline void OSD_OpenStream (T& theStream, |
64 | const TCollection_ExtendedString& theName, |
65 | const std::ios_base::openmode theMode) |
66 | { |
67 | #if defined(_WIN32) && defined(_MSC_VER) |
68 | theStream.open (theName.ToWideString(), theMode); |
69 | #else |
70 | // conversion in UTF-8 for linux |
71 | NCollection_Utf8String aString (theName.ToExtString()); |
72 | theStream.open (aString.ToCString(), theMode); |
73 | #endif |
74 | } |
ce0594b8 |
75 | |
94708556 |
76 | extern "C" { |
77 | #endif // __cplusplus |
78 | |
79 | //! Function opens the file. |
80 | //! @param theName name of file encoded in UTF-8 |
81 | //! @param theMode opening mode |
82 | //! @return file handle of opened file |
83 | __Standard_API FILE* OSD_OpenFile (const char* theName, const char* theMode); |
84 | |
85 | #if defined(__cplusplus) |
86 | } |
87 | #endif // __cplusplus |
88 | |
89 | #endif // _OSD_OpenFile_HeaderFile |