StreamBase C++ API  7.7.1.3
PluginFunction.hpp
1 //
2 // Copyright (c) 2004-2017 Cloud Software Group, Inc. All rights reserved.
3 //
4 
5 #ifndef STREAMBASE_PLUGIN_FUNCTION_H
6 #define STREAMBASE_PLUGIN_FUNCTION_H
7 
8 #include "StreamBase.hpp"
9 #include "StreamBaseVersion.hpp"
10 
11 #include "Plugin.hpp"
12 #include "DataType.hpp"
13 #include "PluginException.hpp"
14 #include "PluginRegistry.hpp"
15 
16 SB_NAMESPACE_BEGIN;
17 
18 class PluginFunctionRep;
19 
20 /// A plugin function.
21 class SB_EXPORT PluginFunction : public Plugin {
22  public:
23  virtual ~PluginFunction() {}
24 
25  /// Check to make sure the argument types are valid for this
26  /// function.
27  /// @param arg_types The types of the arguments to this function.
28  /// @throw TypecheckException if the argument types are not
29  /// appropriate.
30  virtual void typecheck(const Schema &arg_types) {}
31 
32  /// Evaluate this function over the arguments and place the return
33  /// value in retval.
34  /// @param retval Value where the output of this function should
35  /// be placed. Its type will match the type returned from the
36  /// typecheck method.
37  /// @param args Values corresponding to the arguments. Their types
38  /// will match the types passed to typecheck.
39  /// @throw PluginEvalException if anything goes wrong.
40  virtual void eval(Tuple &retval, Tuple &args) = 0;
41 };
42 
43 #ifndef DOXYGEN_SKIP
44 typedef PluginRegistryInfo<PluginFunction> PluginFunctionRegistryInfo;
45 
46 void SB_EXPORT plugin_function_callback(const PluginFunctionRegistryInfo &info);
47 
48 template<>
49 struct PluginRegistryCallback<PluginFunctionRegistryInfo> {
50  void operator()(const PluginFunctionRegistryInfo &info)
51  {
52  plugin_function_callback(info);
53  }
54 };
55 
56 typedef PluginRegistryCallback<PluginFunctionRegistryInfo> PluginFunctionRegistryCallback;
57 
58 typedef PluginRegistry<PluginFunction,
59  PluginFunctionRegistryInfo,
60  PluginFunctionRegistryCallback> PluginFunctionRegistry;
61 
62 #ifdef WIN32
63 // See PluginAggregate.hpp for a description of why this is here...
64 
65 #ifndef STREAMBASE_PLUGIN_VERSION_DEFINED
66 #define STREAMBASE_PLUGIN_VERSION_DEFINED
67 // this function is used to determine what streambase version the plugin was compiled against
68 extern "C" __declspec( dllexport ) inline const char*streambase_plugin_version() {return ((char *)&StreamBaseVersion::INFO_LINE);}
69 #endif
70 
71 class SB_EXPORT PluginRegistryFunction {
72  public:
73  static bool Add(PluginRegistry<PluginFunction, PluginRegistryInfo<PluginFunction>, PluginRegistryCallback< PluginRegistryInfo<PluginFunction> > >::Info* streambase_plugin_info) {
74  return (PluginRegistry<PluginFunction>::get().add(*streambase_plugin_info), true);
75  }
76 };
77 
78 #define STREAMBASE_DEFINE_PLUGIN_FUNCTION(ClassName, FuncName) \
79  const SimplePluginRegistryInfo<PluginFunction, ClassName> ClassName::_streambase_plugin_info(FuncName); \
80  bool ClassName::_streambase_plugin_registered= \
81  PluginRegistryFunction::Add((PluginRegistryInfo<PluginFunction>*)&(ClassName::_streambase_plugin_info));
82 
83 #define STREAMBASE_DECLARE_PLUGIN_FUNCTION(ClassName) \
84  public: \
85  static const SimplePluginRegistryInfo<PluginFunction, ClassName> _streambase_plugin_info; \
86  static bool _streambase_plugin_registered;
87 
88 #else
89 #define STREAMBASE_DECLARE_PLUGIN_FUNCTION(ClassName) \
90  STREAMBASE_DECLARE_PLUGIN_REG_CLASS(PluginFunction, ClassName)
91 
92 #define STREAMBASE_DEFINE_PLUGIN_FUNCTION(ClassName, FuncName) \
93  STREAMBASE_DEFINE_PLUGIN_REG_CLASS_WITH_KEY(PluginFunction, ClassName, FuncName)
94 #endif
95 
96 #endif // !defined(DOXYGEN_SKIP)
97 
98 SB_NAMESPACE_END;
99 #endif //PLUGIN_FUNCTION_H
100