forked from xR3b0rn/dbcppp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValueTableImpl.cpp
More file actions
77 lines (73 loc) · 2.4 KB
/
ValueTableImpl.cpp
File metadata and controls
77 lines (73 loc) · 2.4 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
#include "../../include/dbcppp/Network.h"
#include "ValueTableImpl.h"
using namespace dbcppp;
std::unique_ptr<IValueTable> IValueTable::Create(
std::string&& name
, std::optional<std::unique_ptr<ISignalType>>&& signal_type
, std::vector<std::unique_ptr<IValueEncodingDescription>>&& value_encoding_descriptions)
{
std::optional<SignalTypeImpl> st;
std::vector<ValueEncodingDescriptionImpl> veds;
veds.reserve(value_encoding_descriptions.size());
if (signal_type)
{
st = std::move(static_cast<SignalTypeImpl&>(**signal_type));
(*signal_type).reset(nullptr);
}
for (auto& ved : value_encoding_descriptions)
{
veds.push_back(std::move(static_cast<ValueEncodingDescriptionImpl&>(*ved)));
ved.reset(nullptr);
}
return std::make_unique<ValueTableImpl>(std::move(name), std::move(st), std::move(veds));
}
ValueTableImpl::ValueTableImpl(
std::string&& name
, std::optional<SignalTypeImpl>&& signal_type
, std::vector<ValueEncodingDescriptionImpl>&& value_encoding_descriptions)
: _name(std::move(name))
, _signal_type(std::move(signal_type))
, _value_encoding_descriptions(std::move(value_encoding_descriptions))
{}
std::unique_ptr<IValueTable> ValueTableImpl::Clone() const
{
return std::make_unique<ValueTableImpl>(*this);
}
const std::string& ValueTableImpl::Name() const
{
return _name;
}
std::optional<std::reference_wrapper<const ISignalType>> ValueTableImpl::SignalType() const
{
std::optional<std::reference_wrapper<const ISignalType>> signal_type;
if (_signal_type)
{
signal_type = *_signal_type;
}
return signal_type;
}
const IValueEncodingDescription& ValueTableImpl::ValueEncodingDescriptions_Get(std::size_t i) const
{
return _value_encoding_descriptions[i];
}
uint64_t ValueTableImpl::ValueEncodingDescriptions_Size() const
{
return _value_encoding_descriptions.size();
}
bool ValueTableImpl::operator==(const IValueTable& rhs) const
{
bool equal = true;
equal &= _name == rhs.Name();
equal &= _signal_type == rhs.SignalType();
for (const auto& ved : rhs.ValueEncodingDescriptions())
{
auto beg = _value_encoding_descriptions.begin();
auto end = _value_encoding_descriptions.end();
equal &= std::find(beg, end, ved) != end;
}
return equal;
}
bool ValueTableImpl::operator!=(const IValueTable& rhs) const
{
return !(*this == rhs);
}