blob: 266915109fb002cd02baf7fbcca6117a379d5a89 [file] [log] [blame]
Václav Kubernát02a71152020-01-21 14:52:51 +01001#include "libyang_utils.hpp"
Jan Kundrátbd3169c2020-02-03 19:31:34 +01002#include <cmath>
Václav Kubernát02a71152020-01-21 14:52:51 +01003
4leaf_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átcc2538f2020-02-03 11:33:42 +010021 return value->uint32();
Václav Kubernát02a71152020-01-21 14:52:51 +010022 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át0d8abd12020-05-07 02:00:14 +020030 case LY_TYPE_IDENT:
31 return identityRef_{value->ident()->module()->name(), value->ident()->name()};
Jan Kundrát4225b3f2020-01-24 12:58:38 +010032 case LY_TYPE_BINARY:
Jan Kundrát68985442020-05-07 02:15:34 +020033 return binary_{value->binary()};
Jan Kundrát379bb572020-05-07 03:23:13 +020034 case LY_TYPE_EMPTY:
35 return empty_{};
Jan Kundrátbd3169c2020-02-03 19:31:34 +010036 case LY_TYPE_DEC64:
37 {
38 auto v = value->dec64();
39 return v.value * std::pow(10, -v.digits);
40 }
Václav Kubernát02a71152020-01-21 14:52:51 +010041 default: // TODO: implement all types
42 return "(can't print)"s;
43 }
44}