Treelite
frontend_impl.h
Go to the documentation of this file.
1 
8 #ifndef TREELITE_FRONTEND_IMPL_H_
9 #define TREELITE_FRONTEND_IMPL_H_
10 
11 #include <string>
12 
13 namespace treelite {
14 namespace frontend {
15 
16 template<typename Func>
17 inline auto
18 Value::Dispatch(Func func) {
19  switch (type_) {
20  case TypeInfo::kUInt32:
21  return func(Get<uint32_t>());
22  case TypeInfo::kFloat32:
23  return func(Get<float>());
24  case TypeInfo::kFloat64:
25  return func(Get<double>());
26  default:
27  throw std::runtime_error(std::string("Unknown value type detected: ")
28  + std::to_string(static_cast<int>(type_)));
29  return func(Get<double>()); // avoid "missing return" warning
30  }
31 }
32 
33 template<typename Func>
34 inline auto
35 Value::Dispatch(Func func) const {
36  switch (type_) {
37  case TypeInfo::kUInt32:
38  return func(Get<uint32_t>());
39  case TypeInfo::kFloat32:
40  return func(Get<float>());
41  case TypeInfo::kFloat64:
42  return func(Get<double>());
43  default:
44  throw std::runtime_error(std::string("Unknown value type detected: ")
45  + std::to_string(static_cast<int>(type_)));
46  return func(Get<double>()); // avoid "missing return" warning
47  }
48 }
49 
50 } // namespace frontend
51 } // namespace treelite
52 
53 #endif // TREELITE_FRONTEND_IMPL_H_