1 // Name : ModelHighAPI_RefAttr.cpp
5 // 08/06/16 - Sergey POKHODENKO - Creation of the file
7 //--------------------------------------------------------------------------------------
8 #include "ModelHighAPI_RefAttr.h"
10 #include <ModelAPI_AttributeRefAttr.h>
11 #include <ModelAPI_AttributeRefAttrList.h>
12 #include <ModelAPI_Feature.h>
13 #include <ModelAPI_Result.h>
14 #include "ModelHighAPI_Interface.h"
15 //--------------------------------------------------------------------------------------
17 //--------------------------------------------------------------------------------------
18 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr()
22 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
23 const std::shared_ptr<ModelAPI_Attribute> & theValue)
28 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
29 const std::shared_ptr<ModelAPI_Object> & theValue)
34 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
35 const std::shared_ptr<ModelHighAPI_Interface> & theValue)
36 : myValue(std::shared_ptr<ModelAPI_Object>(theValue->feature()->firstResult()))
38 // TODO(spo): make firstResult() a member of ModelHighAPI_Interface and use it
41 ModelHighAPI_RefAttr::~ModelHighAPI_RefAttr()
45 //--------------------------------------------------------------------------------------
46 struct fill_visitor : boost::static_visitor<void>
48 mutable std::shared_ptr<ModelAPI_AttributeRefAttr> myAttribute;
50 fill_visitor(const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute)
51 : myAttribute(theAttribute) {}
53 void operator()(const std::shared_ptr<ModelAPI_Attribute>& theValue) const { myAttribute->setAttr(theValue); }
54 void operator()(const std::shared_ptr<ModelAPI_Object>& theValue) const { myAttribute->setObject(theValue); }
57 void ModelHighAPI_RefAttr::fillAttribute(
58 const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute) const
60 boost::apply_visitor(fill_visitor(theAttribute), myValue);
63 //--------------------------------------------------------------------------------------
64 struct append_visitor : boost::static_visitor<void>
66 mutable std::shared_ptr<ModelAPI_AttributeRefAttrList> myAttribute;
68 append_visitor(const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute)
69 : myAttribute(theAttribute) {}
71 void operator()(const std::shared_ptr<ModelAPI_Attribute>& theValue) const { myAttribute->append(theValue); }
72 void operator()(const std::shared_ptr<ModelAPI_Object>& theValue) const { myAttribute->append(theValue); }
75 void ModelHighAPI_RefAttr::appendToList(
76 const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute) const
78 boost::apply_visitor(append_visitor(theAttribute), myValue);