-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathparser_context.cpp
More file actions
61 lines (53 loc) · 1.61 KB
/
parser_context.cpp
File metadata and controls
61 lines (53 loc) · 1.61 KB
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
/*
* Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
* Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
*
* Written by Václav Kubernát <[email protected]>
*
*/
#include "parser_context.hpp"
ParserContext::ParserContext(const Schema& schema, const std::shared_ptr<const DataQuery> dataQuery, const dataPath_& curDir)
: m_schema(schema)
, m_curPathOrig(curDir)
, m_dataquery(dataQuery)
, m_curPath(curDir)
{
}
void ParserContext::clearPath()
{
m_curPath = dataPath_{Scope::Absolute, {}};
}
schemaPath_ ParserContext::currentSchemaPath()
{
if (m_curPath.type() == typeid(dataPath_)) {
return dataPathToSchemaPath(boost::get<dataPath_>(m_curPath));
} else {
return boost::get<schemaPath_>(m_curPath);
}
}
dataPath_ ParserContext::currentDataPath()
{
if (m_curPath.type() != typeid(dataPath_)) {
throw std::runtime_error("Tried getting a dataPath_ from ParserContext when only schemaPath_ was available.");
}
return boost::get<dataPath_>(m_curPath);
}
void ParserContext::pushPathFragment(const dataNode_& node)
{
if (m_curPath.type() == typeid(dataPath_)) {
boost::get<dataPath_>(m_curPath).pushFragment(node);
} else {
boost::get<schemaPath_>(m_curPath).pushFragment(dataNodeToSchemaNode(node));
}
}
void ParserContext::pushPathFragment(const schemaNode_& node)
{
if (m_curPath.type() == typeid(dataPath_)) {
m_curPath = dataPathToSchemaPath(boost::get<dataPath_>(m_curPath));
}
boost::get<schemaPath_>(m_curPath).m_nodes.emplace_back(node);
}
void ParserContext::resetPath()
{
m_curPath = m_curPathOrig;
}