Skip to content

Commit

Permalink
c++ FEATURE allow constructing Submodule from Module (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
syyyr committed May 13, 2020
1 parent 43b04d1 commit 9267156
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions swig/cpp/src/Tree_Schema.cpp
Expand Up @@ -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<S_Schema_Node> Module::data_instantiables(int options) {
std::vector<S_Schema_Node> s_vector;
struct lys_node *iter = NULL;
Expand Down
3 changes: 3 additions & 0 deletions swig/cpp/src/Tree_Schema.hpp
Expand Up @@ -111,6 +111,7 @@ class Module

friend Context;
friend Data_Node;
friend Submodule;

private:
struct lys_module *module;
Expand All @@ -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);
Expand Down

0 comments on commit 9267156

Please sign in to comment.