Skip to content

Commit

Permalink
#733 derrive python native types on read operation
Browse files Browse the repository at this point in the history
  • Loading branch information
ylil93 authored and Abhi Keshav committed Sep 7, 2018
1 parent 8d278d7 commit 866c8dd
Show file tree
Hide file tree
Showing 11 changed files with 510 additions and 172 deletions.
7 changes: 6 additions & 1 deletion sdk/cpp/core/src/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ enum class YType {
boolean,
enumeration,
bits,
decimal64
decimal64,
younion
};

class YLeaf
Expand All @@ -245,6 +246,7 @@ class YLeaf
YLeaf(YType type, std::string name);
~YLeaf();

YLeaf(YType type, std::string name, std::vector<YType> younions);
YLeaf(const YLeaf& val);
YLeaf(YLeaf&& val);

Expand Down Expand Up @@ -303,6 +305,7 @@ class YLeaf
std::string name;
std::string value;
YType type;
std::vector<YType> younions;
Bits bits_value;
};

Expand All @@ -311,6 +314,7 @@ class YLeafList {
YLeafList(YType type, const std::string & name);
virtual ~YLeafList();

YLeafList(YType type, const std::string & name, std::vector<YType> younions);
YLeafList(const YLeafList& val);
YLeafList(YLeafList&& val);

Expand Down Expand Up @@ -349,6 +353,7 @@ class YLeafList {
std::vector<YLeaf> values;
YType type;
std::string name;
std::vector<YType> younions;
};

class YList
Expand Down
11 changes: 11 additions & 0 deletions sdk/cpp/core/src/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ std::string to_str(YType t)
TOSTRING(enumeration);
TOSTRING(bits);
TOSTRING(decimal64);
TOSTRING(younion);
}
return "";
#undef TOSTRING
Expand All @@ -70,6 +71,16 @@ YLeaf::YLeaf(YType type, std::string name):
{
}

YLeaf::YLeaf(YType type, std::string name, std::vector<YType> younions):
is_set(false),
yfilter(YFilter::not_set),
name(name),
value(""),
type(type),
younions(younions)
{
}

YLeaf::YLeaf(const YLeaf& val):
is_set{val.is_set},
yfilter(YFilter::not_set),
Expand Down
6 changes: 6 additions & 0 deletions sdk/cpp/core/src/value_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ string to_string(YType t)
TOSTRING(enumeration);
TOSTRING(bits);
TOSTRING(decimal64);
TOSTRING(younion);
}
return "";
}
Expand All @@ -65,6 +66,11 @@ YLeafList::YLeafList(YType type, const std::string & name)
{
}

YLeafList::YLeafList(YType type, const std::string & name, std::vector<YType> younions)
: yfilter(YFilter::not_set), type(type), name(name), younions(younions)
{
}

YLeafList::YLeafList(const YLeafList& other)
: yfilter(YFilter::not_set), values(other.getYLeafs()), type(other.type), name(other.name)
{
Expand Down
7 changes: 6 additions & 1 deletion sdk/python/core/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,8 @@ PYBIND11_MODULE(ydk_, ydk)
.value("boolean", ydk::YType::boolean)
.value("enumeration", ydk::YType::enumeration)
.value("bits", ydk::YType::bits)
.value("decimal64", ydk::YType::decimal64);
.value("decimal64", ydk::YType::decimal64)
.value("younion", ydk::YType::younion);

enum_<ydk::path::ModelCachingOption>(types, "ModelCachingOption")
.value("common", ydk::path::ModelCachingOption::COMMON)
Expand Down Expand Up @@ -665,6 +666,7 @@ PYBIND11_MODULE(ydk_, ydk)

class_<ydk::YLeaf>(types, "YLeaf")
.def(init<ydk::YType, string>(), arg("leaf_type"), arg("name"))
.def(init<ydk::YType, string, vector<ydk::YType>>(), arg("leaf_type"), arg("name"), arg("younions"))
.def("get", &ydk::YLeaf::get, return_value_policy::reference)
.def("get_name_leafdata", &ydk::YLeaf::get_name_leafdata, return_value_policy::reference)
.def(self == self, return_value_policy::reference)
Expand Down Expand Up @@ -694,12 +696,14 @@ PYBIND11_MODULE(ydk_, ydk)
.def_readonly("is_set", &ydk::YLeaf::is_set, return_value_policy::reference)
.def_readonly("name", &ydk::YLeaf::name, return_value_policy::reference)
.def_readonly("type", &ydk::YLeaf::type, return_value_policy::reference)
.def_readonly("younions", &ydk::YLeaf::younions, return_value_policy::reference)
.def_readwrite("yfilter", &ydk::YLeaf::yfilter)
.def_readwrite("value_namespace", &ydk::YLeaf::value_namespace)
.def_readwrite("value_namespace_prefix", &ydk::YLeaf::value_namespace_prefix);

class_<ydk::YLeafList, PyYLeafList>(types, "YLeafList")
.def(init<ydk::YType, string>(), arg("leaflist_type"), arg("name"))
.def(init<ydk::YType, string, vector<ydk::YType>>(), arg("leaflist_type"), arg("name"), arg("younions"))
.def("getYLeafs", &ydk::YLeafList::getYLeafs)
.def("get_name_leafdata", &ydk::YLeafList::get_name_leafdata)
.def(self == self)
Expand Down Expand Up @@ -728,6 +732,7 @@ PYBIND11_MODULE(ydk_, ydk)
})
.def_readonly("name", &ydk::YLeafList::name, return_value_policy::reference)
.def_readonly("type", &ydk::YLeafList::type, return_value_policy::reference)
.def_readonly("younions", &ydk::YLeafList::younions, return_value_policy::reference)
.def_readwrite("yfilter", &ydk::YLeafList::yfilter);

class_<ydk::NetconfServiceProvider, ydk::ServiceProvider>(providers, "NetconfServiceProvider")
Expand Down

0 comments on commit 866c8dd

Please sign in to comment.