-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShoesDataForType.cpp
94 lines (70 loc) · 2.09 KB
/
ShoesDataForType.cpp
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 <iostream>
#include <ostream>
#include "Reader.h"
#include "ShoesDataForType.h"
using std::string;
using std::cout;
using std::endl;
using std::pair;
using std::make_pair;
using std::to_string;
using std::ostream;
#define SMALL_SHOES 37
//В основном, всё описано в заголовочном файле
void ShoesDataForType::addPosition(pair<short, int> p) {
addPosition(p.first,p.second);
}
void ShoesDataForType::addPosition(short size, int amount) {
if (amount >= 0) {
auto searcher = data.find(size);
if (searcher == data.end())
data.insert(make_pair(size, amount));
else (*searcher).second += amount;
}
}
bool ShoesDataForType::hasSmallSizes() const {
if (data.size() == 0) return false;
for (const pair<short, int>& p : data)
if (p.first < SMALL_SHOES) return true;
return false;
}
void ShoesDataForType::contOut() const noexcept{
for (const pair<short, int>& pp : data)
cout << " S:" << pp.first << " x" << pp.second << endl;
}
int ShoesDataForType::countAmount() const noexcept {
int result = 0;
for (const pair<short, int>& p : data)
result += p.second;
return result;
}
void ShoesDataForType::rm(){
data.clear();
}
string ShoesDataForType::fileFill() const noexcept{
string n;
for(const pair<short,int>& i : data) {
n += to_string(i.second);
n+= (i.first - 25 + 'A');
}
return n;
}
int ShoesDataForType::mapSize() const noexcept { return data.size(); }
//Не очень простой метод, который вызывается другим не очень простым методом из StorageShoes. Результат - строку разбирают на данные
void ShoesDataForType::cutFromString(string &s) {
int i;
string t;
char c;
pair<short, int> p;
while (Reader::isDigit(s[0])) {
i = 0;
while (Reader::isDigit(s[i])) i++;
t = s.substr(0, i);
c = s[i];
p.second = stoi(t);
p.first = (short)(c - 'A') + 25;
data.insert(p);
s = s.substr(i + 1, s.length() - i - 1);
if (s.empty()) break;
}
}