forked from yxkhuijie/ick
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadOnlyInt.cpp
More file actions
104 lines (88 loc) · 1.56 KB
/
ReadOnlyInt.cpp
File metadata and controls
104 lines (88 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "ReadOnlyInt.h"
#include "IMutex.h"
#include <sstream>
ReadOnlyInt::ReadOnlyInt(int value)
{
m_dataType = INTDATA;
m_accessMode = READONLY;
m_value = value;
m_valueInfo.setValue(value);
m_oldValue = m_value;
m_valid = false;
}
ReadOnlyInt::ReadOnlyInt(IntValueInfo& valueInfo)
{
m_dataType = INTDATA;
m_accessMode = READONLY;
m_value = valueInfo.getValue();
m_valueInfo = valueInfo;
m_oldValue = m_value;
}
ReadOnlyInt::~ReadOnlyInt()
{
}
int ReadOnlyInt::getValue()
{
if (isSimulated())
{
if (m_value != m_oldValue)
{
m_oldValue = m_value;
m_valid = true;
m_isChanged = true;
}
return m_value;
}
if (m_driver != NULL && m_pfn_read.pfn_ri != NULL)
{
int value = 0;
if ((m_driver->*m_pfn_read.pfn_ri)(this->m_ChannelNumber,&value))
{
if (m_value != value)
{
m_oldValue = m_value;
m_value = value;
m_valid = true;
m_isChanged = true;
}
this->m_isValid = true;
}
}
return this->m_value;
}
int ReadOnlyInt::getOldValue()
{
return this->m_oldValue;
}
bool ReadOnlyInt::isValidated()
{
return m_valid;
}
void ReadOnlyInt::setSimulatedValue(int value)
{
if (isSimulated())
{
m_value = value;
this->m_isValid = true;
}
else
{
throw "read only int data can not be set simulated value in not simulated mode";
}
}
std::string ReadOnlyInt::getValueAsString() const
{
std::stringstream s;
s << m_value << std::endl;
std::string res = "";
s >> res;
return res;
}
IntValueInfo ReadOnlyInt::getValueInfo() const
{
return m_valueInfo;
}
TypeInfo ReadOnlyInt::getTypeInfo() const
{
return TypeInfo();
}