blob: f71c12f0a26d6048dcc8ba1972f3f7445831fa47 [file] [log] [blame]
Václav Kubernát96344a12018-05-28 16:33:39 +02001/*
2 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
3 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
4 *
5 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
6 *
7*/
8
Václav Kubernátb61336d2018-05-28 17:35:03 +02009#include <iostream>
Václav Kubernát96344a12018-05-28 16:33:39 +020010#include "interpreter.hpp"
11
Václav Kubernátebca2552018-06-08 19:06:02 +020012struct leafDataToString : boost::static_visitor<std::string> {
13 std::string operator()(const enum_& data) const
14 {
15 return data.m_value;
16 }
17 template <typename T>
18 std::string operator()(const T& data) const
19 {
20 std::stringstream stream;
21 stream << data;
22 return stream.str();
23 }
24};
25
Václav Kubernát07204242018-06-04 18:12:09 +020026void Interpreter::operator()(const set_& set) const
27{
Václav Kubernátebca2552018-06-08 19:06:02 +020028 std::cout << "Setting " << pathToDataString(set.m_path) << " to " << boost::apply_visitor(leafDataToString(), set.m_data) << std::endl;
Václav Kubernát07204242018-06-04 18:12:09 +020029}
30
Václav Kubernát96344a12018-05-28 16:33:39 +020031void Interpreter::operator()(const cd_& cd) const
32{
33 m_parser.changeNode(cd.m_path);
34}
35
Václav Kubernátb61336d2018-05-28 17:35:03 +020036void Interpreter::operator()(const create_& create) const
37{
Václav Kubernát744f57f2018-06-29 22:46:26 +020038 auto cont = boost::get<container_>(create.m_path.m_nodes.back().m_suffix);
39 std::cout << "Presence container " << cont.m_name << " created." << std::endl;
Václav Kubernátb61336d2018-05-28 17:35:03 +020040}
41
42void Interpreter::operator()(const delete_& delet) const
43{
Václav Kubernát744f57f2018-06-29 22:46:26 +020044 auto cont = boost::get<container_>(delet.m_path.m_nodes.back().m_suffix);
45 std::cout << "Presence container " << cont.m_name << " deleted." << std::endl;
Václav Kubernátb61336d2018-05-28 17:35:03 +020046}
47
Václav Kubernát11afac72018-07-18 14:59:53 +020048void Interpreter::operator()(const ls_& ls) const
49{
50 std::cout << "Possible nodes:" << std::endl;
51
52 for (const auto& it : m_parser.availableNodes(ls.m_path))
53 std::cout << it << std::endl;
54}
55
Václav Kubernátb61336d2018-05-28 17:35:03 +020056Interpreter::Interpreter(Parser& parser, Schema&)
Václav Kubernát96344a12018-05-28 16:33:39 +020057 : m_parser(parser)
58{
59}