blob: b50a2487d22e2489d200d7de2a1813df814d2c37 [file] [log] [blame]
Václav Kubernát195eeea2018-05-18 13:52:36 +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
9#include "parser_context.hpp"
Václav Kubernát43908fb2020-01-02 19:05:51 +010010ParserContext::ParserContext(const Schema& schema, const std::shared_ptr<const DataQuery> dataQuery, const dataPath_& curDir)
Václav Kubernát48fc3832018-05-28 14:21:22 +020011 : m_schema(schema)
Václav Kubernát5c75b252018-10-10 18:33:47 +020012 , m_curPathOrig(curDir)
Václav Kubernát43908fb2020-01-02 19:05:51 +010013 , m_dataquery(dataQuery)
Václav Kubernát72749c62020-01-03 16:47:34 +010014 , m_curPath(curDir)
Václav Kubernát195eeea2018-05-18 13:52:36 +020015{
Václav Kubernát195eeea2018-05-18 13:52:36 +020016}
Václav Kubernát72749c62020-01-03 16:47:34 +010017
18void ParserContext::clearPath()
19{
20 m_curPath = dataPath_{Scope::Absolute, {}};
Václav Kubernát72749c62020-01-03 16:47:34 +010021}
22
23schemaPath_ ParserContext::currentSchemaPath()
24{
25 if (m_curPath.type() == typeid(dataPath_)) {
26 return dataPathToSchemaPath(boost::get<dataPath_>(m_curPath));
27 } else {
28 return boost::get<schemaPath_>(m_curPath);
29 }
30}
31
32dataPath_ ParserContext::currentDataPath()
33{
34 if (m_curPath.type() != typeid(dataPath_)) {
35 throw std::runtime_error("Tried getting a dataPath_ from ParserContext when only schemaPath_ was available.");
36 }
37 return boost::get<dataPath_>(m_curPath);
38}
39
40void ParserContext::pushPathFragment(const dataNode_& node)
41{
Václav Kubernát72749c62020-01-03 16:47:34 +010042 if (m_curPath.type() == typeid(dataPath_)) {
Václav Kubernáte781b902020-06-15 14:35:11 +020043 boost::get<dataPath_>(m_curPath).pushFragment(node);
Václav Kubernát72749c62020-01-03 16:47:34 +010044 } else {
Václav Kubernáte781b902020-06-15 14:35:11 +020045 boost::get<schemaPath_>(m_curPath).pushFragment(dataNodeToSchemaNode(node));
Václav Kubernát72749c62020-01-03 16:47:34 +010046 }
47}
48
49void ParserContext::pushPathFragment(const schemaNode_& node)
50{
51 if (m_curPath.type() == typeid(dataPath_)) {
52 m_curPath = dataPathToSchemaPath(boost::get<dataPath_>(m_curPath));
53 }
54
Václav Kubernátfaacd022020-07-08 16:44:38 +020055 boost::get<schemaPath_>(m_curPath).m_nodes.emplace_back(node);
Václav Kubernát72749c62020-01-03 16:47:34 +010056}
57
58void ParserContext::resetPath()
59{
60 m_curPath = m_curPathOrig;
Václav Kubernát72749c62020-01-03 16:47:34 +010061}