From: kgv Date: Fri, 5 Aug 2016 19:49:11 +0000 (+0300) Subject: 0027676: Foundation Classes - define Standard_ExtCharacter, Standard_Utf16Char using... X-Git-Tag: V7_1_0_beta~208 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=c885cfda247430e8541458769ea2df7c7933b2fb 0027676: Foundation Classes - define Standard_ExtCharacter, Standard_Utf16Char using C++11 types char16_t --- diff --git a/dox/dev_guides/upgrade/upgrade.md b/dox/dev_guides/upgrade/upgrade.md index a05803ceec..3dcab3388a 100644 --- a/dox/dev_guides/upgrade/upgrade.md +++ b/dox/dev_guides/upgrade/upgrade.md @@ -1011,6 +1011,16 @@ The implementation of Graphic3d_Group::SetGroupPrimitivesAspect() has been chang Although it was not documented, previosly it was possible to modify single aspects instance (like Graphic3d_AspectFillArea3d) and set it to multiple groups. Now such code would produce unexpected result and therefore should be updated to create dedicated aspect instance. +@subsection upgrade_710_types Typedefs + +The following type definitions in OCCT has been modified to use C++11 types: +- *Standard_ExtCharacter* is now *char16_t* (previously *short*). +- *Standard_ExtString;* is now *const char16_t* (previously *const short*). +- *Standard_Utf16Char* is now *char16_t* (previously *uint16_t* for compatibility with old compilers). +- *Standard_Utf32Char* is now *char32_t* (previously *uint32_t* for compatibility with old compilers). + +For most applications this change should be transparent, since the size of types have not been changed. + @subsection upgrade_710_removed Removed features The following obsolete features have been removed: diff --git a/samples/mfc/occtdemo/Common/WNT/OCCDemoDoc.cpp b/samples/mfc/occtdemo/Common/WNT/OCCDemoDoc.cpp index 86cbe9b4a8..31efa40129 100755 --- a/samples/mfc/occtdemo/Common/WNT/OCCDemoDoc.cpp +++ b/samples/mfc/occtdemo/Common/WNT/OCCDemoDoc.cpp @@ -46,7 +46,7 @@ COCCDemoDoc::COCCDemoDoc() Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice = ((COCCDemoApp*)AfxGetApp())->GetGraphicDevice(); - myViewer = new V3d_Viewer(theGraphicDevice,(short *) "Visu3D"); + myViewer = new V3d_Viewer(theGraphicDevice,(Standard_ExtString )"Visu3D"); myViewer->SetDefaultLights(); myViewer->SetLightOn(); myViewer->SetDefaultBackgroundColor(Quantity_TOC_RGB, 0.,0.,0.); diff --git a/samples/mfc/standard/08_HLR/src/SelectionDialog.cpp b/samples/mfc/standard/08_HLR/src/SelectionDialog.cpp index 465ee387bf..f4ff794744 100644 --- a/samples/mfc/standard/08_HLR/src/SelectionDialog.cpp +++ b/samples/mfc/standard/08_HLR/src/SelectionDialog.cpp @@ -129,7 +129,7 @@ void CSelectionDialog::OnDisplay (bool isFit) Handle(Graphic3d_GraphicDriver) aGraphicDriver = ((CHLRApp*)AfxGetApp())->GetGraphicDriver(); - myActiveViewer = new V3d_Viewer (aGraphicDriver, (short *) "Visu3D"); + myActiveViewer = new V3d_Viewer (aGraphicDriver, (Standard_ExtString )"Visu3D"); myActiveViewer->SetDefaultLights(); myActiveViewer->SetLightOn(); myActiveView = myActiveViewer->CreateView(); diff --git a/samples/mfc/standard/10_Convert/src/WNT/OCCDemoDoc.cpp b/samples/mfc/standard/10_Convert/src/WNT/OCCDemoDoc.cpp index b79e2be484..6f1b1fd448 100755 --- a/samples/mfc/standard/10_Convert/src/WNT/OCCDemoDoc.cpp +++ b/samples/mfc/standard/10_Convert/src/WNT/OCCDemoDoc.cpp @@ -46,7 +46,7 @@ COCCDemoDoc::COCCDemoDoc() Handle(Graphic3d_GraphicDriver) aGraphicDriver = ((COCCDemoApp*)AfxGetApp())->GetGraphicDriver(); - myViewer = new V3d_Viewer(aGraphicDriver,(short *) "Visu3D"); + myViewer = new V3d_Viewer(aGraphicDriver, (Standard_ExtString )"Visu3D"); myViewer->SetDefaultLights(); myViewer->SetLightOn(); myViewer->SetDefaultBackgroundColor(Quantity_TOC_RGB, 0.,0.,0.); diff --git a/src/DDF/DDF_IOStream.cxx b/src/DDF/DDF_IOStream.cxx index 45e17bf778..77ae98ff13 100644 --- a/src/DDF/DDF_IOStream.cxx +++ b/src/DDF/DDF_IOStream.cxx @@ -413,7 +413,7 @@ Storage_BaseDriver& DDF_IOStream::PutCharacter(const Standard_Character aValue) Storage_BaseDriver& DDF_IOStream::PutExtCharacter(const Standard_ExtCharacter aValue) { - *myOStream << aValue << " "; + *myOStream << (short )aValue << " "; if (myOStream->bad()) Storage_StreamWriteError::Raise("PutExtCharacter"); return *this; } @@ -499,7 +499,9 @@ Storage_BaseDriver& DDF_IOStream::GetCharacter(Standard_Character& aValue) Storage_BaseDriver& DDF_IOStream::GetExtCharacter(Standard_ExtCharacter& aValue) { - if (!(*myIStream >> aValue)) Storage_StreamTypeMismatchError::Raise("GetExtCharacter"); + short aChar = 0; + if (!(*myIStream >> aChar)) Storage_StreamTypeMismatchError::Raise("GetExtCharacter"); + aValue = aChar; return *this; } diff --git a/src/FSD/FSD_CmpFile.cxx b/src/FSD/FSD_CmpFile.cxx index 5a50e3156f..eb0fd5767c 100644 --- a/src/FSD/FSD_CmpFile.cxx +++ b/src/FSD/FSD_CmpFile.cxx @@ -447,7 +447,7 @@ Storage_BaseDriver& FSD_CmpFile::PutCharacter(const Standard_Character aValue) Storage_BaseDriver& FSD_CmpFile::PutExtCharacter(const Standard_ExtCharacter aValue) { - myStream << aValue << " "; + myStream << (short )aValue << " "; if (myStream.bad()) Storage_StreamWriteError::Raise(); return *this; } @@ -539,8 +539,9 @@ Storage_BaseDriver& FSD_CmpFile::GetCharacter(Standard_Character& aValue) Storage_BaseDriver& FSD_CmpFile::GetExtCharacter(Standard_ExtCharacter& aValue) { - if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise(); - + short aChar = 0; + if (!(myStream >> aChar)) Storage_StreamTypeMismatchError::Raise(); + aValue = aChar; return *this; } diff --git a/src/FSD/FSD_File.cxx b/src/FSD/FSD_File.cxx index e5f17857c8..9fb391eccd 100644 --- a/src/FSD/FSD_File.cxx +++ b/src/FSD/FSD_File.cxx @@ -443,7 +443,7 @@ Storage_BaseDriver& FSD_File::PutCharacter(const Standard_Character aValue) Storage_BaseDriver& FSD_File::PutExtCharacter(const Standard_ExtCharacter aValue) { - myStream << aValue << " "; + myStream << (short )aValue << " "; if (myStream.bad()) Storage_StreamWriteError::Raise(); return *this; } @@ -535,8 +535,9 @@ Storage_BaseDriver& FSD_File::GetCharacter(Standard_Character& aValue) Storage_BaseDriver& FSD_File::GetExtCharacter(Standard_ExtCharacter& aValue) { - if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise(); - + short aChar = 0; + if (!(myStream >> aChar)) Storage_StreamTypeMismatchError::Raise(); + aValue = aChar; return *this; } diff --git a/src/Standard/Standard.cxx b/src/Standard/Standard.cxx index a976f865ce..bfc3280715 100644 --- a/src/Standard/Standard.cxx +++ b/src/Standard/Standard.cxx @@ -19,6 +19,7 @@ #include #include #include +#include #include #if(defined(_WIN32) || defined(__WIN32__)) @@ -80,6 +81,13 @@ Standard_MMgrFactory::Standard_MMgrFactory() _configthreadlocale (-1); #endif*/ + // Check basic assumption. + // If assertion happens, then OCCT should be corrected for compatibility with such CPU architecture. + Standard_STATIC_ASSERT(sizeof(Standard_Utf8Char) == 1); + Standard_STATIC_ASSERT(sizeof(short) == 2); + Standard_STATIC_ASSERT(sizeof(Standard_Utf16Char) == 2); + Standard_STATIC_ASSERT(sizeof(Standard_Utf32Char) == 4); + char* aVar; aVar = getenv ("MMGT_OPT"); Standard_Integer anAllocId = (aVar ? atoi (aVar): OCCT_MMGT_OPT_DEFAULT); diff --git a/src/Standard/Standard_TypeDef.hxx b/src/Standard/Standard_TypeDef.hxx index b9a31783a7..fa3a6ad219 100755 --- a/src/Standard/Standard_TypeDef.hxx +++ b/src/Standard/Standard_TypeDef.hxx @@ -17,16 +17,7 @@ #include #include - -#if(defined(_MSC_VER) && (_MSC_VER < 1600)) - // old MSVC - hasn't stdint header - typedef unsigned __int8 uint8_t; - typedef unsigned __int16 uint16_t; - typedef unsigned __int32 uint32_t; - typedef unsigned __int64 uint64_t; -#else - #include -#endif +#include #if(defined(_MSC_VER) && (_MSC_VER < 1800)) // only Visual Studio 2013 (vc12) provides header @@ -61,21 +52,28 @@ typedef double Standard_Real; typedef unsigned int Standard_Boolean; typedef float Standard_ShortReal; typedef char Standard_Character; -typedef short Standard_ExtCharacter; typedef unsigned char Standard_Byte; typedef void* Standard_Address; typedef size_t Standard_Size; typedef std::time_t Standard_Time; -// -typedef const char* Standard_CString; -typedef const short* Standard_ExtString; - // Unicode primitives, char16_t, char32_t typedef char Standard_Utf8Char; //!< signed UTF-8 char typedef unsigned char Standard_Utf8UChar; //!< unsigned UTF-8 char -typedef uint16_t Standard_Utf16Char; //!< UTF-16 char (always unsigned) -typedef uint32_t Standard_Utf32Char; //!< UTF-32 char (always unsigned) +#if (defined(__GNUC__) && !defined(__clang__) && ((__GNUC__ == 4 && __GNUC_MINOR__ <= 3) || __GNUC__ < 4)) +// compatibility with old GCC compilers +typedef uint16_t Standard_ExtCharacter; +typedef uint16_t Standard_Utf16Char; +typedef uint32_t Standard_Utf32Char; +#else +typedef char16_t Standard_ExtCharacter; +typedef char16_t Standard_Utf16Char; //!< UTF-16 char (always unsigned) +typedef char32_t Standard_Utf32Char; //!< UTF-32 char (always unsigned) +#endif typedef wchar_t Standard_WideChar; //!< wide char (unsigned UTF-16 on Windows platform and signed UTF-32 on Linux) +// +typedef const Standard_Character* Standard_CString; +typedef const Standard_ExtCharacter* Standard_ExtString; + #endif // _Standard_TypeDef_HeaderFile diff --git a/src/TCollection/TCollection_ExtendedString.cxx b/src/TCollection/TCollection_ExtendedString.cxx index f4d408e691..beb2785bfc 100644 --- a/src/TCollection/TCollection_ExtendedString.cxx +++ b/src/TCollection/TCollection_ExtendedString.cxx @@ -24,14 +24,21 @@ #include #include -static - Standard_PExtCharacter Allocate(const Standard_Size aLength); -static - Standard_PExtCharacter Reallocate(Standard_Address aAddr, - const Standard_Size aLength); +namespace +{ + static Standard_PExtCharacter Allocate (const Standard_Size theLength) + { + return (Standard_PExtCharacter )Standard::Allocate (theLength); + } + + static Standard_PExtCharacter Reallocate (Standard_Address theAddr, const Standard_Size theLength) + { + return (Standard_PExtCharacter )Standard::Reallocate (theAddr, theLength); + } -Standard_EXPORT short NULL_EXTSTRING[1] = {0}; + static const Standard_ExtCharacter NULL_EXTSTRING[1] = {0}; +} //============================== input value have len = 2 bytes ==== inline Standard_ExtCharacter ConvertToUnicode2B (unsigned char *p) @@ -817,7 +824,7 @@ Standard_Boolean TCollection_ExtendedString::ConvertToUnicode (const Standard_CString aStr) { Standard_Boolean aRes = Standard_True; - short * p = mystring; + Standard_ExtCharacter* p = mystring; int i = 0; while (aStr[i] != '\0') { if((aStr[i] & 0x80) == 0x00) //1byte => 1 symb - Lat1 @@ -904,24 +911,3 @@ Standard_Integer TCollection_ExtendedString::ToUTF8CString(Standard_PCharacter& theCString[j] = 0x00; return j; } -//======================================================================= -//function : Allocate -//purpose : -//======================================================================= -Standard_PExtCharacter Allocate(const Standard_Size aLength) -{ - Standard_PExtCharacter pChar; - // - pChar=(Standard_PExtCharacter)Standard::Allocate(aLength); - // - return pChar; -} -//======================================================================= -//function : Reallocate -//purpose : -//======================================================================= -Standard_PExtCharacter Reallocate(Standard_Address aAddr, - const Standard_Size aLength) -{ - return (Standard_PExtCharacter)Standard::Reallocate(aAddr, aLength); -}