Salome HOME
Avoid SegFault exception
[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 : myVariantType(VT_ATTRIBUTE)
18 {
19 }
20
21 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
22     const std::shared_ptr<ModelAPI_Attribute> & theValue)
23 : myVariantType(VT_ATTRIBUTE)
24 , myAttribute(theValue)
25 {
26 }
27
28 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
29     const std::shared_ptr<ModelAPI_Object> & theValue)
30 : myVariantType(VT_OBJECT)
31 , myObject(theValue)
32 {
33 }
34
35 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
36     const std::shared_ptr<ModelHighAPI_Interface> & theValue)
37 : myVariantType(VT_OBJECT)
38 , myObject(std::shared_ptr<ModelAPI_Object>(theValue->defaultResult()))
39 {
40 }
41
42 ModelHighAPI_RefAttr::~ModelHighAPI_RefAttr()
43 {
44 }
45
46 //--------------------------------------------------------------------------------------
47 void ModelHighAPI_RefAttr::fillAttribute(
48     const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute) const
49 {
50   switch(myVariantType) {
51     case VT_ATTRIBUTE: theAttribute->setAttr(myAttribute); return;
52     case VT_OBJECT: theAttribute->setObject(myObject); return;
53   }
54 }
55
56 //--------------------------------------------------------------------------------------
57 void ModelHighAPI_RefAttr::appendToList(
58     const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute) const
59 {
60   switch(myVariantType) {
61     case VT_ATTRIBUTE: theAttribute->append(myAttribute); return;
62     case VT_OBJECT: theAttribute->append(myObject); return;
63   }
64 }
65
66 //--------------------------------------------------------------------------------------
67 bool ModelHighAPI_RefAttr::isEmpty() const
68 {
69   return !(myAttribute && myObject);
70 }