blob: 561455cd762e7b4768e1dadeee2afd2fd9699586 [file] [log] [blame]
Václav Kubernátbddbb172018-06-13 16:27:39 +02001
Václav Kubernát624a8872018-03-02 17:28:47 +01002/*
3 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
Václav Kubernátd6662962018-03-22 17:41:33 +01004 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
Václav Kubernát624a8872018-03-02 17:28:47 +01005 *
6 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
7 *
8*/
9
10#pragma once
11
Václav Kubernát509ce652019-05-29 19:46:44 +020012#include <boost/variant/variant.hpp>
Václav Kubernátb96eef72018-05-04 19:10:22 +020013#include <set>
Václav Kubernát624a8872018-03-02 17:28:47 +010014#include <stdexcept>
15#include <unordered_map>
Václav Kubernát24df80e2018-06-06 15:18:03 +020016#include "ast_path.hpp"
Václav Kubernátd6662962018-03-22 17:41:33 +010017
Václav Kubernáteeb38842019-03-20 19:46:05 +010018using ModuleValuePair = std::pair<boost::optional<std::string>, std::string>;
19
Václav Kubernát48fc3832018-05-28 14:21:22 +020020namespace yang {
Václav Kubernátebca2552018-06-08 19:06:02 +020021enum class LeafDataTypes {
22 String,
23 Decimal,
24 Bool,
Ivona Oboňová88c78ca2019-07-02 18:40:07 +020025 Int8,
26 Uint8,
27 Int16,
28 Uint16,
29 Int32,
30 Uint32,
31 Int64,
32 Uint64,
Václav Kubernátebca2552018-06-08 19:06:02 +020033 Enum,
Václav Kubernátab538992019-03-06 15:30:50 +010034 Binary,
Václav Kubernáteeb38842019-03-20 19:46:05 +010035 IdentityRef,
Václav Kubernát6a8d1d92019-04-24 20:30:36 +020036 LeafRef,
Václav Kubernátebca2552018-06-08 19:06:02 +020037};
Václav Kubernát34ee85a2020-02-18 17:12:12 +010038
39enum class NodeTypes {
40 Container,
41 PresenceContainer,
42 List,
43 Leaf
44};
Václav Kubernátb96eef72018-05-04 19:10:22 +020045}
Václav Kubernátd6662962018-03-22 17:41:33 +010046
Václav Kubernáte7d4aea2018-09-11 18:15:48 +020047enum class Recursion {
48 NonRecursive,
49 Recursive
50};
Václav Kubernátf2e463f2018-05-28 15:51:08 +020051
Václav Kubernát624a8872018-03-02 17:28:47 +010052
Václav Kubernát34ee85a2020-02-18 17:12:12 +010053class InvalidNodeException {
Václav Kubernát624a8872018-03-02 17:28:47 +010054};
55
Václav Kubernát48fc3832018-05-28 14:21:22 +020056/*! \class Schema
Václav Kubernátbddbb172018-06-13 16:27:39 +020057 * \brief A base schema class for schemas
Václav Kubernát624a8872018-03-02 17:28:47 +010058 * */
Václav Kubernát744f57f2018-06-29 22:46:26 +020059
60using ModuleNodePair = std::pair<boost::optional<std::string>, std::string>;
61
Václav Kubernát48fc3832018-05-28 14:21:22 +020062class Schema {
Václav Kubernát624a8872018-03-02 17:28:47 +010063public:
Václav Kubernátbddbb172018-06-13 16:27:39 +020064 virtual ~Schema();
Václav Kubernátd6662962018-03-22 17:41:33 +010065
Václav Kubernát2a141392020-02-18 17:12:32 +010066 bool isContainer(const schemaPath_& location, const ModuleNodePair& node) const;
67 bool isLeaf(const schemaPath_& location, const ModuleNodePair& node) const;
68 bool isList(const schemaPath_& location, const ModuleNodePair& node) const;
69 bool isPresenceContainer(const schemaPath_& location, const ModuleNodePair& node) const;
Václav Kubernát34ee85a2020-02-18 17:12:12 +010070 virtual yang::NodeTypes nodeType(const std::string& path) const = 0;
71 virtual yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
Václav Kubernát75877de2019-11-20 17:43:02 +010072 virtual bool isModule(const std::string& name) const = 0;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020073 virtual bool leafEnumHasValue(const schemaPath_& location, const ModuleNodePair& node, const std::string& value) const = 0;
Václav Kubernáteeb38842019-03-20 19:46:05 +010074 virtual bool leafIdentityIsValid(const schemaPath_& location, const ModuleNodePair& node, const ModuleValuePair& value) const = 0;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020075 virtual bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const = 0;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020076 virtual const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const = 0;
77 virtual yang::LeafDataTypes leafType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
Václav Kubernát9bf36852020-02-18 17:47:56 +010078 virtual yang::LeafDataTypes leafType(const std::string& path) const = 0;
Václav Kubernátf0fe7692020-02-19 14:39:47 +010079 virtual yang::LeafDataTypes leafrefBaseType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
Václav Kubernát1e09bd62020-02-17 15:13:38 +010080 virtual std::optional<std::string> description(const std::string& location) const = 0;
81 virtual std::optional<std::string> units(const std::string& location) const = 0;
Václav Kubernát6a8d1d92019-04-24 20:30:36 +020082
Václav Kubernáteeb38842019-03-20 19:46:05 +010083 virtual const std::set<std::string> validIdentities(const schemaPath_& location, const ModuleNodePair& node, const Prefixes prefixes) const = 0;
Václav Kubernát989b5de2019-02-20 16:28:35 +010084 virtual const std::set<std::string> enumValues(const schemaPath_& location, const ModuleNodePair& node) const = 0;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020085 virtual std::set<std::string> childNodes(const schemaPath_& path, const Recursion recursion) const = 0;
Václav Kubernát9456b5c2019-10-02 21:14:52 +020086 virtual std::set<std::string> moduleNodes(const module_& module, const Recursion recursion) const = 0;
Václav Kubernát624a8872018-03-02 17:28:47 +010087};