1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name : ModelHighAPI_ComponentValue.cpp
6 // 29/03/16 - Sergey POKHODENKO - Creation of the file
8 //--------------------------------------------------------------------------------------
9 #include "ModelHighAPI_ComponentValue.h"
11 #include <ModelAPI_AttributeInteger.h>
15 //--------------------------------------------------------------------------------------
16 ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const bool theValue)
17 : myType(ModelAPI_AttributeTables::BOOLEAN)
19 // initialize everything since in python there may be problem with correct typification
20 myValue.myBool = theValue;
21 myValue.myInt = theValue ? 1 : 0;
22 myValue.myDouble = theValue ? 1. : 0.;
23 myValue.myStr = theValue ? "True" : "False";
25 //--------------------------------------------------------------------------------------
26 ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const int theValue)
27 : myType(ModelAPI_AttributeTables::INTEGER)
29 // initialize everything since in python there may be problem with correct typification
30 myValue.myBool = theValue == 0 ? false : true;
31 myValue.myInt = theValue;
32 myValue.myDouble = theValue;
35 myValue.myStr = s.str();
37 //--------------------------------------------------------------------------------------
38 ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const double theValue)
39 : myType(ModelAPI_AttributeTables::DOUBLE)
41 // initialize everything since in python there may be problem with correct typification
42 myValue.myBool = theValue == 0. ? false : true;
43 myValue.myInt = int(theValue);
44 myValue.myDouble = theValue;
47 myValue.myStr = s.str();
49 //--------------------------------------------------------------------------------------
50 ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const std::string& theValue)
51 : myType(ModelAPI_AttributeTables::STRING)
53 myValue.myBool = (theValue.empty() || theValue == "False" || theValue == "0") ? false : true;
55 std::stringstream stream1(theValue);
57 stream1 >> myValue.myInt;
58 std::stringstream stream2(theValue);
59 myValue.myDouble = 0.;
60 stream2 >> myValue.myDouble;
62 myValue.myStr = theValue;
65 //--------------------------------------------------------------------------------------
66 ModelHighAPI_ComponentValue::~ModelHighAPI_ComponentValue()
70 //--------------------------------------------------------------------------------------
71 void ModelHighAPI_ComponentValue::fill(const std::shared_ptr<ModelAPI_AttributeTables>& theAttr,
72 const int theTable, const int theColumn, const int theRow) const
74 theAttr->setValue(myValue, theRow, theColumn, theTable);