Line data Source code
1 : #ifndef ERROR_HANDLER_MA_TEST_H
2 : #define ERROR_HANDLER_MA_TEST_H
3 :
4 : // ----------------------------------------------------------
5 : //
6 : // Base class for custom condition test functions
7 : //
8 : // ----------------------------------------------------------
9 :
10 : #include <boost/any.hpp>
11 : #include <boost/function.hpp>
12 :
13 : #include <map>
14 : #include <string>
15 : #include <vector>
16 :
17 : namespace novadaq {
18 : namespace errorhandler {
19 :
20 : class ma_condition;
21 :
22 : typedef std::vector<boost::any> anys_t;
23 :
24 : class ma_test_function
25 : {
26 : public:
27 0 : ma_test_function() {}
28 0 : virtual ~ma_test_function() {}
29 :
30 : // evaluation function
31 : virtual boost::any
32 : evaluate(ma_condition const& cond) = 0;
33 :
34 : // parse aruments
35 : virtual bool
36 0 : parse_arguments(anys_t const& /*args*/) { return true; }
37 : };
38 :
39 : typedef boost::function<ma_test_function*()> gen_test_t;
40 :
41 : struct ma_test_function_factory
42 : {
43 : typedef std::map<std::string, gen_test_t> gen_map_t;
44 :
45 : public:
46 : static void
47 : reg(std::string const& func_name, gen_test_t f);
48 :
49 : static ma_test_function*
50 : create_instance(std::string const& func_name);
51 :
52 : private:
53 : ma_test_function_factory() {}
54 :
55 : static gen_map_t&
56 0 : get_map()
57 : {
58 0 : static gen_map_t map;
59 0 : return map;
60 : }
61 : };
62 :
63 : struct ma_test_function_maker
64 : {
65 0 : ma_test_function_maker(std::string const& func_name, gen_test_t f)
66 : {
67 0 : ma_test_function_factory::reg(func_name, f);
68 0 : }
69 : };
70 :
71 : } // end of namespace errorhandler
72 : } // end of namespace novadaq
73 :
74 : #define REG_MA_TEST_FUNCTION(func_name, class_name) \
75 : ma_test_function* \
76 : class_name##_maker_func() { return new class_name(); } \
77 : ma_test_function_maker \
78 : class_name##_maker_func_global_var(#func_name, class_name##_maker_func);
79 :
80 : #endif
|