Salome HOME
Remove dependency on boost
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Selection.cpp
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;
+  }
 }