Salome HOME
Add Mirror and fix tests
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_RefAttr.cpp
1 // Name   : ModelHighAPI_RefAttr.cpp
2 // Purpose: 
3 //
4 // History:
5 // 08/06/16 - Sergey POKHODENKO - Creation of the file
6
7 //--------------------------------------------------------------------------------------
8 #include "ModelHighAPI_RefAttr.h"
9
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 //--------------------------------------------------------------------------------------
16 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr()
17 {
18 }
19
20 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
21     const std::shared_ptr<ModelAPI_Attribute> & theValue)
22 : myValue(theValue)
23 {
24 }
25
26 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
27     const std::shared_ptr<ModelAPI_Object> & theValue)
28 : myValue(theValue)
29 {
30 }
31
32 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
33     const std::shared_ptr<ModelHighAPI_Interface> & theValue)
34 : myValue(std::shared_ptr<ModelAPI_Object>(theValue->defaultResult()))
35 {
36 }
37
38 ModelHighAPI_RefAttr::~ModelHighAPI_RefAttr()
39 {
40 }
41
42 //--------------------------------------------------------------------------------------
43 struct fill_visitor : boost::static_visitor<void>
44 {
45   mutable std::shared_ptr<ModelAPI_AttributeRefAttr> myAttribute;
46
47   fill_visitor(const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute)
48   : myAttribute(theAttribute) {}
49
50   void operator()(const std::shared_ptr<ModelAPI_Attribute>& theValue) const { myAttribute->setAttr(theValue); }
51   void operator()(const std::shared_ptr<ModelAPI_Object>& theValue) const { myAttribute->setObject(theValue); }
52 };
53
54 void ModelHighAPI_RefAttr::fillAttribute(
55     const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute) const
56 {
57   boost::apply_visitor(fill_visitor(theAttribute), myValue);
58 }
59
60 //--------------------------------------------------------------------------------------
61 struct append_visitor : boost::static_visitor<void>
62 {
63   mutable std::shared_ptr<ModelAPI_AttributeRefAttrList> myAttribute;
64
65   append_visitor(const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute)
66   : myAttribute(theAttribute) {}
67
68   void operator()(const std::shared_ptr<ModelAPI_Attribute>& theValue) const { myAttribute->append(theValue); }
69   void operator()(const std::shared_ptr<ModelAPI_Object>& theValue) const { myAttribute->append(theValue); }
70 };
71
72 void ModelHighAPI_RefAttr::appendToList(
73     const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute) const
74 {
75   boost::apply_visitor(append_visitor(theAttribute), myValue);
76 }