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 | 4225b3f | 2020-01-24 12:58:38 +0100 | [diff] [blame] | 30 | case LY_TYPE_BINARY: |
| 31 | return std::string{value->binary()}; |
Jan Kundrát | bd3169c | 2020-02-03 19:31:34 +0100 | [diff] [blame] | 32 | case LY_TYPE_DEC64: |
| 33 | { |
| 34 | auto v = value->dec64(); |
| 35 | return v.value * std::pow(10, -v.digits); |
| 36 | } |
Václav Kubernát | 02a7115 | 2020-01-21 14:52:51 +0100 | [diff] [blame] | 37 | default: // TODO: implement all types |
| 38 | return "(can't print)"s; |
| 39 | } |
| 40 | } |