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