-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBmsReferenceListDataUnit.cpp
More file actions
42 lines (35 loc) · 1.21 KB
/
BmsReferenceListDataUnit.cpp
File metadata and controls
42 lines (35 loc) · 1.21 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
#include "BmsReferenceListDataUnit.hpp"
#include "_Detail/Utilities.hpp"
namespace Bms {
BmsReferenceListDataUnit::BmsReferenceListDataUnit(const IdType &id)
: BmsDataUnit(id) {}
void BmsReferenceListDataUnit::SetValue(const std::string &value) throw(BmsException) {
using namespace std;
using namespace _Detail;
if (value.size() % 2 != 0) {
throw BmsException(string("in ") + LIBBMS_FUNCTION_SIGNATURE + ": Wrong format.");
}
ValueType newValue;
for (size_t i = 0; i < value.size(); i += 2) {
ValueType::value_type id(value.substr(i, 2));
newValue.push_back(id);
}
Value = newValue;
}
void BmsReferenceListDataUnit::Shrink() {
using namespace std;
const auto size = Value.size();
auto gcd = size;
for (size_t i = 1; i < size; ++i) {
if (Value[i].UnderlyingValue() != 0) {
gcd = _Detail::Gcd(gcd, i);
}
}
vector<BmsReferenceId> ids;
for (size_t i = 0; i < size; i += gcd) {
ids.push_back(Value[i]);
}
Value = move(ids);
}
BmsReferenceListDataUnit::~BmsReferenceListDataUnit() {}
}