Psyllid  v1.12.4
Project 8 Data Acquisisition Software
stream_preset.hh
Go to the documentation of this file.
1 /*
2  * stream_preset.hh
3  *
4  * Created on: Jan 27, 2016
5  * Author: nsoblath
6  */
7 
8 #ifndef PSYLLID_STREAM_PRESET_HH_
9 #define PSYLLID_STREAM_PRESET_HH_
10 
11 #include "factory.hh"
12 
13 #include <map>
14 #include <memory>
15 #include <set>
16 #include <string>
17 
18 namespace scarab
19 {
20  class param_node;
21 }
22 
23 namespace psyllid
24 {
25  class node_manager;
26 
28  {
29  public:
30  typedef std::map< std::string, std::string > nodes_t;
31  typedef std::set< std::string > connections_t;
32 
33  public:
34  stream_preset();
35  stream_preset( const std::string& a_type );
36  stream_preset( const stream_preset& a_orig );
37  virtual ~stream_preset();
38 
39  stream_preset& operator=( const stream_preset& a_rhs );
40 
41  const nodes_t& get_nodes() const;
42  const connections_t& get_connections() const;
43 
44  protected:
45  void node( const std::string& a_type, const std::string& a_name );
46  void connection( const std::string& a_conn );
47 
48  protected:
49  std::string f_type;
50  nodes_t f_nodes;
51  connections_t f_connections;
52  };
53 
54 
56  {
57  public:
59  runtime_stream_preset( const std::string& a_type );
61  virtual ~runtime_stream_preset();
62 
63  runtime_stream_preset& operator=( const runtime_stream_preset& a_rhs );
64 
65  public:
66  static bool add_preset( const scarab::param_node& a_preset_node );
67 
68  protected:
69  struct rsp_creator
70  {
71  std::shared_ptr< runtime_stream_preset > f_preset_ptr;
72  typedef scarab::registrar< stream_preset, runtime_stream_preset, const std::string& > registrar_t;
73  std::shared_ptr< registrar_t > f_registrar_ptr;
74  rsp_creator() : f_preset_ptr( new runtime_stream_preset() ), f_registrar_ptr( new registrar_t( "" ) ) {}
75  rsp_creator( const std::string& a_type ) : f_preset_ptr( new runtime_stream_preset( a_type ) ), f_registrar_ptr( new registrar_t( a_type ) ) {}
76  };
77  typedef std::map< std::string, rsp_creator> runtime_presets;
78  static runtime_presets s_runtime_presets;
79  static std::mutex s_runtime_presets_mutex;
80 
81  };
82 
83 
84 
85 
86  inline const stream_preset::nodes_t& stream_preset::get_nodes() const
87  {
88  return f_nodes;
89  }
90 
91  inline const stream_preset::connections_t& stream_preset::get_connections() const
92  {
93  return f_connections;
94  }
95 
96 
97 } /* namespace psyllid */
98 
99 
100 
101 #define DECLARE_PRESET( preset_class ) \
102  class preset_class : public stream_preset \
103  { \
104  public: \
105  preset_class( const std::string& a_type ); \
106  virtual ~preset_class() {}; \
107  };
108 
109 #define REGISTER_PRESET( preset_class, preset_type ) \
110  static ::scarab::registrar< ::psyllid::stream_preset, preset_class, const std::string& > s_stream_preset_##preset_class##_registrar( preset_type );
111 
112 
113 #endif /* CONTROL_STREAM_PRESET_HH_ */
std::shared_ptr< registrar_t > f_registrar_ptr
std::map< std::string, std::string > nodes_t
static runtime_presets s_runtime_presets
connections_t f_connections
scarab::registrar< stream_preset, runtime_stream_preset, const std::string &> registrar_t
std::shared_ptr< runtime_stream_preset > f_preset_ptr
std::map< std::string, rsp_creator > runtime_presets
rsp_creator(const std::string &a_type)
std::set< std::string > connections_t
static std::mutex s_runtime_presets_mutex