Salome HOME
Remove dependency on boost
authorspo <sergey.pokhodenko@opencascade.com>
Mon, 20 Jun 2016 11:52:33 +0000 (14:52 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Mon, 20 Jun 2016 11:52:33 +0000 (14:52 +0300)
src/ModelHighAPI/ModelHighAPI_Double.cpp
src/ModelHighAPI/ModelHighAPI_Double.h
src/ModelHighAPI/ModelHighAPI_Integer.cpp
src/ModelHighAPI/ModelHighAPI_Integer.h
src/ModelHighAPI/ModelHighAPI_RefAttr.cpp
src/ModelHighAPI/ModelHighAPI_RefAttr.h
src/ModelHighAPI/ModelHighAPI_Selection.cpp
src/ModelHighAPI/ModelHighAPI_Selection.h

index 91cbaac32914e30e1e68db9c6f0f18bd3bd0158c..c62a0f678c5fa5a14cacabe6616402a56e710cea 100644 (file)
 
 //--------------------------------------------------------------------------------------
 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<void>
-{
-  mutable std::shared_ptr<ModelAPI_AttributeDouble> myAttribute;
-
-  fill_visitor(const std::shared_ptr<ModelAPI_AttributeDouble> & 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<ModelAPI_AttributeDouble> & 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;
+  }
 }
index e1b3ce6872758fab3095907c7a1acd367c4e7016..fdab71d1e54696c9033a92f680d5a09b8c49c692 100644 (file)
@@ -12,8 +12,6 @@
 
 #include <memory>
 #include <string>
-
-#include <boost/variant.hpp>
 //--------------------------------------------------------------------------------------
 class ModelAPI_AttributeDouble;
 //--------------------------------------------------------------------------------------
@@ -42,7 +40,9 @@ public:
   virtual void fillAttribute(const std::shared_ptr<ModelAPI_AttributeDouble> & theAttribute) const;
 
 private:
-  boost::variant<double, std::string> myValue;
+  enum VariantType { VT_DOUBLE, VT_STRING } myVariantType;
+  double myDouble;
+  std::string myString;
 };
 
 //--------------------------------------------------------------------------------------
index 68a612302d16437915b6b6980d867458c8cde503..e59f605f13bdbb420e7df0fac6d0b31c707e64f7 100644 (file)
 
 //--------------------------------------------------------------------------------------
 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<void>
-{
-  mutable std::shared_ptr<ModelAPI_AttributeInteger> myAttribute;
-
-  fill_visitor(const std::shared_ptr<ModelAPI_AttributeInteger> & 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<ModelAPI_AttributeInteger> & 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;
+  }
 }
index 7650b125644b7abc36923c9ac377f7f2a36ff42d..9d7758fbd26e9029229dd707a19706a02f153865 100644 (file)
@@ -12,8 +12,6 @@
 
 #include <memory>
 #include <string>
-
-#include <boost/variant.hpp>
 //--------------------------------------------------------------------------------------
 class ModelAPI_AttributeInteger;
 //--------------------------------------------------------------------------------------
@@ -42,7 +40,9 @@ public:
   virtual void fillAttribute(const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute) const;
 
 private:
-  boost::variant<int, std::string> myValue;
+  enum VariantType { VT_INT, VT_STRING } myVariantType;
+  int myInt;
+  std::string myString;
 };
 
 //--------------------------------------------------------------------------------------
index 85b4b7acb1b423bee3159e7d95bb015b3d6418f1..999cc718effb225a7dbef99b34f4539dc94cdae4 100644 (file)
 #include "ModelHighAPI_Interface.h"
 //--------------------------------------------------------------------------------------
 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr()
+: myVariantType(VT_ATTRIBUTE)
 {
 }
 
 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
     const std::shared_ptr<ModelAPI_Attribute> & theValue)
-: myValue(theValue)
+: myVariantType(VT_ATTRIBUTE)
+, myAttribute(theValue)
 {
 }
 
 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
     const std::shared_ptr<ModelAPI_Object> & theValue)
-: myValue(theValue)
+: myVariantType(VT_OBJECT)
+, myObject(theValue)
 {
 }
 
 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
     const std::shared_ptr<ModelHighAPI_Interface> & theValue)
