-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStation.cpp
More file actions
83 lines (77 loc) · 2.58 KB
/
Station.cpp
File metadata and controls
83 lines (77 loc) · 2.58 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
#include "Station.h"
namespace sdds
{
unsigned Station::m_widthField = 0;
unsigned Station::id_generator = 0;
Station::Station(const std::string &record)
{
Utilities util;
bool more = true; // if there are more tokens in the input string
size_t pos = 0u; // position of the next token in the input string
int counter = 0;
while (more)
{
counter++;
try
{
auto token = util.extractToken(record, pos, more);
if (counter == 1)
{
m_id = ++id_generator;
if (util.getFieldWidth() > m_widthField)
m_widthField = util.getFieldWidth();
m_name = token;
}
else if (counter == 2)
m_serial_num = std::stoi(token);
else if (counter == 3)
m_stock = std::stoi(token);
else
m_description = token;
}
catch (...)
{
std::cout << " ERROR: No token.\n";
}
}
};
const std::string &Station::getItemName() const
{
return m_name;
};
size_t Station::getNextSerialNumber()
{
return m_serial_num++;
};
size_t Station::getQuantity() const
{
return m_stock;
};
void Station::updateQuantity()
{
m_stock > 0 && --m_stock;
};
std::string Station::generateStringBluePrint() const
{
// Armchair, 654321, 10, Upholstered Wing Chair
std::string bluePrint = m_name + "| " + std::to_string(m_serial_num) + "| " + std::to_string(m_stock) + "| " + m_description;
return bluePrint;
}
void Station::display(std::ostream &os, bool full) const
{
if (full)
{
os << std::setfill('0') << std::setw(3) << std::right << m_id << " | "
<< std::setfill(' ') << std::setw(m_widthField - 1) << std::left << m_name << " | "
<< std::setfill('0') << std::setw(6) << std::right << m_serial_num << " | "
<< std::setfill(' ') << std::setw(4) << std::right << m_stock << " | "
<< m_description << std::endl;
}
else
{
os << std::setfill('0') << std::setw(3) << std::right << m_id << " | ";
os << std::setfill(' ') << std::setw(m_widthField - 1) << std::left << m_name << " | ";
os << std::setfill('0') << std::setw(6) << std::right << m_serial_num << " | " << std::endl;
}
};
}