taco-db  0.1.0
fmgr.h
Go to the documentation of this file.
1 
13 namespace taco {
14 
15 
22 {
23  std::vector<NullableDatumRef> args;
24  uint64_t typparam;
25 };
26 
27 
28 typedef Datum (*FunctionPtr)(FunctionCallInfo &fcinfo);
29 
50 typedef std::function<Datum(FunctionCallInfo&)> FunctionInfo;
51 
52 /* Standard parameter list for fmgr-compatible functions */
53 #define FMGR_FUNCTION_ARGS ::taco::FunctionCallInfo &fcinfo_
54 
58 #define FMGR_NARGS() (fcinfo_.args.size())
59 
63 #define FMGR_ARG(n) (fcinfo_.args[n])
64 
69 #define FMGR_TYPPARAM() (fcinfo_.typparam)
70 
75 #define FMGR_RETURN_VOID() return Datum::From(0)
76 
80 template<class ...Args>
81 Datum
82 FunctionCall(const FunctionInfo &func, Args&& ...args) {
83  FunctionCallInfo flinfo {
84  .args = std::vector<NullableDatumRef>{std::forward<Args>(args)...},
85  .typparam = 0
86  };
87 
88  return func(flinfo);
89 }
90 
91 /*
92  * Call a function with a type parameter for the return type.
93  */
94 template<class ...Args>
95 Datum
97  uint64_t typparam,
98  Args&& ...args) {
99  FunctionCallInfo flinfo {
100  .args = std::vector<NullableDatumRef>{std::forward<Args>(args)...},
101  .typparam = typparam,
102  };
103 
104  return func(flinfo);
105 }
106 
107 } // namespace taco
108 
A Datum stores and possibly manage the memory resource of a read-only value of a plain fixed-length C...
Definition: datum.h:250
Definition: datum.h:28
Datum FunctionCall(const FunctionInfo &func, Args &&...args)
Call a function without passing any type parameter for the return type.
Definition: fmgr.h:82
Datum(* FunctionPtr)(FunctionCallInfo &fcinfo)
Definition: fmgr.h:28
Datum FunctionCallWithTypparam(const FunctionInfo &func, uint64_t typparam, Args &&...args)
Definition: fmgr.h:96
std::function< Datum(FunctionCallInfo &)> FunctionInfo
An FMGR managed function should be declared as.
Definition: fmgr.h:50
This struct is the data actually passed to an fmgr function.
Definition: fmgr.h:22
uint64_t typparam
Definition: fmgr.h:24
std::vector< NullableDatumRef > args
Definition: fmgr.h:23