0027676: Foundation Classes - define Standard_ExtCharacter, Standard_Utf16Char using...
authorkgv <kgv@opencascade.com>
Fri, 5 Aug 2016 19:49:11 +0000 (22:49 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 11 Aug 2016 09:17:03 +0000 (12:17 +0300)
dox/dev_guides/upgrade/upgrade.md
samples/mfc/occtdemo/Common/WNT/OCCDemoDoc.cpp
samples/mfc/standard/08_HLR/src/SelectionDialog.cpp
samples/mfc/standard/10_Convert/src/WNT/OCCDemoDoc.cpp
src/DDF/DDF_IOStream.cxx
src/FSD/FSD_CmpFile.cxx
src/FSD/FSD_File.cxx
src/Standard/Standard.cxx
src/Standard/Standard_TypeDef.hxx
src/TCollection/TCollection_ExtendedString.cxx

index a05803c..3dcab33 100644 (file)
@@ -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:
index 86cbe9b..31efa40 100755 (executable)
@@ -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.);
index 465ee38..f4ff794 100644 (file)
@@ -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();
index b79e2be..6f1b1fd 100755 (executable)
@@ -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.);
index 45e17bf..77ae98f 100644 (file)
@@ -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;
 }
 
index 5a50e31..eb0fd57 100644 (file)
@@ -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;
 }
 
index e5f1785..9fb391e 100644 (file)
@@ -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;
 }
 
index a976f86..bfc3280 100644 (file)
@@ -19,6 +19,7 @@
 #include <Standard_MMgrOpt.hxx>
 #include <Standard_MMgrRaw.hxx>
 #include <Standard_MMgrTBBalloc.hxx>
+#include <Standard_Assert.hxx>
 
 #include <stdlib.h>
 #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);
index b9a3178..fa3a6ad 100755 (executable)
 
 #include <cstddef>
 #include <ctime>
-
-#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 <stdint.h>
-#endif
+#include <stdint.h>
 
 #if(defined(_MSC_VER) && (_MSC_VER < 1800))
   // only Visual Studio 2013 (vc12) provides <cinttypes> 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
index f4d408e..beb2785 100644 (file)
 
 #include <cctype>
 #include <cstdio>
-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);
-}