From 631e526ea63fc394c8fcbafe4af9a21cb84ddd4e Mon Sep 17 00:00:00 2001 From: spo Date: Mon, 20 Jun 2016 14:52:33 +0300 Subject: [PATCH] Remove dependency on boost --- src/ModelHighAPI/ModelHighAPI_Double.cpp | 25 +++++------- src/ModelHighAPI/ModelHighAPI_Double.h | 6 +-- src/ModelHighAPI/ModelHighAPI_Integer.cpp | 25 +++++------- src/ModelHighAPI/ModelHighAPI_Integer.h | 6 +-- src/ModelHighAPI/ModelHighAPI_RefAttr.cpp | 42 +++++++------------- src/ModelHighAPI/ModelHighAPI_RefAttr.h | 9 ++--- src/ModelHighAPI/ModelHighAPI_Selection.cpp | 44 +++++++-------------- src/ModelHighAPI/ModelHighAPI_Selection.h | 6 +-- 8 files changed, 62 insertions(+), 101 deletions(-) diff --git a/src/ModelHighAPI/ModelHighAPI_Double.cpp b/src/ModelHighAPI/ModelHighAPI_Double.cpp index 91cbaac32..c62a0f678 100644 --- a/src/ModelHighAPI/ModelHighAPI_Double.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Double.cpp @@ -12,17 +12,20 @@ //-------------------------------------------------------------------------------------- ModelHighAPI_Double::ModelHighAPI_Double(double theValue) -: myValue(theValue) +: myVariantType(VT_DOUBLE) +, myDouble(theValue) { } ModelHighAPI_Double::ModelHighAPI_Double(const std::string & theValue) -: myValue(theValue) +: myVariantType(VT_STRING) +, myString(theValue) { } ModelHighAPI_Double::ModelHighAPI_Double(const char * theValue) -: myValue(theValue) +: myVariantType(VT_STRING) +, myString(theValue) { } @@ -31,19 +34,11 @@ ModelHighAPI_Double::~ModelHighAPI_Double() } //-------------------------------------------------------------------------------------- -struct fill_visitor : boost::static_visitor -{ - mutable std::shared_ptr myAttribute; - - fill_visitor(const std::shared_ptr & theAttribute) - : myAttribute(theAttribute) {} - - void operator()(double theValue) const { myAttribute->setValue(theValue); } - void operator()(const std::string & theValue) const { myAttribute->setText(theValue); } -}; - void ModelHighAPI_Double::fillAttribute( const std::shared_ptr & theAttribute) const { - boost::apply_visitor(fill_visitor(theAttribute), myValue); + switch(myVariantType) { + case VT_DOUBLE: theAttribute->setValue(myDouble); return; + case VT_STRING: theAttribute->setText(myString); return; + } } diff --git a/src/ModelHighAPI/ModelHighAPI_Double.h b/src/ModelHighAPI/ModelHighAPI_Double.h index e1b3ce687..fdab71d1e 100644 --- a/src/ModelHighAPI/ModelHighAPI_Double.h +++ b/src/ModelHighAPI/ModelHighAPI_Double.h @@ -12,8 +12,6 @@ #include #include - -#include //-------------------------------------------------------------------------------------- class ModelAPI_AttributeDouble; //-------------------------------------------------------------------------------------- @@ -42,7 +40,9 @@ public: virtual void fillAttribute(const std::shared_ptr & theAttribute) const; private: - boost::variant myValue; + enum VariantType { VT_DOUBLE, VT_STRING } myVariantType; + double myDouble; + std::string myString; }; //-------------------------------------------------------------------------------------- diff --git a/src/ModelHighAPI/ModelHighAPI_Integer.cpp b/src/ModelHighAPI/ModelHighAPI_Integer.cpp index 68a612302..e59f605f1 100644 --- a/src/ModelHighAPI/ModelHighAPI_Integer.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Integer.cpp @@ -12,17 +12,20 @@ //-------------------------------------------------------------------------------------- ModelHighAPI_Integer::ModelHighAPI_Integer(int theValue) -: myValue(theValue) +: myVariantType(VT_INT) +, myInt(theValue) { } ModelHighAPI_Integer::ModelHighAPI_Integer(const std::string & theValue) -: myValue(theValue) +: myVariantType(VT_STRING) +, myString(theValue) { } ModelHighAPI_Integer::ModelHighAPI_Integer(const char * theValue) -: myValue(theValue) +: myVariantType(VT_STRING) +, myString(theValue) { } @@ -31,19 +34,11 @@ ModelHighAPI_Integer::~ModelHighAPI_Integer() } //-------------------------------------------------------------------------------------- -struct fill_visitor : boost::static_visitor -{ - mutable std::shared_ptr myAttribute; - - fill_visitor(const std::shared_ptr & theAttribute) - : myAttribute(theAttribute) {} - - void operator()(int theValue) const { myAttribute->setValue(theValue); } - void operator()(const std::string & theValue) const { myAttribute->setText(theValue); } -}; - void ModelHighAPI_Integer::fillAttribute( const std::shared_ptr & theAttribute) const { - boost::apply_visitor(fill_visitor(theAttribute), myValue); + switch(myVariantType) { + case VT_INT: theAttribute->setValue(myInt); return; + case VT_STRING: theAttribute->setText(myString); return; + } } diff --git a/src/ModelHighAPI/ModelHighAPI_Integer.h b/src/ModelHighAPI/ModelHighAPI_Integer.h index 7650b1256..9d7758fbd 100644 --- a/src/ModelHighAPI/ModelHighAPI_Integer.h +++ b/src/ModelHighAPI/ModelHighAPI_Integer.h @@ -12,8 +12,6 @@ #include #include - -#include //-------------------------------------------------------------------------------------- class ModelAPI_AttributeInteger; //-------------------------------------------------------------------------------------- @@ -42,7 +40,9 @@ public: virtual void fillAttribute(const std::shared_ptr & theAttribute) const; private: - boost::variant myValue; + enum VariantType { VT_INT, VT_STRING } myVariantType; + int myInt; + std::string myString; }; //-------------------------------------------------------------------------------------- diff --git a/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp b/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp index 85b4b7acb..999cc718e 100644 --- a/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp +++ b/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp @@ -14,24 +14,28 @@ #include "ModelHighAPI_Interface.h" //-------------------------------------------------------------------------------------- ModelHighAPI_RefAttr::ModelHighAPI_RefAttr() +: myVariantType(VT_ATTRIBUTE) { } ModelHighAPI_RefAttr::ModelHighAPI_RefAttr( const std::shared_ptr & theValue) -: myValue(theValue) +: myVariantType(VT_ATTRIBUTE) +, myAttribute(theValue) { } ModelHighAPI_RefAttr::ModelHighAPI_RefAttr( const std::shared_ptr & theValue) -: myValue(theValue) +: myVariantType(VT_OBJECT) +, myObject(theValue) { } ModelHighAPI_RefAttr::ModelHighAPI_RefAttr( const std::shared_ptr & theValue) -: myValue(std::shared_ptr(theValue->defaultResult())) +: myVariantType(VT_OBJECT) +, myObject(std::shared_ptr(theValue->defaultResult())) { } @@ -40,37 +44,21 @@ ModelHighAPI_RefAttr::~ModelHighAPI_RefAttr() } //-------------------------------------------------------------------------------------- -struct fill_visitor : boost::static_visitor -{ - mutable std::shared_ptr myAttribute; - - fill_visitor(const std::shared_ptr & theAttribute) - : myAttribute(theAttribute) {} - - void operator()(const std::shared_ptr& theValue) const { myAttribute->setAttr(theValue); } - void operator()(const std::shared_ptr& theValue) const { myAttribute->setObject(theValue); } -}; - void ModelHighAPI_RefAttr::fillAttribute( const std::shared_ptr & theAttribute) const { - boost::apply_visitor(fill_visitor(theAttribute), myValue); + switch(myVariantType) { + case VT_ATTRIBUTE: theAttribute->setAttr(myAttribute); return; + case VT_OBJECT: theAttribute->setObject(myObject); return; + } } //-------------------------------------------------------------------------------------- -struct append_visitor : boost::static_visitor -{ - mutable std::shared_ptr myAttribute; - - append_visitor(const std::shared_ptr & theAttribute) - : myAttribute(theAttribute) {} - - void operator()(const std::shared_ptr& theValue) const { myAttribute->append(theValue); } - void operator()(const std::shared_ptr& theValue) const { myAttribute->append(theValue); } -}; - void ModelHighAPI_RefAttr::appendToList( const std::shared_ptr & theAttribute) const { - boost::apply_visitor(append_visitor(theAttribute), myValue); + switch(myVariantType) { + case VT_ATTRIBUTE: theAttribute->append(myAttribute); return; + case VT_OBJECT: theAttribute->append(myObject); return; + } } diff --git a/src/ModelHighAPI/ModelHighAPI_RefAttr.h b/src/ModelHighAPI/ModelHighAPI_RefAttr.h index a2667cab2..bc54e2078 100644 --- a/src/ModelHighAPI/ModelHighAPI_RefAttr.h +++ b/src/ModelHighAPI/ModelHighAPI_RefAttr.h @@ -12,8 +12,6 @@ #include #include - -#include //-------------------------------------------------------------------------------------- class ModelAPI_Attribute; class ModelAPI_AttributeRefAttr; @@ -53,10 +51,9 @@ public: virtual void appendToList(const std::shared_ptr & theAttribute) const; private: - boost::variant< - std::shared_ptr, - std::shared_ptr - > myValue; + enum VariantType { VT_ATTRIBUTE, VT_OBJECT } myVariantType; + std::shared_ptr myAttribute; + std::shared_ptr myObject; }; //-------------------------------------------------------------------------------------- diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.cpp b/src/ModelHighAPI/ModelHighAPI_Selection.cpp index e997aa4e0..ff2ba0479 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Selection.cpp @@ -14,13 +14,15 @@ //-------------------------------------------------------------------------------------- ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr& theContext, const std::shared_ptr& theSubShape) -: myValue(ResultSubShapePair(theContext, theSubShape)) +: myVariantType(VT_ResultSubShapePair) +, myResultSubShapePair(theContext, theSubShape) { } ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType, const std::string& theSubShapeName) -: myValue(TypeSubShapeNamePair(theType, theSubShapeName)) +: myVariantType(VT_TypeSubShapeNamePair) +, myTypeSubShapeNamePair(theType, theSubShapeName) { } @@ -29,40 +31,24 @@ ModelHighAPI_Selection::~ModelHighAPI_Selection() } //-------------------------------------------------------------------------------------- -struct fill_visitor : boost::static_visitor -{ - mutable std::shared_ptr myAttribute; - - fill_visitor(const std::shared_ptr & theAttribute) - : myAttribute(theAttribute) {} - - void operator()(const ResultSubShapePair & thePair) const { myAttribute->setValue(thePair.first, thePair.second); } - void operator()(const TypeSubShapeNamePair & thePair) const { myAttribute->selectSubShape(thePair.first, thePair.second); } -}; - void ModelHighAPI_Selection::fillAttribute( const std::shared_ptr & theAttribute) const { - boost::apply_visitor(fill_visitor(theAttribute), myValue); + switch(myVariantType) { + case VT_ResultSubShapePair: theAttribute->setValue(myResultSubShapePair.first, myResultSubShapePair.second); return; + case VT_TypeSubShapeNamePair: theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second); return; + } } //-------------------------------------------------------------------------------------- -struct append_visitor : boost::static_visitor -{ - mutable std::shared_ptr myAttribute; - - append_visitor(const std::shared_ptr & theAttribute) - : myAttribute(theAttribute) {} - - void operator()(const ResultSubShapePair & thePair) const { myAttribute->append(thePair.first, thePair.second); } - void operator()(const TypeSubShapeNamePair & thePair) const { - // Note: the reverse order (first - type, second - sub-shape name) - myAttribute->append(thePair.second, thePair.first); - } -}; - void ModelHighAPI_Selection::appendToList( const std::shared_ptr & theAttribute) const { - boost::apply_visitor(append_visitor(theAttribute), myValue); + switch(myVariantType) { + case VT_ResultSubShapePair: theAttribute->append(myResultSubShapePair.first, myResultSubShapePair.second); return; + case VT_TypeSubShapeNamePair: + // Note: the reverse order (first - type, second - sub-shape name) + theAttribute->append(myTypeSubShapeNamePair.second, myTypeSubShapeNamePair.first); + return; + } } diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.h b/src/ModelHighAPI/ModelHighAPI_Selection.h index 36706aacb..0be8642f7 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.h +++ b/src/ModelHighAPI/ModelHighAPI_Selection.h @@ -13,8 +13,6 @@ #include #include #include - -#include //-------------------------------------------------------------------------------------- class GeomAPI_Shape; class ModelAPI_AttributeSelection; @@ -52,7 +50,9 @@ public: virtual void appendToList(const std::shared_ptr & theAttribute) const; private: - boost::variant myValue; + enum VariantType { VT_ResultSubShapePair, VT_TypeSubShapeNamePair } myVariantType; + ResultSubShapePair myResultSubShapePair; + TypeSubShapeNamePair myTypeSubShapeNamePair; }; //-------------------------------------------------------------------------------------- -- 2.30.2