Skip to content

YAMLNode.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
#include "YAMLNode.hpp"

bool YAMLNode::has(const key_type& key) const {
  return isMapping() && mapping().contains(key);
}

bool YAMLNode::isValue() const {
  return std::holds_alternative<value_type>(contents);
}

bool YAMLNode::isSequence() const {
  return std::holds_alternative<sequence_type>(contents);
}

bool YAMLNode::isMapping() const {
  return std::holds_alternative<mapping_type>(contents);
}

YAMLNode::value_type& YAMLNode::value() {
  return std::get<value_type>(contents);
}

const YAMLNode::value_type& YAMLNode::value() const {
  return std::get<value_type>(contents);
}

YAMLNode::sequence_type& YAMLNode::sequence() {
  return std::get<sequence_type>(contents);
}

const YAMLNode::sequence_type& YAMLNode::sequence() const {
  return std::get<sequence_type>(contents);
}

YAMLNode::mapping_type& YAMLNode::mapping() {
  return std::get<mapping_type>(contents);
}

const YAMLNode::mapping_type& YAMLNode::mapping() const {
  return std::get<mapping_type>(contents);
}

void YAMLNode::set(const variant_type& contents) {
  this->contents = contents;
}

void YAMLNode::setSequence() {
  contents = sequence_type{};
}

void YAMLNode::setMapping() {
  contents = mapping_type{};
}

YAMLNode& YAMLNode::push() {
  return *sequence().emplace_back(std::make_unique<YAMLNode>());
}

YAMLNode& YAMLNode::insert(const key_type& key) {
  return *mapping().insert(std::make_pair(key,
      std::make_unique<YAMLNode>())).first->second;
}