From: oan Date: Thu, 14 Sep 2017 08:39:36 +0000 (+0300) Subject: 0028824: Possibility to build OCCT 7.1.0 and above using Visual Studio 2008 X-Git-Tag: V7_3_0_beta~261 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=71c810df6174e9f6bdf2902c4ceccb5c755b0a4c 0028824: Possibility to build OCCT 7.1.0 and above using Visual Studio 2008 Possibility to build OCCT using Visual Studio 2008 (VC9) is restored. For that: - template functions and classes from namespace std or tr1 (for VC9) are imported to namespace opencascade which is then used instead of std in relevant places - templates not provided by compiler (VC9) but required for OCCT are defined in this namespace (in Standard_Handle.hxx) - methods implementing move semantics are excluded for VC9 compiler (which does not support && syntax) - support of vc9 compiler is restored in build procedures and environment scripts - check of type of the current class in macros DEFINE_STANDARD_RTTI* is refactored VS 2008 is restored in the list of supported platforms on Overview / System Requirements. --- diff --git a/adm/templates/env.bat b/adm/templates/env.bat index 0748e483e9..65c399d4e9 100644 --- a/adm/templates/env.bat +++ b/adm/templates/env.bat @@ -82,6 +82,8 @@ set "VisualStudioExpressName=VCExpress" if not "%DevEnvDir%" == "" ( rem If DevEnvDir is already defined (e.g. in custom.bat), use that value +) else if /I "%VCFMT%" == "vc9" ( + set "DevEnvDir=%VS90COMNTOOLS%..\IDE" ) else if /I "%VCFMT%" == "vc10" ( set "DevEnvDir=%VS100COMNTOOLS%..\IDE" ) else if /I "%VCFMT%" == "vc11" ( @@ -101,12 +103,22 @@ if not "%DevEnvDir%" == "" ( ) else if /I "%VCFMT%" == "gcc" ( rem MinGW ) else ( - echo Error: wrong VS identifier + echo Error: first argument ^(%VCVER%^) should specify supported version of Visual C++, + echo one of: + echo vc9 = VS 2008 ^(SP1^) + echo vc10 = VS 2010 ^(SP3^) + echo vc11 = VS 2012 ^(SP3^) + echo vc12 = VS 2013 ^(SP3^) + echo vc14 = VS 2015 + echo vc141 = VS 2017 exit /B ) rem ----- Parsing vcvarsall for qt samples and define PlatformToolset ----- -if /I "%VCFMT%" == "vc10" ( +if /I "%VCFMT%" == "vc9" ( + set "VCVARS=%VS90COMNTOOLS%..\..\VC\vcvarsall.bat" + set "VCPlatformToolSet=v90" +) else if /I "%VCFMT%" == "vc10" ( set "VCVARS=%VS100COMNTOOLS%..\..\VC\vcvarsall.bat" set "VCPlatformToolSet=v100" ) else if /I "%VCFMT%" == "vc11" ( @@ -126,9 +138,8 @@ if /I "%VCFMT%" == "vc10" ( ) else if /I "%VCFMT%" == "gcc" ( rem MinGW ) else ( - echo Error: first argument ^(%VCVER%^) should specify supported version of Visual C++, - echo one of: vc10 ^(VS 2010 SP3^), vc11 ^(VS 2012 SP3^), vc12 ^(VS 2013^) or vc14 ^(VS 2015^) - exit + echo Error: wrong VS identifier + exit /B ) set "CSF_OPT_LIB32D=%CSF_OPT_LIB32%" diff --git a/adm/templates/env.bat.in b/adm/templates/env.bat.in index c84a9637cd..74f130a82d 100644 --- a/adm/templates/env.bat.in +++ b/adm/templates/env.bat.in @@ -52,6 +52,8 @@ set "VisualStudioExpressName=VCExpress" if not "%DevEnvDir%" == "" ( rem If DevEnvDir is already defined (e.g. in custom.bat), use that value +) else if /I "%VCFMT%" == "vc9" ( + set "DevEnvDir=%VS90COMNTOOLS%..\IDE" ) else if /I "%VCFMT%" == "vc10" ( set "DevEnvDir=%VS100COMNTOOLS%..\IDE" ) else if /I "%VCFMT%" == "vc11" ( @@ -76,7 +78,10 @@ if not "%DevEnvDir%" == "" ( ) rem ----- Parsing vcvarsall for qt samples and define PlatformToolset ----- -if /I "%VCFMT%" == "vc10" ( +if /I "%VCFMT%" == "vc9" ( + set "VCVARS=%VS90COMNTOOLS%..\..\VC\vcvarsall.bat" + set "VCPlatformToolSet=v90" +) else if /I "%VCFMT%" == "vc10" ( set "VCVARS=%VS100COMNTOOLS%..\..\VC\vcvarsall.bat" set "VCPlatformToolSet=v100" ) else if /I "%VCFMT%" == "vc11" ( diff --git a/adm/templates/template.vc9 b/adm/templates/template.vc9 index 8dc5ba5fa2..a6de42e0ec 100644 --- a/adm/templates/template.vc9 +++ b/adm/templates/template.vc9 @@ -24,6 +24,7 @@ ConfigurationType="2" UseOfMFC="0" ATLMinimizesCRunTimeLibraryUsage="false" + CharacterSet="1" > 1, 2012 Update 4, 2013 Update 5, 2015, 2017
Intel C++ Composer XE 2013 SP1
GCC 4.3+ (Mingw-w64)| +| Windows | Microsoft Visual Studio: 2008 SP1, 2010 SP11, 2012 Update 4, 2013 Update 5, 2015, 2017
GCC 4.3+ (Mingw-w64)| | Linux | GNU gcc 4.3+
LLVM CLang 3.6+ | -| OS X | XCode 6 or newer | +| OS X / macOS | XCode 6 or newer | | Android | NDK r10, GNU gcc 4.8 or newer | 1) VC++ 10 64-bit is used for regular testing and for building diff --git a/src/BVH/BVH_BinaryTree.hxx b/src/BVH/BVH_BinaryTree.hxx index 80d36aca17..c9db4cad40 100644 --- a/src/BVH/BVH_BinaryTree.hxx +++ b/src/BVH/BVH_BinaryTree.hxx @@ -215,21 +215,21 @@ BVH_Tree* BVH_Tree::CollapseToQuadTree { const std::pair aNode = aQueue.front(); - BVH::Array::Append (aQBVH->myMinPointBuffer, BVH::Array::Value (this->myMinPointBuffer, std::get<0> (aNode))); - BVH::Array::Append (aQBVH->myMaxPointBuffer, BVH::Array::Value (this->myMaxPointBuffer, std::get<0> (aNode))); + BVH::Array::Append (aQBVH->myMinPointBuffer, BVH::Array::Value (this->myMinPointBuffer, opencascade::std::get<0> (aNode))); + BVH::Array::Append (aQBVH->myMaxPointBuffer, BVH::Array::Value (this->myMaxPointBuffer, opencascade::std::get<0> (aNode))); BVH_Vec4i aNodeInfo; - if (this->IsOuter (std::get<0> (aNode))) // is leaf node + if (this->IsOuter (opencascade::std::get<0> (aNode))) // is leaf node { aNodeInfo = BVH_Vec4i (1 /* leaf flag */, - this->BegPrimitive (std::get<0> (aNode)), this->EndPrimitive (std::get<0> (aNode)), std::get<1> (aNode) /* level */); + this->BegPrimitive (opencascade::std::get<0> (aNode)), this->EndPrimitive (opencascade::std::get<0> (aNode)), opencascade::std::get<1> (aNode) /* level */); } else { NCollection_Vector aGrandChildNodes; - const int aLftChild = Child<0> (std::get<0> (aNode)); - const int aRghChild = Child<1> (std::get<0> (aNode)); + const int aLftChild = Child<0> (opencascade::std::get<0> (aNode)); + const int aRghChild = Child<1> (opencascade::std::get<0> (aNode)); if (this->IsOuter (aLftChild)) // is leaf node { aGrandChildNodes.Append (aLftChild); @@ -252,13 +252,13 @@ BVH_Tree* BVH_Tree::CollapseToQuadTree for (int aNodeIdx = 0; aNodeIdx < aGrandChildNodes.Size(); ++aNodeIdx) { - aQueue.push_back (std::make_pair (aGrandChildNodes (aNodeIdx), std::get<1> (aNode) + 1)); + aQueue.push_back (std::make_pair (aGrandChildNodes (aNodeIdx), opencascade::std::get<1> (aNode) + 1)); } aNodeInfo = BVH_Vec4i (0 /* inner flag */, - aNbNodes, aGrandChildNodes.Size() - 1, std::get<1> (aNode) /* level */); + aNbNodes, aGrandChildNodes.Size() - 1, opencascade::std::get<1> (aNode) /* level */); - aQBVH->myDepth = Max (aQBVH->myDepth, std::get<1> (aNode) + 1); + aQBVH->myDepth = Max (aQBVH->myDepth, opencascade::std::get<1> (aNode) + 1); aNbNodes += aGrandChildNodes.Size(); } diff --git a/src/BVH/BVH_Types.hxx b/src/BVH/BVH_Types.hxx index 70dc9bfafd..6cbf7ae916 100644 --- a/src/BVH/BVH_Types.hxx +++ b/src/BVH/BVH_Types.hxx @@ -247,7 +247,14 @@ namespace BVH if (Size (theArray) == theCount) { #ifdef _STD_VECTOR_SHRINK + +#if(defined(_MSC_VER) && (_MSC_VER < 1600)) + BVH_ArrayNt aTmpArray(theArray); + theArray.swap(aTmpArray); +#else theArray.shrink_to_fit(); +#endif + #endif } else diff --git a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx index eede80cf5a..ccc4e1f5ab 100644 --- a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx +++ b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx @@ -249,7 +249,7 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream& for (; anIterS.More(); anIterS.Next()) { BinLDrivers_DocumentSection& aCurSection = anIterS.ChangeValue(); if (aCurSection.IsPostRead() == Standard_False) { - theIStream.seekg ((streampos) aCurSection.Offset()); + theIStream.seekg ((std::streamsize)aCurSection.Offset()); if (aCurSection.Name().IsEqual ((Standard_CString)SHAPESECTION_POS)) ReadShapeSection (aCurSection, theIStream); else @@ -321,7 +321,7 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream& for (; aSectIter.More(); aSectIter.Next()) { BinLDrivers_DocumentSection& aCurSection = aSectIter.ChangeValue(); if (aCurSection.IsPostRead()) { - theIStream.seekg ((streampos) aCurSection.Offset()); + theIStream.seekg ((std::streamsize)aCurSection.Offset()); ReadSection (aCurSection, theDoc, theIStream); } } diff --git a/src/BinLDrivers/BinLDrivers_DocumentSection.cxx b/src/BinLDrivers/BinLDrivers_DocumentSection.cxx index 1032888a6a..b527ca568a 100644 --- a/src/BinLDrivers/BinLDrivers_DocumentSection.cxx +++ b/src/BinLDrivers/BinLDrivers_DocumentSection.cxx @@ -160,7 +160,7 @@ void BinLDrivers_DocumentSection::Write (Standard_OStream& theStream, const uint64_t theOffset) { const uint64_t aSectionEnd = (uint64_t) theStream.tellp(); - theStream.seekp(myValue[0]); + theStream.seekp((std::streamsize)myValue[0]); myValue[0] = theOffset; myValue[1] = aSectionEnd - theOffset; uint64_t aVal[3] = { @@ -175,7 +175,7 @@ void BinLDrivers_DocumentSection::Write (Standard_OStream& theStream, #endif theStream.write((char *)&aVal[0], 3*sizeof(uint64_t)); - theStream.seekp(aSectionEnd); + theStream.seekp((std::streamsize)aSectionEnd); } //======================================================================= diff --git a/src/DrawTrSurf/DrawTrSurf.hxx b/src/DrawTrSurf/DrawTrSurf.hxx index ad7a723afb..c6c892cc68 100644 --- a/src/DrawTrSurf/DrawTrSurf.hxx +++ b/src/DrawTrSurf/DrawTrSurf.hxx @@ -89,14 +89,14 @@ public: //! isSenseMarker indicates whether to render the //! sense glyph (arrow) for curves or not Standard_EXPORT static void Set (const Standard_CString Name, const Handle(Geom_Geometry)& G, const Standard_Boolean isSenseMarker = Standard_True); -template static void Set (const Standard_CString Name, const Handle(T)& Arg, typename std::enable_if::value>::type * = 0) { Set (Name, (const Handle(Geom_Geometry)&)Arg); } +template static void Set (const Standard_CString Name, const Handle(T)& Arg, typename opencascade::std::enable_if::value>::type * = 0) { Set (Name, (const Handle(Geom_Geometry)&)Arg); } //! Sets in the variable . Overwrite the //! variable if already set. //! isSenseMarker indicates whether to render the //! sense glyph (arrow) for curves or not Standard_EXPORT static void Set (const Standard_CString Name, const Handle(Geom2d_Curve)& C, const Standard_Boolean isSenseMarker = Standard_True); -template static void Set (const Standard_CString Name, const Handle(T)& Arg, typename std::enable_if::value>::type * = 0) { Set (Name, (const Handle(Geom2d_Curve)&)Arg); } +template static void Set (const Standard_CString Name, const Handle(T)& Arg, typename opencascade::std::enable_if::value>::type * = 0) { Set (Name, (const Handle(Geom2d_Curve)&)Arg); } //! Sets in the variable . Overwrite the //! variable if already set. diff --git a/src/IGESData/IGESData_IGESWriter.hxx b/src/IGESData/IGESData_IGESWriter.hxx index 5ec8715aeb..c9b8af5487 100644 --- a/src/IGESData/IGESData_IGESWriter.hxx +++ b/src/IGESData/IGESData_IGESWriter.hxx @@ -152,7 +152,7 @@ public: //! classes derived from IGESData_IGESEntity, for VC++ 10 and 11 compillers template void Send (const Handle(T)& val, Standard_Boolean negative = Standard_False, - typename std::enable_if::value>::type * = 0) + typename opencascade::std::enable_if::value>::type * = 0) { Send ((const Handle(IGESData_IGESEntity)&)val, negative); } diff --git a/src/NCollection/NCollection_Array1.hxx b/src/NCollection/NCollection_Array1.hxx index 8245603f96..85d2c43aff 100644 --- a/src/NCollection/NCollection_Array1.hxx +++ b/src/NCollection/NCollection_Array1.hxx @@ -192,6 +192,8 @@ public: } //! Move constructor +#if(defined(_MSC_VER) && (_MSC_VER < 1600)) +#else NCollection_Array1 (NCollection_Array1&& theOther) : myLowerBound (theOther.myLowerBound), myUpperBound (theOther.myUpperBound), @@ -202,6 +204,7 @@ public: theOther.myDeletable = false; theOther.myData = NULL; } +#endif //! C array-based constructor NCollection_Array1 (const TheItemType& theBegin, @@ -279,7 +282,7 @@ public: } //! Move assignment - NCollection_Array1& Move (NCollection_Array1&& theOther) + NCollection_Array1& Move (NCollection_Array1& theOther) { if (&theOther == this) { @@ -308,10 +311,13 @@ public: } //! Move assignment operator. +#if(defined(_MSC_VER) && (_MSC_VER < 1600)) +#else NCollection_Array1& operator= (NCollection_Array1&& theOther) { - return Move (std::move (theOther)); + return Move (theOther); } +#endif //! @return first element const TheItemType& First() const diff --git a/src/NCollection/NCollection_DefineHSequence.hxx b/src/NCollection/NCollection_DefineHSequence.hxx index 34a8901cc9..9973d9b866 100644 --- a/src/NCollection/NCollection_DefineHSequence.hxx +++ b/src/NCollection/NCollection_DefineHSequence.hxx @@ -41,7 +41,7 @@ class HClassName : public _SequenceType_, public Standard_Transient { _SequenceType_& ChangeSequence () { return *this; } \ template \ void Append (const Handle(T)& theOther, \ - typename std::enable_if::value>::type * = 0) { \ + typename opencascade::std::enable_if::value>::type * = 0) { \ _SequenceType_::Append (theOther->ChangeSequence()); \ } \ DEFINE_STANDARD_RTTI_INLINE(HClassName,Standard_Transient) \ diff --git a/src/NCollection/NCollection_Shared.hxx b/src/NCollection/NCollection_Shared.hxx index 446a0ccfec..f8125f28b6 100644 --- a/src/NCollection/NCollection_Shared.hxx +++ b/src/NCollection/NCollection_Shared.hxx @@ -32,7 +32,7 @@ //! The intent is similar to std::make_shared<> in STL, except that this //! implementation defines a separate type. -template ::value>::type> +template ::value>::type> class NCollection_Shared : public Standard_Transient, public T { public: diff --git a/src/NCollection/NCollection_StlIterator.hxx b/src/NCollection/NCollection_StlIterator.hxx index 8e6c6ea842..6789f4ab62 100644 --- a/src/NCollection/NCollection_StlIterator.hxx +++ b/src/NCollection/NCollection_StlIterator.hxx @@ -19,48 +19,6 @@ #include #include -// This file uses C++11 utilities like std::is_base<>, which are not -// available in some environments (e.g. MSVC includes them since VS 2008). -// Hence here we define our own implementation of these tools in namespace opencascade. -// When all compilers support this, this namespace can be removed and replaced by std. -namespace opencascade -{ - template - struct enable_if - { - typedef T type; - }; - - template - struct enable_if - { - }; - - template - struct is_same - { - enum { value = 0 }; - }; - - template - struct is_same - { - enum { value = 1 }; - }; - - template - struct conditional - { - typedef TypeTrue type; - }; - - template - struct conditional - { - typedef TypeFalse type; - }; -} - //! Helper class that allows to use NCollection iterators as STL iterators. //! NCollection iterator can be extended to STL iterator of any category by //! adding necessary methods: STL forward iterator requires IsEqual method, @@ -70,8 +28,8 @@ namespace opencascade template class NCollection_StlIterator : public std::iterator::type, - typename opencascade::conditional::type> + typename opencascade::std::conditional::type, + typename opencascade::std::conditional::type> { public: @@ -113,13 +71,13 @@ protected: //! @name methods related to forward STL iterator // an appropriate method based on template arguments (at instantiation time). template - typename opencascade::enable_if::type Reference() const + typename opencascade::std::enable_if::type Reference() const { return myIterator.ChangeValue(); } template - typename opencascade::enable_if::type Reference() const + typename opencascade::std::enable_if::type Reference() const { return myIterator.Value(); } @@ -171,8 +129,8 @@ public: //! @name methods related to bidirectional STL iterator //! Prefix decrement NCollection_StlIterator& operator--() { - Standard_STATIC_ASSERT((opencascade::is_same::value || - opencascade::is_same::value)); + Standard_STATIC_ASSERT((opencascade::std::is_same::value || + opencascade::std::is_same::value)); myIterator.Previous(); return *this; } @@ -190,7 +148,7 @@ public: //! @name methods related to random access STL iterator //! Move forward NCollection_StlIterator& operator+= (typename NCollection_StlIterator::difference_type theOffset) { - Standard_STATIC_ASSERT((opencascade::is_same::value)); + Standard_STATIC_ASSERT((opencascade::std::is_same::value)); myIterator.Offset (theOffset); return *this; } @@ -218,7 +176,7 @@ public: //! @name methods related to random access STL iterator //! Difference typename NCollection_StlIterator::difference_type operator- (const NCollection_StlIterator& theOther) const { - Standard_STATIC_ASSERT((opencascade::is_same::value)); + Standard_STATIC_ASSERT((opencascade::std::is_same::value)); return myIterator.Differ (theOther.myIterator); } diff --git a/src/NCollection/NCollection_UBTreeFiller.hxx b/src/NCollection/NCollection_UBTreeFiller.hxx index 22f6c593e5..3171200389 100644 --- a/src/NCollection/NCollection_UBTreeFiller.hxx +++ b/src/NCollection/NCollection_UBTreeFiller.hxx @@ -130,7 +130,7 @@ template class NCollection_UBTreeFiller UBTree& myTree; NCollection_Vector mySeqPtr; - std::mt19937 myRandGen; //!< random number generator + opencascade::std::mt19937 myRandGen; //!< random number generator Standard_Boolean myIsFullRandom; }; diff --git a/src/OpenGl/OpenGl_Context.cxx b/src/OpenGl/OpenGl_Context.cxx index 52f9a16050..538331a5d7 100644 --- a/src/OpenGl/OpenGl_Context.cxx +++ b/src/OpenGl/OpenGl_Context.cxx @@ -2904,7 +2904,7 @@ void OpenGl_Context::ReleaseResource (const TCollection_AsciiString& theKey, { return; } - auto& aRes = mySharedResources->Find (theKey); + const Handle(OpenGl_Resource)& aRes = mySharedResources->Find (theKey); if (aRes->GetRefCount() > 1) { return; @@ -2952,7 +2952,7 @@ void OpenGl_Context::ReleaseDelayed() continue; } - auto& aRes = mySharedResources->ChangeFind (aKey); + const Handle(OpenGl_Resource)& aRes = mySharedResources->ChangeFind (aKey); if (aRes->GetRefCount() > 1) { // should be only 1 instance in mySharedResources diff --git a/src/Poly/Poly_Connect.cxx b/src/Poly/Poly_Connect.cxx index 2d2590e704..3fc55e2c18 100644 --- a/src/Poly/Poly_Connect.cxx +++ b/src/Poly/Poly_Connect.cxx @@ -82,13 +82,11 @@ void Poly_Connect::Load (const Handle(Poly_Triangulation)& theTriangulation) const Standard_Integer aNbAdjs = 6 * nbTriangles; if (myTriangles.Size() != nbNodes) { - TColStd_Array1OfInteger aTriArray (1, nbNodes); - myTriangles.Move (std::move (aTriArray)); + myTriangles.Resize (1, nbNodes, Standard_False); } if (myAdjacents.Size() != aNbAdjs) { - TColStd_Array1OfInteger anAdjArray (1, aNbAdjs); - myAdjacents.Move (std::move (anAdjArray)); + myAdjacents.Resize (1, aNbAdjs, Standard_False); } } diff --git a/src/QANCollection/QANCollection_Handle.cxx b/src/QANCollection/QANCollection_Handle.cxx index f52c9599c7..42f2d345f5 100644 --- a/src/QANCollection/QANCollection_Handle.cxx +++ b/src/QANCollection/QANCollection_Handle.cxx @@ -435,7 +435,7 @@ static Standard_Integer QAHandleInc (Draw_Interpretor& theDI, } Handle(Standard_Transient) aHandle = new Standard_Transient(); - std::shared_ptr aSharePtr (new Standard_Transient()); + opencascade::std::shared_ptr aSharePtr (new Standard_Transient()); theDI << "Time of creating and destroying " << aNbIters << " smart pointers to the same object, per item, ns:"; { { @@ -451,7 +451,7 @@ static Standard_Integer QAHandleInc (Draw_Interpretor& theDI, { QATimer aTimer (theDI, "\nC++ shared_ptr: ", QATimer::ns, aNbIters); { - std::vector< std::shared_ptr > aSharePointers (aNbIters); + std::vector< opencascade::std::shared_ptr > aSharePointers (aNbIters); for (Standard_Integer anIter = 0; anIter < aNbIters; ++anIter) { aSharePointers[anIter] = aSharePtr; diff --git a/src/RWStl/RWStl_Reader.cxx b/src/RWStl/RWStl_Reader.cxx index df2dfb92b5..29f669f378 100644 --- a/src/RWStl/RWStl_Reader.cxx +++ b/src/RWStl/RWStl_Reader.cxx @@ -250,7 +250,7 @@ Standard_Boolean RWStl_Reader::ReadAscii (Standard_IStream& theStream, const int64_t aEndPos = (theUntilPos > 0 ? 1 + GETPOS(theUntilPos) : std::numeric_limits::max()); // skip header "solid ..." - theStream.ignore (aEndPos - aStartPos, '\n'); + theStream.ignore ((std::streamsize)(aEndPos - aStartPos), '\n'); if (!theStream) { Message::DefaultMessenger()->Send ("Error: premature end of file", Message_Fail); @@ -264,7 +264,7 @@ Standard_Boolean RWStl_Reader::ReadAscii (Standard_IStream& theStream, // report progress every 1 MiB of read data const int aStepB = 1024 * 1024; - const Standard_Integer aNbSteps = 1 + Standard_Integer((theUntilPos - aStartPos) / aStepB); + const Standard_Integer aNbSteps = 1 + Standard_Integer((GETPOS(theUntilPos) - aStartPos) / aStepB); Message_ProgressSentry aPSentry (theProgress, "Reading text STL file", 0, aNbSteps, 1); int64_t aProgressPos = aStartPos + aStepB; @@ -280,13 +280,13 @@ Standard_Boolean RWStl_Reader::ReadAscii (Standard_IStream& theStream, } char facet[LINELEN], outer[LINELEN]; - theStream.getline (facet, std::min (LINELEN, aEndPos - GETPOS(theStream.tellg()))); // "facet normal nx ny nz" + theStream.getline (facet, (std::streamsize)std::min (LINELEN, aEndPos - GETPOS(theStream.tellg()))); // "facet normal nx ny nz" if (str_starts_with (facet, "endsolid", 8)) { // end of STL code break; } - theStream.getline (outer, std::min (LINELEN, aEndPos - GETPOS(theStream.tellg()))); // "outer loop" + theStream.getline (outer, (std::streamsize)std::min (LINELEN, aEndPos - GETPOS(theStream.tellg()))); // "outer loop" if (!str_starts_with (facet, "facet", 5) || !str_starts_with (outer, "outer", 5)) { TCollection_AsciiString aStr ("Error: unexpected format of facet at line "); @@ -295,9 +295,9 @@ Standard_Boolean RWStl_Reader::ReadAscii (Standard_IStream& theStream, return false; } - theStream.getline (aLine1, std::min (LINELEN, aEndPos - GETPOS(theStream.tellg()))); - theStream.getline (aLine2, std::min (LINELEN, aEndPos - GETPOS(theStream.tellg()))); - theStream.getline (aLine3, std::min (LINELEN, aEndPos - GETPOS(theStream.tellg()))); + theStream.getline (aLine1, (std::streamsize)std::min (LINELEN, aEndPos - GETPOS(theStream.tellg()))); + theStream.getline (aLine2, (std::streamsize)std::min (LINELEN, aEndPos - GETPOS(theStream.tellg()))); + theStream.getline (aLine3, (std::streamsize)std::min (LINELEN, aEndPos - GETPOS(theStream.tellg()))); // stop reading if end of file is reached; // note that well-formatted file never ends by the vertex line @@ -335,8 +335,8 @@ Standard_Boolean RWStl_Reader::ReadAscii (Standard_IStream& theStream, AddTriangle (n1, n2, n3); } - theStream.ignore (aEndPos - GETPOS(theStream.tellg()), '\n'); // skip "endloop" - theStream.ignore (aEndPos - GETPOS(theStream.tellg()), '\n'); // skip "endfacet" + theStream.ignore ((std::streamsize)(aEndPos - GETPOS(theStream.tellg())), '\n'); // skip "endloop" + theStream.ignore ((std::streamsize)(aEndPos - GETPOS(theStream.tellg())), '\n'); // skip "endfacet" aNbLine += 2; } diff --git a/src/Standard/Standard_ArrayStreamBuffer.hxx b/src/Standard/Standard_ArrayStreamBuffer.hxx index 6e5973bf36..e472446e19 100644 --- a/src/Standard/Standard_ArrayStreamBuffer.hxx +++ b/src/Standard/Standard_ArrayStreamBuffer.hxx @@ -18,6 +18,12 @@ #include +// Suppress VC9 warning on xsputn() function +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4996) +#endif + //! Custom buffer object implementing STL interface std::streambuf for streamed reading from allocated memory block. //! Implements minimal sub-set of methods for passing buffer to std::istream, including seek support. //! @@ -110,4 +116,8 @@ protected: }; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif // _Standard_ArrayStreamBuffer_HeaderFile diff --git a/src/Standard/Standard_Handle.hxx b/src/Standard/Standard_Handle.hxx index ee0abc7eee..9e7a3a6a5e 100644 --- a/src/Standard/Standard_Handle.hxx +++ b/src/Standard/Standard_Handle.hxx @@ -22,16 +22,59 @@ class Standard_Transient; +//! Namespace opencascade is intended for low-level template classes and functions namespace opencascade { + //! Namespace opencascade::std includes templates from C++11 std namespace used by + //! OCCT classes. These definitions are imported from std namespace, plus (on older + //! compilers) from std::tr1, or implemented by custom code where neither std + //! not std::tr1 provide necessary definitions. + namespace std + { + // import all available standard stuff from std namespace + using namespace ::std; + +// for old MSVC compiler, some standard templates are defined in std::tr1 namespace, +// and some missing ones are implemented here +#if(defined(_MSC_VER) && (_MSC_VER < 1600)) + using namespace ::std::tr1; + + // C++11 template class enable_if + template + struct enable_if + {// type is undefined for assumed !_Test + }; + + template + struct enable_if + {// type is _Type for _Test + typedef _Type type; + }; + + template + struct conditional + { + typedef TypeTrue type; + }; + + template + struct conditional + { + typedef TypeFalse type; + }; + +#endif + + } // namespace opencascade::std + //! Trait yielding true if class T1 is base of T2 but not the same template - struct is_base_but_not_same : std::is_base_of {}; + struct is_base_but_not_same : opencascade::std::is_base_of {}; //! Explicit specialization of is_base_of trait to workaround the //! requirement of type to be complete when T1 and T2 are the same. template - struct is_base_but_not_same ::value>::type> : std::false_type {}; + struct is_base_but_not_same ::value>::type> : opencascade::std::false_type {}; //! Intrusive smart pointer for use with Standard_Transient class and its descendants. //! @@ -79,11 +122,14 @@ namespace opencascade { BeginScope(); } +#if(defined(_MSC_VER) && (_MSC_VER < 1600)) +#else //! Move constructor handle (handle&& theHandle) : entity(theHandle.entity) { theHandle.entity = 0; } +#endif //! Destructor ~handle () @@ -120,12 +166,15 @@ namespace opencascade { return *this; } +#if(defined(_MSC_VER) && (_MSC_VER < 1600)) +#else //! Move operator handle& operator= (handle&& theHandle) { std::swap (this->entity, theHandle.entity); return *this; } +#endif //! STL-like cast to pointer to referred object (note non-const). //! @sa std::shared_ptr::get() @@ -188,7 +237,7 @@ namespace opencascade { //! Down casting operator from handle to base type template - static typename std::enable_if::value, handle>::type + static typename opencascade::std::enable_if::value, handle>::type DownCast (const handle& theObject) { return handle (dynamic_cast(const_cast(theObject.get()))); @@ -196,7 +245,7 @@ namespace opencascade { //! Down casting operator from pointer to base type template - static typename std::enable_if::value, handle>::type + static typename opencascade::std::enable_if::value, handle>::type DownCast (const T2* thePtr) { return handle (dynamic_cast(const_cast(thePtr))); @@ -205,7 +254,7 @@ namespace opencascade { //! For compatibility, define down casting operator from non-base type, as deprecated template Standard_DEPRECATED("down-casting from object of the same or unrelated type is meaningless") - static handle DownCast (const handle& theObject, typename std::enable_if::value, void*>::type = 0) + static handle DownCast (const handle& theObject, typename opencascade::std::enable_if::value, void*>::type = 0) { return handle (dynamic_cast(const_cast(theObject.get()))); } @@ -213,7 +262,7 @@ namespace opencascade { //! For compatibility, define down casting operator from non-base type, as deprecated template Standard_DEPRECATED("down-casting from object of the same or unrelated type is meaningless") - static handle DownCast (const T2* thePtr, typename std::enable_if::value, void*>::type = 0) + static handle DownCast (const T2* thePtr, typename opencascade::std::enable_if::value, void*>::type = 0) { return handle (dynamic_cast(const_cast(thePtr))); } @@ -312,6 +361,8 @@ namespace opencascade { BeginScope(); } +#if(defined(_MSC_VER) && (_MSC_VER < 1600)) +#else //! Generalized move constructor template handle (handle&& theHandle, typename std::enable_if ::value>::type* = nullptr) @@ -319,6 +370,7 @@ namespace opencascade { { theHandle.entity = 0; } +#endif //! Generalized assignment operator. template @@ -330,6 +382,8 @@ namespace opencascade { return *this; } +#if(defined(_MSC_VER) && (_MSC_VER < 1600)) +#else //! Generalized move operator template handle& operator= (handle&& theHandle) @@ -339,6 +393,7 @@ namespace opencascade { std::swap (this->entity, theHandle.entity); return *this; } +#endif #else @@ -351,7 +406,7 @@ namespace opencascade { { // error "type is not a member of enable_if" will be generated if T2 is not sub-type of T // (handle is being cast to const& to handle of non-base type) - return reinterpret_cast::value, const handle&>::type>(*this); + return reinterpret_cast::value, const handle&>::type>(*this); } //! Upcast to non-const reference to base type. @@ -362,7 +417,7 @@ namespace opencascade { { // error "type is not a member of enable_if" will be generated if T2 is not sub-type of T // (handle is being cast to const& to handle of non-base type) - return reinterpret_cast::value, handle&>::type>(*this); + return reinterpret_cast::value, handle&>::type>(*this); } #endif /* OCCT_HANDLE_NOCAST */ diff --git a/src/Standard/Standard_Type.hxx b/src/Standard/Standard_Type.hxx index bbcf0075f1..b21ba3a3b9 100644 --- a/src/Standard/Standard_Type.hxx +++ b/src/Standard/Standard_Type.hxx @@ -24,11 +24,13 @@ // Auxiliary tools to check at compile time that class declared as base in // DEFINE_STANDARD_RTTI* macro is actually a base class. -// For GCC 4.7+, more strict check is possible -- ensuring that base class -// is direct base -- using non-standard C++ reflection functionality. #if ! defined(OCC_CHECK_BASE_CLASS) + #if (defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 7) || (__GNUC__ > 4))) +// For GCC 4.7+, more strict check is possible -- ensuring that base class +// is direct base -- using non-standard C++ reflection functionality. + #include #include @@ -58,14 +60,30 @@ namespace opencascade #define OCC_CHECK_BASE_CLASS(Class,Base) \ using direct_base_classes = opencascade::direct_base_class_as_tuple::type>::type; \ - static_assert(opencascade::has_type::type::value, "OCCT RTTI definition is incorrect: " #Base " is not direct base class of " #Class); + static_assert(opencascade::has_type::type::value, "OCCT RTTI definition is incorrect: " #Base " is not direct base class of " #Class); \ + static_assert(&get_type_name == &Class::get_type_name, "OCCT RTTI definition is misplaced: current class is not " #Class); + +#elif (defined(_MSC_VER) && (_MSC_VER < 1600)) + +// VC9 does not support static_assert and decltype at all +#define OCC_CHECK_BASE_CLASS(Class,Base) -#else /* ! GCC 4.7+ */ +#elif (defined(_MSC_VER) && (_MSC_VER >= 1900)) +// VC14+ allow using address of member functions in static checks, +// that allows checking for the current type being correctly named in the macro +#define OCC_CHECK_BASE_CLASS(Class,Base) \ + static_assert(opencascade::is_base_but_not_same::value, "OCCT RTTI definition is incorrect: " #Base " is not base class of " #Class); \ + static_assert(&get_type_name == &Class::get_type_name, "OCCT RTTI definition is misplaced: current class is not " #Class); + +#else + +// by default, check only the base class #define OCC_CHECK_BASE_CLASS(Class,Base) \ static_assert(opencascade::is_base_but_not_same::value, "OCCT RTTI definition is incorrect: " #Base " is not base class of " #Class); -#endif /* GCC 4.7+ */ +#endif + #endif /* ! defined(OCC_CHECK_BASE_CLASS) */ //! Helper macro to get instance of a type descriptor for a class in a legacy way. @@ -81,10 +99,7 @@ public: \ typedef Base base_type; \ static const char* get_type_name () { return #Class; OCC_CHECK_BASE_CLASS(Class,Base) } \ static const Handle(Standard_Type)& get_type_descriptor () { return Standard_Type::Instance(); } \ - virtual const Handle(Standard_Type)& DynamicType() const Standard_OVERRIDE { \ - static_assert(std::is_same::value, "OCCT RTTI definition is misplaced: current class is not " #Class); \ - return get_type_descriptor (); \ - } + virtual const Handle(Standard_Type)& DynamicType() const Standard_OVERRIDE { return get_type_descriptor (); } //! Helper macro to be included in definition of the classes inheriting //! Standard_Transient to enable use of OCCT RTTI. @@ -100,10 +115,7 @@ public: \ //! Defines implementation of type descriptor and DynamicType() function #define IMPLEMENT_STANDARD_RTTIEXT(Class,Base) \ const Handle(Standard_Type)& Class::get_type_descriptor () { return Standard_Type::Instance(); } \ - const Handle(Standard_Type)& Class::DynamicType() const { \ - static_assert(std::is_same::value, "OCCT RTTI definition is misplaced: current class is not " #Class); \ - return STANDARD_TYPE(Class); \ - } + const Handle(Standard_Type)& Class::DynamicType() const { return STANDARD_TYPE(Class); } // forward declaration of type_instance class namespace opencascade { diff --git a/src/Standard/Standard_TypeDef.hxx b/src/Standard/Standard_TypeDef.hxx index e232d6681a..6216e25fd6 100755 --- a/src/Standard/Standard_TypeDef.hxx +++ b/src/Standard/Standard_TypeDef.hxx @@ -17,7 +17,22 @@ #include #include -#include + +// VC9 does not have stdint.h +#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; + + typedef __int8 int8_t; + typedef __int16 int16_t; + typedef __int32 int32_t; + typedef __int64 int64_t; +#else + #include +#endif #if(defined(_MSC_VER) && (_MSC_VER < 1800)) // only Visual Studio 2013 (vc12) provides header @@ -64,8 +79,8 @@ typedef std::time_t Standard_Time; // Unicode primitives, char16_t, char32_t typedef char Standard_Utf8Char; //!< signed UTF-8 char typedef unsigned char Standard_Utf8UChar; //!< unsigned UTF-8 char -#if (defined(__GNUC__) && !defined(__clang__) && ((__GNUC__ == 4 && __GNUC_MINOR__ <= 3) || __GNUC__ < 4)) -// compatibility with old GCC compilers +#if ((defined(__GNUC__) && !defined(__clang__) && ((__GNUC__ == 4 && __GNUC_MINOR__ <= 3) || __GNUC__ < 4)) || (defined(_MSC_VER) && (_MSC_VER < 1600))) +// compatibility with old GCC and MSVC compilers typedef uint16_t Standard_ExtCharacter; typedef uint16_t Standard_Utf16Char; typedef uint32_t Standard_Utf32Char;