blob: f97e382b76ec3682cf52f8c1c5fca53b14bd10a2 [file] [log] [blame]
Václav Kubernát3a99f002020-03-31 02:27:41 +02001/*
2 * Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Václav Kubernát <kubernat@cesnet.cz>
5 *
6*/
7#include "ast_values.hpp"
8#include "leaf_data_type.hpp"
9
10namespace yang {
Václav Kubernát13b23d72020-04-16 21:49:51 +020011bool TypeInfo::operator==(const TypeInfo& other) const
12{
Václav Kubernát1ae24f42020-12-01 02:32:04 +010013 return std::tie(this->m_type, this->m_units, this->m_description) == std::tie(other.m_type, other.m_units, other.m_description);
Václav Kubernát13b23d72020-04-16 21:49:51 +020014}
Václav Kubernát1ae24f42020-12-01 02:32:04 +010015TypeInfo::TypeInfo(const yang::LeafDataType& type, const std::optional<std::string> units, const std::optional<std::string> description)
Václav Kubernát13b23d72020-04-16 21:49:51 +020016 : m_type(type)
17 , m_units(units)
Václav Kubernát1ae24f42020-12-01 02:32:04 +010018 , m_description(description)
Václav Kubernát13b23d72020-04-16 21:49:51 +020019{
20}
Václav Kubernát3a99f002020-03-31 02:27:41 +020021Enum::Enum(std::set<enum_>&& values)
22 : m_allowedValues(std::move(values))
23{
24}
25bool Enum::operator==(const Enum& other) const
26{
27 return this->m_allowedValues == other.m_allowedValues;
28}
29IdentityRef::IdentityRef(std::set<identityRef_>&& values)
30 : m_allowedValues(std::move(values))
31{
32}
33bool IdentityRef::operator==(const IdentityRef& other) const
34{
35 return this->m_allowedValues == other.m_allowedValues;
36}
37// Copy constructor needed, because unique_ptr is not copy-constructible
38LeafRef::LeafRef(const LeafRef& src)
39 : m_targetXPath(src.m_targetXPath)
Václav Kubernát13b23d72020-04-16 21:49:51 +020040 , m_targetType(std::make_unique<TypeInfo>(*src.m_targetType))
Václav Kubernát3a99f002020-03-31 02:27:41 +020041{
42}
Václav Kubernát13b23d72020-04-16 21:49:51 +020043LeafRef::LeafRef(const std::string& xpath, std::unique_ptr<TypeInfo>&& type)
Václav Kubernát3a99f002020-03-31 02:27:41 +020044 : m_targetXPath(xpath)
45 , m_targetType(std::move(type))
46{
47}
48bool LeafRef::operator==(const LeafRef& other) const
49{
50 return this->m_targetXPath == other.m_targetXPath && *this->m_targetType == *other.m_targetType;
51}
Václav Kubernát2984f442020-02-20 17:43:35 +010052bool Union::operator==(const Union& other) const
53{
54 return this->m_unionTypes == other.m_unionTypes;
55}
Václav Kubernát3a99f002020-03-31 02:27:41 +020056bool String::operator==(const String&) const
57{
58 return true;
59}
60bool Decimal::operator==(const Decimal&) const
61{
62 return true;
63}
64bool Bool::operator==(const Bool&) const
65{
66 return true;
67}
68bool Int8::operator==(const Int8&) const
69{
70 return true;
71}
72bool Uint8::operator==(const Uint8&) const
73{
74 return true;
75}
76bool Int16::operator==(const Int16&) const
77{
78 return true;
79}
80bool Uint16::operator==(const Uint16&) const
81{
82 return true;
83}
84bool Int32::operator==(const Int32&) const
85{
86 return true;
87}
88bool Uint32::operator==(const Uint32&) const
89{
90 return true;
91}
92bool Int64::operator==(const Int64&) const
93{
94 return true;
95}
96bool Uint64::operator==(const Uint64&) const
97{
98 return true;
99}
100bool Binary::operator==(const Binary&) const
101{
102 return true;
103}
Jan Kundrát379bb572020-05-07 03:23:13 +0200104bool Empty::operator==(const Empty&) const
105{
106 return true;
107}
Václav Kubernátdab73ca2020-10-26 23:44:43 +0100108bool Bits::operator==(const Bits& other) const
109{
110 return this->m_allowedValues == other.m_allowedValues;
111}
Václav Kubernát3a99f002020-03-31 02:27:41 +0200112}