From a3157439834df6948cc688a63b752dd8db0a18cd Mon Sep 17 00:00:00 2001 From: kgv Date: Thu, 28 Aug 2014 14:05:21 +0400 Subject: [PATCH] 0025182: Standard_OVERRIDE - add alias for C++11 "override" specifier --- dox/dev_guides/contribution/coding_rules.md | 35 +++++++++++++++++++++ src/AIS/AIS_ColoredShape.hxx | 8 ++--- src/Standard/Standard_Macro.hxx | 14 +++++++-- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/dox/dev_guides/contribution/coding_rules.md b/dox/dev_guides/contribution/coding_rules.md index d757d1a0db..d17dee10df 100644 --- a/dox/dev_guides/contribution/coding_rules.md +++ b/dox/dev_guides/contribution/coding_rules.md @@ -556,6 +556,41 @@ If a class has a destructor, an assignment operator or a copy constructor, it us A class with virtual function(s) ought to have a virtual destructor. +### Overriding virtual methods + +Declaration of overriding method should contains specifiers "virtual" and "override" +(using Standard_OVERRIDE alias for compatibility with old compilers). + +~~~~~{.cpp} +class MyPackage_BaseClass +{ + +public: + + Standard_EXPORT virtual Standard_Boolean Perform(); + +}; + +~~~~~{.cpp} +class MyPackage_MyClass : public MyPackage_BaseClass +{ + +public: + + Standard_EXPORT virtual Standard_Boolean Perform() Standard_OVERRIDE; + +}; +~~~~~ + +This makes class definition more clear (virtual methods become highlighted). + +Declaration of interface using pure virtual functions protects against +incomplete inheritance at first level, but does not help when method is overridden multiple times within nested inheritance +or when method in base class is intended to be optional. + +And here "override" specifier introduces additional protection against situations when interface changes might be missed +(class might contain old methods which will be never called). + ### Default parameter value Do not redefine a default parameter value in an inherited function. diff --git a/src/AIS/AIS_ColoredShape.hxx b/src/AIS/AIS_ColoredShape.hxx index 0fedcf8d20..f116bab7f6 100644 --- a/src/AIS/AIS_ColoredShape.hxx +++ b/src/AIS/AIS_ColoredShape.hxx @@ -92,19 +92,19 @@ public: //! @name sub-shape aspects public: //! @name global aspects //! Setup color of entire shape. - Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor); + Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE; //! Setup line width of entire shape. - Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth); + Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth) Standard_OVERRIDE; //! Sets transparency value. - Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue); + Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue) Standard_OVERRIDE; protected: //! @name override presentation computation Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, const Handle(Prs3d_Presentation)& thePrs, - const Standard_Integer theMode); + const Standard_Integer theMode) Standard_OVERRIDE; protected: diff --git a/src/Standard/Standard_Macro.hxx b/src/Standard/Standard_Macro.hxx index 330a2bd54a..cc5d7260c7 100644 --- a/src/Standard/Standard_Macro.hxx +++ b/src/Standard/Standard_Macro.hxx @@ -27,6 +27,16 @@ # define Handle(ClassName) Handle_##ClassName # define STANDARD_TYPE(aType) aType##_Type_() +#if defined(__cplusplus) && (__cplusplus >= 201100L) + // part of C++11 standard + #define Standard_OVERRIDE override +#elif defined(_MSC_VER) && (_MSC_VER >= 1700) + // MSVC extension since VS2005 + #define Standard_OVERRIDE override +#else + #define Standard_OVERRIDE +#endif + //====================================================== // Windows-specific definitions //====================================================== @@ -36,7 +46,7 @@ #error "Wrong compiler options has been detected. Add /DWNT option for proper compilation!!!!!" #endif -# if defined(WNT) && !defined(HAVE_NO_DLL) +# if defined(_WIN32) && !defined(HAVE_NO_DLL) # ifndef Standard_EXPORT # define Standard_EXPORT __declspec( dllexport ) @@ -129,7 +139,7 @@ # ifndef __Standard_API //# ifdef WNT -# if !defined(WNT) || defined(__Standard_DLL) || defined(__FSD_DLL) || defined(__MMgt_DLL) || defined(__OSD_DLL) || defined(__Plugin_DLL) || defined(__Quantity_DLL) || defined(__Resource_DLL) || defined(__SortTools_DLL) || defined(__StdFail_DLL) || defined(__Storage_DLL) || defined(__TColStd_DLL) || defined(__TCollection_DLL) || defined(__TShort_DLL) || defined(__Units_DLL) || defined(__UnitsAPI_DLL) || defined(__Dico_DLL) +# if !defined(_WIN32) || defined(__Standard_DLL) || defined(__FSD_DLL) || defined(__MMgt_DLL) || defined(__OSD_DLL) || defined(__Plugin_DLL) || defined(__Quantity_DLL) || defined(__Resource_DLL) || defined(__SortTools_DLL) || defined(__StdFail_DLL) || defined(__Storage_DLL) || defined(__TColStd_DLL) || defined(__TCollection_DLL) || defined(__TShort_DLL) || defined(__Units_DLL) || defined(__UnitsAPI_DLL) || defined(__Dico_DLL) # define __Standard_API Standard_EXPORT # define __Standard_APIEXTERN Standard_EXPORTEXTERN # else