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 <treelite/error.h>
12 #include <string>
13 
14 namespace treelite {
15 namespace frontend {
16 
17 template<typename Func>
18 inline auto
19 Value::Dispatch(Func func) {
20  switch (type_) {
21  case TypeInfo::kUInt32:
22  return func(Get<uint32_t>());
23  case TypeInfo::kFloat32:
24  return func(Get<float>());
25  case TypeInfo::kFloat64:
26  return func(Get<double>());
27  default:
28  throw Error(std::string("Unknown value type detected: ")
29  + std::to_string(static_cast<int>(type_)));
30  return func(Get<double>()); // avoid "missing return" warning
31  }
32 }
33 
34 template<typename Func>
35 inline auto
36 Value::Dispatch(Func func) const {
37  switch (type_) {
38  case TypeInfo::kUInt32:
39  return func(Get<uint32_t>());
40  case TypeInfo::kFloat32:
41  return func(Get<float>());
42  case TypeInfo::kFloat64:
43  return func(Get<double>());
44  default:
45  throw Error(std::string("Unknown value type detected: ")
46  + std::to_string(static_cast<int>(type_)));
47  return func(Get<double>()); // avoid "missing return" warning
48  }
49 }
50 
51 } // namespace frontend
52 } // namespace treelite
53 
54 #endif // TREELITE_FRONTEND_IMPL_H_
Exception class used throughout the Treelite codebase.