-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecimalData.cpp
More file actions
94 lines (86 loc) · 1.99 KB
/
Copy pathDecimalData.cpp
File metadata and controls
94 lines (86 loc) · 1.99 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
#include "DecimalData.h"
#include <iomanip>
#include <sstream>
using namespace std;
using namespace insight;
/* Constructor
*
*/
DecimalData::DecimalData()
{
m_precision = 2;
m_decimalData = 0;
}
/* Construct to define header
*
* header - header string, left justified in the zone
* precision - number of decimal places to display
*/
DecimalData::DecimalData(string header, int precision)
{
m_decimalHeader = header;
m_precision = precision;
m_decimalData = 0;
}
/* Get the formatted string for the zone
*
* lengthOfZone - lenght to format to
*
*/
string DecimalData::getFormattedString(char lengthOfZone)
{
if(m_updateString)
{
ostringstream oss;
oss.setf(ios::fixed,ios::floatfield);
oss.precision(m_precision);
oss << m_decimalData;
string tmpString = oss.str();
m_formattedString.clear();
m_updateString = false;
if(m_decimalHeader.length() + tmpString.length() > lengthOfZone)
{
if(tmpString.length() > lengthOfZone)
{
tmpString.erase(tmpString.end() - (tmpString.length() - lengthOfZone), tmpString.end());
}
m_formattedString = m_decimalHeader.substr(0, lengthOfZone - tmpString.length()) + tmpString;
}
else
{
m_formattedString = m_decimalHeader + string(lengthOfZone - (m_decimalHeader.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 DecimalData::setData(float data)
{
m_updateString = true;
m_decimalData = data;
}
/* Set the header. This is called to set or change the header, as the display
* runs the updated value will be displayed
*
*
*/
void DecimalData::setHeader(string header)
{
m_updateString = true;
m_decimalHeader = header;
}
/* Set the precision to display the data at
*
* precision - decimal places to display
*/
void DecimalData::setPrecision(int precision)
{
m_updateString = true;
m_precision = precision;
}