Salome HOME
Correct naming of results while dumping
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_RefAttr.cpp
index 4f00429c14ce22dcd6cfd0572d303d1c0b9327a3..6bb6aeb3b2597aedc5ccd7e8e52c48dd9582e94e 100644 (file)
 #include <ModelAPI_Result.h>
 #include "ModelHighAPI_Interface.h"
 //--------------------------------------------------------------------------------------
-#include <iostream>
-//--------------------------------------------------------------------------------------
 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->feature()->firstResult()))
+: myVariantType(VT_OBJECT)
+, myObject(std::shared_ptr<ModelAPI_Object>(theValue->defaultResult()))
 {
-  // TODO(spo): make firstResult() a member of ModelHighAPI_Interface and use it
 }
 
 ModelHighAPI_RefAttr::~ModelHighAPI_RefAttr()
@@ -43,37 +44,27 @@ 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;
+  }
+}
+
+//--------------------------------------------------------------------------------------
+bool ModelHighAPI_RefAttr::isEmpty() const
+{
+  return !(myAttribute && myObject);
 }