-: myValue(std::shared_ptr<ModelAPI_Object>(theValue->defaultResult()))
+: myVariantType(VT_OBJECT)
+, myObject(std::shared_ptr<ModelAPI_Object>(theValue->defaultResult()))
 {
 }
 
@@ -40,37 +44,21 @@ ModelHighAPI_RefAttr::~ModelHighAPI_RefAttr()
 }
 
 //--------------------------------------------------------------------------------------
-struct fill_visitor : boost::static_visitor<void>
-{
-  mutable std::shared_ptr<ModelAPI_AttributeRefAttr> myAttribute;
-
-  fill_visitor(const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute)
-  : myAttribute(theAttribute) {}
-
-  void operator()(const std::shared_ptr<ModelAPI_Attribute>& theValue) const { myAttribute->setAttr(theValue); }
-  void operator()(const std::shared_ptr<ModelAPI_Object>& theValue) const { myAttribute->setObject(theValue); }
-};
-
 void ModelHighAPI_RefAttr::fillAttribute(
     const std::shared_ptr<ModelAPI_AttributeRefAttr> & 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<void>
-{
-  mutable std::shared_ptr<ModelAPI_AttributeRefAttrList> myAttribute;
-
-  append_visitor(const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute)
-  : myAttribute(theAttribute) {}
-
-  void operator()(const std::shared_ptr<ModelAPI_Attribute>& theValue) const { myAttribute->append(theValue); }
-  void operator()(const std::shared_ptr<ModelAPI_Object>& theValue) const { myAttribute->append(theValue); }
-};
-
 void ModelHighAPI_RefAttr::appendToList(
     const std::shared_ptr<ModelAPI_AttributeRefAttrList> & 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;
+  }
 }
index a2667cab244e7afea283c19f6d874b20e8f76082..bc54e20789d32777a9d11b4a387ddd3a8235689b 100644 (file)
@@ -12,8 +12,6 @@
 
 #include <memory>
 #include <string>
-
-#include <boost/variant.hpp>
 //--------------------------------------------------------------------------------------
 class ModelAPI_Attribute;
 class ModelAPI_AttributeRefAttr;
@@ -53,10 +51,9 @@ public:
   virtual void appendToList(const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute) const;
 
 private:
-  boost::variant<
-    std::shared_ptr<ModelAPI_Attribute>,
-    std::shared_ptr<ModelAPI_Object>
-  > myValue;
+  enum VariantType { VT_ATTRIBUTE, VT_OBJECT } myVariantType;
+  std::shared_ptr<ModelAPI_Attribute> myAttribute;
+  std::shared_ptr<ModelAPI_Object> myObject;
 };
 
 //--------------------------------------------------------------------------------------
index e997aa4e01db5cd53d2304e9e7f9c4de986de32a..ff2ba0479b00db32db1335b15ce5b883f250890e 100644 (file)
 //--------------------------------------------------------------------------------------
 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext,
                                                const std::shared_ptr<GeomAPI_Shape>& 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<void>
-{
-  mutable std::shared_ptr<ModelAPI_AttributeSelection> myAttribute;
-
-  fill_visitor(const std::shared_ptr<ModelAPI_AttributeSelection> & 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<ModelAPI_AttributeSelection> & 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<void>
-{
-  mutable std::shared_ptr<ModelAPI_AttributeSelectionList> myAttribute;
-
-  append_visitor(const std::shared_ptr<ModelAPI_AttributeSelectionList> & 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<ModelAPI_AttributeSelectionList> & 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;
+  }
 }
index 36706aacbc612956fff2a30723a0310a2344d6e6..0be8642f78557c541dfe43b96d6d6ed0f2e2eec3 100644 (file)
@@ -13,8 +13,6 @@
 #include <memory>
 #include <string>
 #include <utility>
-
-#include <boost/variant.hpp>
 //--------------------------------------------------------------------------------------
 class GeomAPI_Shape;
 class ModelAPI_AttributeSelection;
@@ -52,7 +50,9 @@ public:
   virtual void appendToList(const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const;
 
 private:
-  boost::variant<ResultSubShapePair, TypeSubShapeNamePair> myValue;
+  enum VariantType { VT_ResultSubShapePair, VT_TypeSubShapeNamePair } myVariantType;
+  ResultSubShapePair myResultSubShapePair;
+  TypeSubShapeNamePair myTypeSubShapeNamePair;
 };
 
 //--------------------------------------------------------------------------------------