-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegerData.cpp
More file actions
80 lines (73 loc) · 1.7 KB
/
Copy pathIntegerData.cpp
File metadata and controls
80 lines (73 loc) · 1.7 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
#include <string>
#include <sstream>
#include "IntegerData.h"
using namespace std;
using namespace insight;
/* Constructor
*
*/
IntegerData::IntegerData()
{
m_integerData = 0;
}
/* Construct to define header
*
* header - header string, left justified in the zone
*/
IntegerData::IntegerData(std::string header)
{
m_integerHeader = m_integerHeader;
m_integerData = 0;
}
/* Get the formatted string for the zone
*
* lengthOfZone - lenght to format to
*
*/
std::string IntegerData::getFormattedString(char lengthOfZone)
{
if(m_updateString)
{
ostringstream oss;
oss << m_integerData;
string tmpString = oss.str();
m_formattedString.clear();
m_updateString = false;
if(m_integerHeader.length() + tmpString.length() > lengthOfZone)
{
if(tmpString.length() > lengthOfZone)
{
tmpString.erase(tmpString.end() - (tmpString.length() - lengthOfZone), tmpString.end());
}
m_formattedString = m_integerHeader.substr(0, lengthOfZone - tmpString.length()) + tmpString;
}
else
{
m_formattedString = m_integerHeader + string(lengthOfZone - (m_integerHeader.length() + tmpString.length()), ' ').
append(tmpString);
}
}
return m_formattedString;
}
/* Set the data. This is called to set the data, as the display runs
* the updated values will be displayed
*
* data - the data to display
*
*/
void IntegerData::setData(int data)
{
m_updateString = true;
m_integerData = data;
}
/* Set the header. This is called to set or change the header, as the display
* runs the updated value will be displayed
*
* header - data description to display
*/
void IntegerData::setHeader(string header)
{
m_updateString = true;
m_integerHeader.clear();
m_integerHeader = header;
}