blob: e30c7015cdd45e21458951d66a199c7314df0e9e [file] [log] [blame]
Václav Kubernát0d4db442018-07-18 17:18:43 +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#pragma once
10
11#include <set>
12#include <stdexcept>
13#include <unordered_map>
14#include "ast_path.hpp"
15#include "schema.hpp"
16
17class Context;
18class Set;
19class Schema_Node;
20
21/*! \class YangSchema
22 * \brief A schema class, which uses libyang for queries.
23 * */
24class YangSchema : public Schema {
25public:
26 YangSchema();
27 ~YangSchema() override;
28
29 bool isContainer(const path_& location, const ModuleNodePair& node) const override;
30 bool isLeaf(const path_& location, const ModuleNodePair& node) const override;
31 bool isModule(const path_& location, const std::string& name) const override;
32 bool isList(const path_& location, const ModuleNodePair& node) const override;
33 bool isPresenceContainer(const path_& location, const ModuleNodePair& node) const override;
34 bool leafEnumHasValue(const path_& location, const ModuleNodePair& node, const std::string& value) const override;
35 bool listHasKey(const path_& location, const ModuleNodePair& node, const std::string& key) const override;
36 bool nodeExists(const std::string& location, const std::string& node) const override;
37 const std::set<std::string> listKeys(const path_& location, const ModuleNodePair& node) const override;
38 yang::LeafDataTypes leafType(const path_& location, const ModuleNodePair& node) const override;
39 std::set<std::string> childNodes(const path_& path) const override;
40
41 /** @short Adds a new module passed as a YANG string. */
42 void addSchemaString(const char* schema);
43
44 /** @short Adds a new module from a file. */
45 void addSchemaFile(const char* filename);
46
47 /** @short Adds a new directory for schema lookup. */
48 void addSchemaDirectory(const char* directoryName);
49
50private:
51 std::set<std::string> modules() const;
52 bool nodeExists(const path_& location, const ModuleNodePair& node) const;
53
54 /** @short Returns a set of nodes, that match the location and name criteria. */
55 std::shared_ptr<Set> getNodeSet(const path_& location, const ModuleNodePair& node) const;
56
57 /** @short Returns a single Schema_Node if the criteria matches only one, otherwise nullptr. */
58 std::shared_ptr<Schema_Node> getSchemaNode(const path_& location, const ModuleNodePair& node) const;
59 std::shared_ptr<Context> m_context;
60};