artdaq_mfextensions  v1_05_00
ma_test_function.h
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 <vector>
14 #include <map>
15 #include <string>
16 
17 namespace novadaq {
18 namespace errorhandler {
19 
20 class ma_condition;
21 
22 typedef std::vector<boost::any> anys_t;
23 
25 {
26 public:
27 
28  ma_test_function( ) { }
29  virtual ~ma_test_function() { }
30 
31  // evaluation function
32  virtual boost::any
33  evaluate( ma_condition const & cond ) = 0;
34 
35  // parse aruments
36  virtual bool
37  parse_arguments( anys_t const & /*args*/ ) { return true; }
38 
39 };
40 
41 
42 typedef boost::function<ma_test_function * ( )> gen_test_t;
43 
44 
46 {
47  typedef std::map<std::string, gen_test_t> gen_map_t;
48 
49 public:
50 
51  static void
52  reg( std::string const & func_name, gen_test_t f );
53 
54  static ma_test_function *
55  create_instance( std::string const & func_name );
56 
57 private:
58 
60 
61  static gen_map_t &
62  get_map() { static gen_map_t map; return map; }
63 
64 };
65 
66 
68 {
69  ma_test_function_maker( std::string const & func_name, gen_test_t f )
70  { ma_test_function_factory::reg( func_name, f ); }
71 };
72 
73 
74 } // end of namespace errorhandler
75 } // end of namespace novadaq
76 
77 
78 #define REG_MA_TEST_FUNCTION(func_name, class_name) \
79 ma_test_function * \
80  class_name ## _maker_func( ) { return new class_name( ); } \
81 ma_test_function_maker \
82  class_name ## _maker_func_global_var ( #func_name, class_name ## _maker_func );
83 
84 
85 #endif
86 
87 
88 
89