Bayeux  3.4.1
Core Foundation library for SuperNEMO
command_utils.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2014-09-25
4  * Last modified : 2016-06-23
5  *
6  * Copyright (C) 2014-2016 Francois Mauger <mauger@lpccaen.in2p3.fr>
7  *
8  * This program 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 (at
11  * your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  * Description:
24  *
25  * Command utilities.
26  *
27  */
28 
29 #ifndef DATATOOLS_COMMAND_UTILS_H
30 #define DATATOOLS_COMMAND_UTILS_H
31 
32 // Standard library:
33 #include <iostream>
34 
35 // This project:
36 #ifndef Q_MOC_RUN
38 #endif // Q_MOC_RUN
39 
40 namespace datatools {
41 
43  class command
44  {
45  public:
46 
49  // Special non-error values:
51  CEC_STOP = -2,
52  CEC_CONTINUE = -1,
53  // Sucess:
55  // Failures:
60  CEC_ABORT = 9,
75  };
76 
79  {
80  public:
81 
83  returned_info();
84 
86  returned_info(const std::string & output_);
87 
89  returned_info(error_code_type code_, const std::string & message_ = "");
90 
93 
95  void set_continue();
96 
98  void set_stop();
99 
101  void set_success(const std::string & output_ = "");
102 
104  void set_failure(error_code_type code_, const std::string & message_ = "");
105 
107  bool is_stop() const;
108 
110  bool is_continue() const;
111 
113  bool is_deprecated() const;
114 
116  bool is_special() const;
117 
119  bool is_success() const;
120 
122  bool is_failure() const;
123 
125  bool error_is(error_code_type code_) const;
126 
128  void set_error_code(error_code_type code_);
129 
132 
134  bool has_error_message() const;
135 
137  void set_error_message(const std::string & message_);
138 
140  const std::string& get_error_message() const;
141 
143  bool has_output() const;
144 
146  void set_output(const std::string & output_);
147 
149  const std::string& get_output() const;
150 
152  void reset();
153 
155  friend std::ostream & operator<<(std::ostream & out_, const returned_info & ri_);
156 
157  private:
158 
159  error_code_type _error_code_;
160  std::string _error_message_;
161  std::string _output_;
162 
163  DR_CLASS_RTTI()
164 
165  };
166 
167  DR_CLASS_RTTI()
168 
169  };
170 
171 } // end of namespace datatools
172 
173 #ifndef Q_MOC_RUN
174 // Activate reflection layer:
175 DR_TYPE_INIT(::datatools::command) // mandatory to access the embedded enum
178 #endif // Q_MOC_RUN
179 
180 #endif // DATATOOLS_COMMAND_UTILS_H
181 
182 // Local Variables: --
183 // mode: c++ --
184 // c-file-style: "gnu" --
185 // tab-width: 2 --
186 // End: --
bool error_is(error_code_type code_) const
Check if error code matches a given value.
error_code_type
Command error codes.
Definition: command_utils.h:48
Invalid command priviledge.
Definition: command_utils.h:63
Generic command utilities.
Definition: command_utils.h:43
const std::string & get_output() const
Get the output.
void set_success(const std::string &output_="")
Set success code and output.
friend std::ostream & operator<<(std::ostream &out_, const returned_info &ri_)
Print operator.
bool is_failure() const
Check failure.
bool is_deprecated() const
Check deprecation.
Stop without error (can be used to stop a loop or a pipeline)
Definition: command_utils.h:51
void set_continue()
Set continue code.
Invalid parameter error.
Definition: command_utils.h:67
void set_error_code(error_code_type code_)
Set the error code.
Deprecated context without error.
Definition: command_utils.h:50
Unset value.
Definition: command_utils.h:72
const std::string & get_error_message() const
Get the error message.
Command returned information.
Definition: command_utils.h:78
bool has_output() const
Check if an output is set.
Invalid parameter value.
Definition: command_utils.h:73
bool is_special() const
Check special case.
Invalid scope (wrong namespace or general context)
Definition: command_utils.h:61
Invalid command context.
Definition: command_utils.h:64
Invalid command (unrecognized command name)
Definition: command_utils.h:62
Generic parsing error.
Definition: command_utils.h:57
bool is_success() const
Check success.
error_code_type get_error_code() const
Return the error code.
Invalid parameter key.
Definition: command_utils.h:68
void set_output(const std::string &output_)
Set the output.
Invalid command number of arguments.
Definition: command_utils.h:66
Generic success.
Definition: command_utils.h:54
Generic failure.
Definition: command_utils.h:56
bool is_continue() const
Check continue.
Abort (can be used to abort a loop or a pipeline)
Definition: command_utils.h:60
Not implemented feature.
Definition: command_utils.h:59
Invalid parameter unit (for real numbers)
Definition: command_utils.h:74
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
returned_info()
Default constructor.
void set_failure(error_code_type code_, const std::string &message_="")
Set error code and message.
void set_stop()
Set stop code.
bool has_error_message() const
Check if an error message is set.
Continue without error (can be used to continue a loop or a pipeline)
Definition: command_utils.h:52
#define DR_TYPE_INIT(Introspectable)
Definition: reflection_interface.h:165
Invalid parameter context.
Definition: command_utils.h:70
Invalid parameter type.
Definition: command_utils.h:71
Invalid context.
Definition: command_utils.h:58
bool is_stop() const
Check stop.
#define DR_CLASS_RTTI()
Declare Camp RTTI within class declaration.
Definition: reflection_interface.h:46
Invalid parameter access mode.
Definition: command_utils.h:69
void set_error_message(const std::string &message_)
Set the error message.
Invalid command syntax.
Definition: command_utils.h:65