Repository navigation
Expand file tree
/
Copy pathRCQuery.cpp
More file actions
115 lines (103 loc) · 2.55 KB
/
Copy pathRCQuery.cpp
File metadata and controls
115 lines (103 loc) · 2.55 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
104
105
106
107
108
109
110
111
112
113
114
115
//
// Created by andrei on 13.03.23.
//
#include <sstream>
#include "RCQuery.h"
RCQuery::RCQuery(
MEASURE_LOCALE aLocale,
const std::string &aValue,
COMPONENT defaultMeasure
)
{
size_t p = 0;
parse(aLocale, aValue, p, defaultMeasure);
}
RCQuery::RCQuery(
const RCQuery &value
) {
locale = value.locale;
measure = value.measure;
nominal = value.nominal;
componentName = value.componentName;
// properties
properties = value.properties;
// operation
code = value.code;
boxes = value.boxes;
count = value.count;
destinationBox = value.destinationBox;
}
int RCQuery::parse(
MEASURE_LOCALE aLocale,
const std::string &value,
size_t &position,
COMPONENT defaultComponent
)
{
MeasureUnit::parse(aLocale, value, position, nominal, measure, componentName, defaultComponent);
int r = QueryProperties::parse(value, position, properties);
if (r)
return r;
r = StockOperation::parse(value, position, code, boxBlocks, boxes, count, destinationBox);
if (r)
return r;
return r;
}
RCQuery::RCQuery(
MEASURE_LOCALE locale,
COMPONENT measure,
uint64_t nominal,
const std::string &componentName,
const std::map<std::string, std::string> &properties,
STOCK_OPERATION_CODE code,
uint64_t boxes,
size_t count
)
: locale(locale), measure(measure), nominal(nominal),
componentName(componentName), properties(properties), code(code),
boxBlocks(boxBlocks), boxes(boxes), count(count)
{
}
std::string RCQuery::toString()
{
std::stringstream ss;
if (!componentName.empty()) {
ss << componentName;
if (measure)
ss << " ";
}
if (nominal)
ss << MeasureUnit::value(ML_RU, measure, nominal);
for (auto p(properties.begin()); p != properties.end(); p++) {
ss << " " << p->first << ":" << p->second;
}
if (boxes) {
ss << " " << StockOperation::boxes2string(boxes);
}
switch (code) {
case SO_COUNT:
ss << " count";
break;
case SO_SUM:
ss << " sum";
break;
case SO_SET:
ss << "=" << count;
break;
case SO_ADD:
ss << "+" << count;
break;
case SO_SUB:
ss << "-" << count;
break;
case SO_RM:
ss << " rm";
break;
default: // SO_NONE SO_LIST SO_LIST_NO_BOX:
break;
}
return ss.str();
}
bool RCQuery::hasNominal() const {
return MeasureUnit::hasNominal(measure);
}