From 926715683c5afed203358c24f64aa70b501f057c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Kubern=C3=A1t?= Date: Wed, 13 May 2020 09:03:27 +0200 Subject: [PATCH] c++ FEATURE allow constructing Submodule from Module (#1085) --- swig/cpp/src/Tree_Schema.cpp | 8 ++++++++ swig/cpp/src/Tree_Schema.hpp | 3 +++ 2 files changed, 11 insertions(+) diff --git a/swig/cpp/src/Tree_Schema.cpp b/swig/cpp/src/Tree_Schema.cpp index 8ff2df389..3500ceda6 100644 --- a/swig/cpp/src/Tree_Schema.cpp +++ b/swig/cpp/src/Tree_Schema.cpp @@ -39,6 +39,14 @@ Submodule::Submodule(struct lys_submodule *submodule, S_Deleter deleter): submodule(submodule), deleter(deleter) {}; +Submodule::Submodule(S_Module module): + submodule((lys_submodule*)module->module), + deleter(module->deleter) +{ + if (module->type() != 1) { + throw std::invalid_argument("Attempted to cast a YANG module into a YANG submodule"); + } +} std::vector Module::data_instantiables(int options) { std::vector s_vector; struct lys_node *iter = NULL; diff --git a/swig/cpp/src/Tree_Schema.hpp b/swig/cpp/src/Tree_Schema.hpp index e3cb31929..aebea0fde 100644 --- a/swig/cpp/src/Tree_Schema.hpp +++ b/swig/cpp/src/Tree_Schema.hpp @@ -111,6 +111,7 @@ class Module friend Context; friend Data_Node; + friend Submodule; private: struct lys_module *module; @@ -126,6 +127,8 @@ class Submodule public: /** wrapper for struct [lys_submodule](@ref lys_submodule), for internal use only */ Submodule(struct lys_submodule *submodule, S_Deleter deleter); + /** creates a Submodule from `module` if it is a submodule */ + Submodule(S_Module module); ~Submodule(); /** get ctx variable from [lys_submodule](@ref lys_submodule)*/ S_Context ctx() LY_NEW(submodule, ctx, Context);