mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0027838: Foundation Classes - support wchar_t* input within TCollection_AsciiString and TCollection_ExtendedString
TCollection_ExtendedString/TCollection_AsciiString description has been updated to reflect usage of this classes for Unicode strings. TCollection_ExtendedString now defines constructor taking wchar_t* (all platforms) and method ::ToWideString() returning wchar_t* (Windows only). TCollection_AsciiString now defines constructor taking wchar_t*. TCollection_ExtendedString/TCollection_AsciiString now defines auxiliary methods ::StartsWith() and ::EndsWith(). TCollection_ExtendedString internals has been updated to eliminate duplicated code for converting between UTF-16 and UTF-8. Code has been cleaned up from redundant explicit conversions to wchar_t*. Global method OSD_OpenStream()/OSD_OpenFileBuf() have been replaced by C++ template to eliminate copy-paste for different STL collections. OSD_SharedLibrary now uses wide-char system API call LoadLibraryExW() on Windows for consistency. New macro Standard_UNUSED has been added for marking possibly unused functions and variables (to suppress gcc/clang compiler warnings).
This commit is contained in:
@@ -12,9 +12,10 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
|
||||
#include <FSD_CmpFile.hxx>
|
||||
|
||||
#include <OSD.hxx>
|
||||
#include <OSD_OpenFile.hxx>
|
||||
#include <Standard_PCharacter.hxx>
|
||||
#include <Storage_BaseDriver.hxx>
|
||||
#include <Storage_StreamExtCharParityError.hxx>
|
||||
@@ -79,40 +80,46 @@ Storage_Error FSD_CmpFile::Open(const TCollection_AsciiString& aName,const Stora
|
||||
SetName(aName);
|
||||
|
||||
if (OpenMode() == Storage_VSNone) {
|
||||
|
||||
#if defined(_WNT32)
|
||||
TCollection_ExtendedString aWName(aName);
|
||||
if (aMode == Storage_VSRead) {
|
||||
myStream.open((const wchar_t*)aWName.ToExtString(),ios::in|ios::binary); // ios::nocreate is not portable
|
||||
std::ios_base::openmode anOpenMode = std::ios_base::openmode(0);
|
||||
switch (aMode)
|
||||
{
|
||||
case Storage_VSNone:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case Storage_VSRead:
|
||||
{
|
||||
// ios::nocreate is not portable
|
||||
#if !defined(IRIX) && !defined(DECOSF1)
|
||||
anOpenMode = ios::in | ios::binary;
|
||||
#else
|
||||
anOpenMode = ios::in;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case Storage_VSWrite:
|
||||
{
|
||||
#if !defined(IRIX) && !defined(DECOSF1)
|
||||
anOpenMode = ios::out | ios::binary;
|
||||
#else
|
||||
anOpenMode = ios::out;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case Storage_VSReadWrite:
|
||||
{
|
||||
#if !defined(IRIX) && !defined(DECOSF1)
|
||||
anOpenMode = ios::in | ios::out | ios::binary;
|
||||
#else
|
||||
anOpenMode = ios::in | ios::out;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (aMode == Storage_VSWrite) {
|
||||
myStream.open((const wchar_t*)aWName.ToExtString(),ios::out|ios::binary);
|
||||
if (anOpenMode != 0)
|
||||
{
|
||||
OSD_OpenStream (myStream, aName, anOpenMode);
|
||||
}
|
||||
else if (aMode == Storage_VSReadWrite) {
|
||||
myStream.open((const wchar_t*)aWName.ToExtString(),ios::in|ios::out|ios::binary);
|
||||
}
|
||||
#elif !defined(IRIX) && !defined(DECOSF1)
|
||||
if (aMode == Storage_VSRead) {
|
||||
myStream.open(aName.ToCString(),ios::in|ios::binary); // ios::nocreate is not portable
|
||||
}
|
||||
else if (aMode == Storage_VSWrite) {
|
||||
myStream.open(aName.ToCString(),ios::out|ios::binary);
|
||||
}
|
||||
else if (aMode == Storage_VSReadWrite) {
|
||||
myStream.open(aName.ToCString(),ios::in|ios::out|ios::binary);
|
||||
}
|
||||
#else
|
||||
if (aMode == Storage_VSRead) {
|
||||
myStream.open(aName.ToCString(),ios::in); // ios::nocreate is not portable
|
||||
}
|
||||
else if (aMode == Storage_VSWrite) {
|
||||
myStream.open(aName.ToCString(),ios::out);
|
||||
}
|
||||
else if (aMode == Storage_VSReadWrite) {
|
||||
myStream.open(aName.ToCString(),ios::in|ios::out);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (myStream.fail()) {
|
||||
result = Storage_VSOpenError;
|
||||
}
|
||||
|
@@ -12,9 +12,10 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
|
||||
#include <FSD_File.hxx>
|
||||
|
||||
#include <OSD.hxx>
|
||||
#include <OSD_OpenFile.hxx>
|
||||
#include <Storage_BaseDriver.hxx>
|
||||
#include <Storage_StreamExtCharParityError.hxx>
|
||||
#include <Storage_StreamFormatError.hxx>
|
||||
@@ -79,30 +80,36 @@ Storage_Error FSD_File::Open(const TCollection_AsciiString& aName,const Storage_
|
||||
|
||||
SetName(aName);
|
||||
|
||||
if (OpenMode() == Storage_VSNone) {
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
TCollection_ExtendedString aWName(aName);
|
||||
if (aMode == Storage_VSRead) {
|
||||
myStream.open( (const wchar_t*) aWName.ToExtString(),ios::in); // ios::nocreate is not portable
|
||||
if (OpenMode() == Storage_VSNone)
|
||||
{
|
||||
std::ios_base::openmode anOpenMode = std::ios_base::openmode(0);
|
||||
switch (aMode)
|
||||
{
|
||||
case Storage_VSNone:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case Storage_VSRead:
|
||||
{
|
||||
// ios::nocreate is not portable
|
||||
anOpenMode = ios::in;
|
||||
break;
|
||||
}
|
||||
case Storage_VSWrite:
|
||||
{
|
||||
anOpenMode = ios::out;
|
||||
break;
|
||||
}
|
||||
case Storage_VSReadWrite:
|
||||
{
|
||||
anOpenMode = ios::in | ios::out;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (aMode == Storage_VSWrite) {
|
||||
myStream.open( (const wchar_t*) aWName.ToExtString(),ios::out);
|
||||
if (anOpenMode != 0)
|
||||
{
|
||||
OSD_OpenStream (myStream, aName.ToCString(), anOpenMode);
|
||||
}
|
||||
else if (aMode == Storage_VSReadWrite) {
|
||||
myStream.open( (const wchar_t*) aWName.ToExtString(),ios::in|ios::out);
|
||||
#else
|
||||
if (aMode == Storage_VSRead) {
|
||||
myStream.open(aName.ToCString(),ios::in); // ios::nocreate is not portable
|
||||
}
|
||||
else if (aMode == Storage_VSWrite) {
|
||||
myStream.open(aName.ToCString(),ios::out);
|
||||
}
|
||||
else if (aMode == Storage_VSReadWrite) {
|
||||
myStream.open(aName.ToCString(),ios::in|ios::out);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (myStream.fail()) {
|
||||
result = Storage_VSOpenError;
|
||||
}
|
||||
|
Reference in New Issue
Block a user