Václav Kubernát | 195eeea | 2018-05-18 13:52:36 +0200 | [diff] [blame] | 1 | /* |
| 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át | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 10 | ParserContext::ParserContext(const Schema& schema, const std::shared_ptr<const DataQuery> dataQuery, const dataPath_& curDir) |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 11 | : m_schema(schema) |
Václav Kubernát | 5c75b25 | 2018-10-10 18:33:47 +0200 | [diff] [blame] | 12 | , m_curPathOrig(curDir) |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 13 | , m_dataquery(dataQuery) |
Václav Kubernát | 72749c6 | 2020-01-03 16:47:34 +0100 | [diff] [blame] | 14 | , m_curPath(curDir) |
Václav Kubernát | 195eeea | 2018-05-18 13:52:36 +0200 | [diff] [blame] | 15 | { |
Václav Kubernát | 195eeea | 2018-05-18 13:52:36 +0200 | [diff] [blame] | 16 | } |
Václav Kubernát | 72749c6 | 2020-01-03 16:47:34 +0100 | [diff] [blame] | 17 | |
| 18 | void ParserContext::clearPath() |
| 19 | { |
| 20 | m_curPath = dataPath_{Scope::Absolute, {}}; |
Václav Kubernát | 72749c6 | 2020-01-03 16:47:34 +0100 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | schemaPath_ 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 | |
| 32 | dataPath_ 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 | |
| 40 | void ParserContext::pushPathFragment(const dataNode_& node) |
| 41 | { |
Václav Kubernát | 72749c6 | 2020-01-03 16:47:34 +0100 | [diff] [blame] | 42 | if (m_curPath.type() == typeid(dataPath_)) { |
Václav Kubernát | e781b90 | 2020-06-15 14:35:11 +0200 | [diff] [blame] | 43 | boost::get<dataPath_>(m_curPath).pushFragment(node); |
Václav Kubernát | 72749c6 | 2020-01-03 16:47:34 +0100 | [diff] [blame] | 44 | } else { |
Václav Kubernát | e781b90 | 2020-06-15 14:35:11 +0200 | [diff] [blame] | 45 | boost::get<schemaPath_>(m_curPath).pushFragment(dataNodeToSchemaNode(node)); |
Václav Kubernát | 72749c6 | 2020-01-03 16:47:34 +0100 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
| 49 | void 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át | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 55 | boost::get<schemaPath_>(m_curPath).m_nodes.emplace_back(node); |
Václav Kubernát | 72749c6 | 2020-01-03 16:47:34 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void ParserContext::resetPath() |
| 59 | { |
| 60 | m_curPath = m_curPathOrig; |
Václav Kubernát | 72749c6 | 2020-01-03 16:47:34 +0100 | [diff] [blame] | 61 | } |