Václav Kubernát | 02a7115 | 2020-01-21 14:52:51 +0100 | [diff] [blame] | 1 | #include "libyang_utils.hpp" |
Jan Kundrát | bd3169c | 2020-02-03 19:31:34 +0100 | [diff] [blame] | 2 | #include <cmath> |
Václav Kubernát | 02a7115 | 2020-01-21 14:52:51 +0100 | [diff] [blame] | 3 | |
| 4 | leaf_data_ leafValueFromValue(const libyang::S_Value& value, LY_DATA_TYPE type) |
| 5 | { |
| 6 | using namespace std::string_literals; |
| 7 | switch (type) { |
| 8 | case LY_TYPE_INT8: |
| 9 | return value->int8(); |
| 10 | case LY_TYPE_INT16: |
| 11 | return value->int16(); |
| 12 | case LY_TYPE_INT32: |
| 13 | return value->int32(); |
| 14 | case LY_TYPE_INT64: |
| 15 | return value->int64(); |
| 16 | case LY_TYPE_UINT8: |
| 17 | return value->uint8(); |
| 18 | case LY_TYPE_UINT16: |
| 19 | return value->uint16(); |
| 20 | case LY_TYPE_UINT32: |
Jan Kundrát | cc2538f | 2020-02-03 11:33:42 +0100 | [diff] [blame] | 21 | return value->uint32(); |
Václav Kubernát | 02a7115 | 2020-01-21 14:52:51 +0100 | [diff] [blame] | 22 | case LY_TYPE_UINT64: |
| 23 | return value->uint64(); |
| 24 | case LY_TYPE_BOOL: |
| 25 | return bool(value->bln()); |
| 26 | case LY_TYPE_STRING: |
| 27 | return std::string(value->string()); |
| 28 | case LY_TYPE_ENUM: |
| 29 | return enum_{std::string(value->enm()->name())}; |
Jan Kundrát | 0d8abd1 | 2020-05-07 02:00:14 +0200 | [diff] [blame] | 30 | case LY_TYPE_IDENT: |
| 31 | return identityRef_{value->ident()->module()->name(), value->ident()->name()}; |
Jan Kundrát | 4225b3f | 2020-01-24 12:58:38 +0100 | [diff] [blame] | 32 | case LY_TYPE_BINARY: |
Jan Kundrát | 6898544 | 2020-05-07 02:15:34 +0200 | [diff] [blame^] | 33 | return binary_{value->binary()}; |
Jan Kundrát | bd3169c | 2020-02-03 19:31:34 +0100 | [diff] [blame] | 34 | case LY_TYPE_DEC64: |
| 35 | { |
| 36 | auto v = value->dec64(); |
| 37 | return v.value * std::pow(10, -v.digits); |
| 38 | } |
Václav Kubernát | 02a7115 | 2020-01-21 14:52:51 +0100 | [diff] [blame] | 39 | default: // TODO: implement all types |
| 40 | return "(can't print)"s; |
| 41 | } |
| 42 | } |