Bayeux  3.4.1
Core Foundation library for SuperNEMO
reflective_command_interface-inl.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2016-08-17
4  * Last modified : 2016-08-17
5  */
6 
7 #ifndef DATATOOLS_UI_REFLECTIVE_COMMAND_INTERFACE_INL_H
8 #define DATATOOLS_UI_REFLECTIVE_COMMAND_INTERFACE_INL_H
9 
10 // Standard library:
11 #include <typeinfo>
12 
13 // This project:
15 
16 namespace datatools {
17 
18  namespace ui {
19 
20  template <class Type>
22  : target_command_interface<Type>()
23  {
24  return;
25  }
26 
27  template <class Type>
29  const std::string & description_,
30  const version_id & vid_)
31  : target_command_interface<Type>(name_, description_, vid_)
32  {
33  return;
34  }
35 
36  template <class Type>
38  const std::string & name_,
39  const std::string & description_,
40  const version_id & vid_)
41  : target_command_interface<Type>(target_,
42  name_,
43  description_, vid_)
44  {
45  return;
46  }
47 
48  template <class Type>
50  {
53  }
54  return;
55  }
56 
57  template <class Type>
59  {
60  return _initialized_;
61  }
62 
63  template <class Type>
65  const datatools::service_manager & /* services_ */)
66  {
67  DT_THROW_IF(is_initialized(), std::logic_error,
68  "Command interface is already initialized!");
70  std::logic_error,
71  "Command interface has no target!");
73 
74  if (config_.has_key("disabled_commands")) {
75  std::vector<std::string> discoms;
76  config_.fetch("disabled_commands", discoms);
77  for (auto discom : discoms) {
78  add_disabled_command(discom);
79  }
80  }
81 
82  _add_commands();
83  _initialized_ = true;
84  return;
85  }
86 
87  template <class Type>
89  {
90  DT_THROW_IF(!is_initialized(), std::logic_error,
91  "Command interface is not initialized!");
92  _initialized_ = false;
93  //_remove_commands();
95  return;
96  }
97 
98  template <class Type>
100  {
101  _disabled_commands_.insert(name_);
102  return;
103  }
104 
105  template <class Type>
107  {
108  const camp::Class * metaclass = camp::classByTypeSafe<Type>();
109  DT_THROW_IF(metaclass == nullptr, std::logic_error,
110  "Class '" << typeid(Type).name() << "' has no reflection support!");
111 
112  for (std::size_t ifunc = 0; ifunc < metaclass->functionCount(); ifunc++) {
113  const camp::Function & func = metaclass->function(ifunc);
115  continue;
116  }
117  if (_disabled_commands_.count(func.name()) != 0) {
118  continue;
119  }
122  cmd->initialize_simple();
124  }
125 
126  return;
127  }
128 
129  template <class Type>
131  {
132  return;
133  }
134 
135  } // end of namespace ui
136 
137 } // end of namespace datatools
138 
139 #endif // DATATOOLS_UI_REFLECTIVE_COMMAND_INTERFACE_INL_H
140 
141 // Local Variables: --
142 // mode: c++ --
143 // c-file-style: "gnu" --
144 // tab-width: 2 --
145 // End: --
reflective_command_interface()
Default constructor.
Definition: reflective_command_interface-inl.h:21
void fetch(const std::string &key_, bool &value_, int index_=0) const
Fetch the boolean value stored with a given key/name and index.
virtual bool is_initialized() const
Check initialization status.
Definition: reflective_command_interface-inl.h:58
void add_disabled_command(const std::string &name_)
Add the name of a command to be disabled.
Definition: reflective_command_interface-inl.h:99
bool is_initialized()
Check if Bayeux library core functionnalities are initialized.
Base command interface for a target object.
Definition: target_command_interface.h:37
virtual void reset()
Reset.
Definition: reflective_command_interface-inl.h:88
bool has_key(const std::string &prop_key_) const
Check if a property with given key/name exists.
virtual void _remove_commands()
Remove commands.
Definition: reflective_command_interface-inl.h:130
virtual ~reflective_command_interface()
Destructor.
Definition: reflective_command_interface-inl.h:49
#define DT_THROW_IF(Condition, ExceptionType, Message)
Definition: exception.h:76
Reflective command.
base_command_interface & add_command(base_command &command_, const std::string &command_name_="")
Add an external command object.
virtual void _add_commands()
Add commands.
Definition: reflective_command_interface-inl.h:106
std::string function_builder_flag()
void _base_initialize(const datatools::properties &config_)
Base initialization.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
virtual void initialize(const datatools::properties &config_, const datatools::service_manager &services_)
Initialization.
Definition: reflective_command_interface-inl.h:64
Reflective command interface for a target object.
Definition: reflective_command_interface.h:42
void initialize_simple()
Initialize.
A class representing a version ID :
Definition: version_id.h:67
Service management class.
Definition: service_manager.h:57
Reflective command for a target object.
Definition: reflective_command.h:41
A dictionary of arbitrary properties.
Definition: properties.h:125