Bayeux  3.4.1
Core Foundation library for SuperNEMO
base_command_interface.h
Go to the documentation of this file.
1 //
4 // Copyright (c) 2015 by François Mauger <mauger@lpccaen.in2p3.fr>
5 //
6 // This file is part of datatools.
7 //
8 // datatools is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // datatools is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with datatools. If not, see <http://www.gnu.org/licenses/>.
20 
21 #ifndef DATATOOLS_UI_BASE_COMMAND_INTERFACE_H
22 #define DATATOOLS_UI_BASE_COMMAND_INTERFACE_H
23 
24 // Standard library:
25 #include <string>
26 #include <iostream>
27 #include <vector>
28 #include <memory>
29 
30 // Third Party:
31 // - Boost:
32 #include <boost/optional.hpp>
33 // - Bayeux/datatools:
35 #include <datatools/version_id.h>
38 #include <datatools/exception.h>
39 
40 namespace datatools {
41 
42  class properties;
43  class service_manager;
44 
45  namespace ui {
46 
47  class basic_shell;
48  class base_command;
49 
56  {
57  public:
58 
61 
63  base_command_interface(const std::string & name_,
64  const std::string & description_ = "",
65  const version_id & vid_ = version_id::invalid());
66 
68  virtual ~base_command_interface();
69 
71  bool has_version() const;
72 
74  void set_version(const datatools::version_id & version_);
75 
77  const datatools::version_id & get_version() const;
78 
80  std::size_t size() const;
81 
83  bool has_command(const std::string & command_name_) const;
84 
86  base_command & grab_command(const std::string & command_name_);
87 
89  const base_command & get_command(const std::string & command_name_) const;
90 
93  const std::string & command_name_ = "");
94 
98  const std::string & command_name_ = "");
99 
101  void remove_command(const std::string & command_name_);
102 
104  void remove_all_commands();
105 
107  void build_command_names(std::vector<std::string> & names_) const;
108 
110  void initialize_simple();
111 
114 
116  virtual bool is_initialized() const = 0;
117 
119  virtual void initialize(const datatools::properties & config_,
120  const datatools::service_manager & services_) = 0;
121 
123  virtual void reset() = 0;
124 
126  bool is_valid() const;
127 
129  bool is_disabled() const;
130 
132  virtual void tree_dump(std::ostream & out_ = std::clog,
133  const std::string & title_ = "",
134  const std::string & indent_ = "",
135  bool inherit_ = false) const;
136 
138  int operator()(const std::vector<std::string> & argv_,
140  uint32_t flags_ = 0);
141 
144  operator()(const std::vector<std::string> & argv_,
145  uint32_t flags_ = 0);
146 
148  void call(const std::vector<std::string> & argv_,
150  uint32_t flags_ = 0);
151 
152  protected:
153 
155  void _base_setup(const std::string & name_,
156  const std::string & description_,
157  const version_id & vid_);
158 
160  void _set_version(const datatools::version_id &);
161 
163  void _base_initialize(const datatools::properties & config_);
164 
166  void _base_reset();
167 
169  virtual bool _is_valid() const;
170 
172  virtual bool _is_disabled() const;
173 
174 
175  private:
176 
177  // Configuration:
178  boost::optional<datatools::version_id> _version_;
179 
180  // Private data:
181 
182  struct pimpl_type;
183  pimpl_type & _grab_pimpl();
184  const pimpl_type & _get_pimpl() const;
185  std::unique_ptr<pimpl_type> _pimpl_;
186 
187  // Factory stuff :
189 
190  };
191 
192  } // namespace ui
193 
194 } // namespace datatools
195 
196 #endif // DATATOOLS_UI_BASE_COMMAND_INTERFACE_H
197 
198 // Local Variables: --
199 // mode: c++ --
200 // c-file-style: "gnu" --
201 // tab-width: 2 --
202 // End: --
bool has_command(const std::string &command_name_) const
Check if a command with given name exists.
void _set_version(const datatools::version_id &)
Set the version.
virtual bool _is_valid() const
Check the validity (this can be overloaded)
void call(const std::vector< std::string > &argv_, datatools::command::returned_info &cri_, uint32_t flags_=0)
Call method.
bool is_valid() const
Check if the command interface is valid.
bool is_disabled() const
Check if the command interface is disabled.
base_command_interface()
Default constructor.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
std::size_t size() const
Return the number of commands.
static const version_id & invalid()
Return an invalid version identifier.
Utility macros for exception handling.
Command returned information.
Definition: command_utils.h:78
int operator()(const std::vector< std::string > &argv_, datatools::command::returned_info &cri_, uint32_t flags_=0)
Main command call operator.
void set_version(const datatools::version_id &version_)
Set the version.
void build_command_names(std::vector< std::string > &names_) const
Build the list of command names.
virtual bool _is_disabled() const
Check the active status (default: true, this can be overloaded)
Base command.
Definition: base_command.h:48
Command interface for arbitrary objects.
Definition: base_command_interface.h:54
void initialize_simple()
Initialize the parser.
base_command_interface & add_command(base_command &command_, const std::string &command_name_="")
Add an external command object.
base_command & grab_command(const std::string &command_name_)
Return a reference to a mutable command.
void remove_all_commands()
Remove all commands.
void _base_initialize(const datatools::properties &config_)
Base initialization.
const base_command & get_command(const std::string &command_name_) const
Return a reference to a command.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
virtual ~base_command_interface()
Destructor.
A base class with useful attributes usable in many contexts.
Definition: enriched_base.h:52
void _base_setup(const std::string &name_, const std::string &description_, const version_id &vid_)
Basic setup.
virtual void initialize(const datatools::properties &config_, const datatools::service_manager &services_)=0
Initialize the parser using a list of properties with access to a service manager.
#define DATATOOLS_FACTORY_SYSTEM_REGISTER_INTERFACE(BaseType)
Declaration of a system (allocator/functor) factory register as a static member of a base class and s...
Definition: factory_macros.h:52
virtual bool is_initialized() const =0
Check if the parser is initialized.
void remove_command(const std::string &command_name_)
Remove a command.
void initialize_standalone(const datatools::properties &)
Initialize the parser using only a list of properties.
A class representing a version ID :
Definition: version_id.h:67
bool has_version() const
Check if the version is set.
Service management class.
Definition: service_manager.h:57
A dictionary of arbitrary properties.
Definition: properties.h:125
const datatools::version_id & get_version() const
Return the version.