| Disk ARchive 2.7.12 Full featured and portable backup and archiving tool

user_interaction5.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2023 Denis Corbin
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 2
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18//
19// to contact the author, see the AUTHOR file
20/*********************************************************************/
21
25
26#ifndef USER_INTERACTION5_HPP
27#define USER_INTERACTION5_HPP
28
29#include "../my_config.h"
30
31#include <string>
32#include <memory>
33#include "user_interaction.hpp"
34#include "secu_string.hpp"
35
36 namespace libdar5
37{
38
41
42 using libdar::secu_string;
43 using libdar::U_I;
44 using libdar::infinint;
45 using libdar::Euser_abort;
46 using libdar::Elibcall;
47
48 using libdar::Ebug;
49 using libdar::Egeneric;
50 using libdar::Ememory;
51
53
87 class user_interaction : public libdar::user_interaction
88 {
89 public:
90
92 user_interaction();
93 user_interaction(const user_interaction & ref) = default;
94 user_interaction(user_interaction && ref) noexcept = default;
95 user_interaction & operator = (const user_interaction & ref) = default;
96 user_interaction & operator = (user_interaction && ref) noexcept = default;
97 virtual ~user_interaction() = default;
98
100
106 void warning(const std::string & msg) { message(msg); };
107
109
113 virtual void pause(const std::string & message)
114 {
115 if(!pause2(message))
116 throw Euser_abort(message);
117 };
118
120
127 virtual bool pause2(const std::string & message)
128 { throw Elibcall("user_interaction::pause2", "user_interaction::pause() or pause2() must be overwritten !"); };
129
131
135 virtual std::string get_string(const std::string & message, bool echo) = 0;
136
138
142 virtual secu_string get_secu_string(const std::string & message, bool echo) = 0;
143
144
151
163 virtual void listing(const std::string & flag,
164 const std::string & perm,
165 const std::string & uid,
166 const std::string & gid,
167 const std::string & size,
168 const std::string & date,
169 const std::string & filename,
170 bool is_dir,
171 bool has_children);
172
173
174
181
186 virtual void dar_manager_show_files(const std::string & filename,
187 bool data_change,
188 bool ea_change);
189
190
197
202 virtual void dar_manager_contents(U_I number,
203 const std::string & chemin,
204 const std::string & archive_name);
205
212
219 virtual void dar_manager_statistics(U_I number,
220 const infinint & data_count,
221 const infinint & total_data,
222 const infinint & ea_count,
223 const infinint & total_ea);
224
231
238 virtual void dar_manager_show_version(U_I number,
239 const std::string & data_date,
240 const std::string & data_presence,
241 const std::string & ea_date,
242 const std::string & ea_presence);
243
247
249 bool get_use_listing() const { return use_listing; };
251 bool get_use_dar_manager_show_files() const { return use_dar_manager_show_files; };
253 bool get_use_dar_manager_contents() const { return use_dar_manager_contents; };
255 bool get_use_dar_manager_statistics() const { return use_dar_manager_statistics; };
257 bool get_use_dar_manager_show_version() const { return use_dar_manager_show_version; };
258
259 virtual void printf(const char *format, ...) override;
260
262
268 virtual user_interaction *clone() const = 0;
269
271
276 void warning_with_more(U_I num) { at_once = num; count = 0; };
277
278 protected:
279
281
286 void set_use_listing(bool val) { use_listing = val; };
287
289 void set_use_dar_manager_show_files(bool val) { use_dar_manager_show_files = val; };
290
292 void set_use_dar_manager_contents(bool val) { use_dar_manager_contents = val; };
293
295 void set_use_dar_manager_statistics(bool val) { use_dar_manager_statistics = val; };
296
298 void set_use_dar_manager_show_version(bool val) { use_dar_manager_show_version = val; };
299
301
302 // inherited from libdar::user_interaction
303 virtual void inherited_message(const std::string & message) override;
304 virtual bool inherited_pause(const std::string & message) override;
305 virtual std::string inherited_get_string(const std::string & message, bool echo) override;
306 virtual secu_string inherited_get_secu_string(const std::string & message, bool echo) override;
307
309 virtual void inherited_warning(const std::string & message) = 0;
310
311
312 private:
313 bool use_listing;
314 bool use_dar_manager_show_files;
315 bool use_dar_manager_contents;
316 bool use_dar_manager_statistics;
317 bool use_dar_manager_show_version;
318 U_I at_once, count;
319
320 };
321
323
324 extern std::shared_ptr<user_interaction> user_interaction5_clone_to_shared_ptr(user_interaction & dialog);
325
327
328} // end of namespace
329
330#endif
libdar5::user_interaction
This is a pure virtual class that is used by libdar when interaction with the user is required.
Definition: user_interaction5.hpp:88
libdar5::user_interaction::dar_manager_show_files
virtual void dar_manager_show_files(const std::string &filename, bool data_change, bool ea_change)
libdar5::user_interaction::get_secu_string
virtual secu_string get_secu_string(const std::string &message, bool echo)=0
same a get_string() but uses secu_string instead
libdar5::user_interaction::inherited_warning
virtual void inherited_warning(const std::string &message)=0
to be defined by inherited classes
libdar5::user_interaction::inherited_message
virtual void inherited_message(const std::string &message) override
need to be overwritten in place of the warning() method since API 3.1.x
libdar5::user_interaction::user_interaction
user_interaction()
class constructor.
libdar5::user_interaction::inherited_get_secu_string
virtual secu_string inherited_get_secu_string(const std::string &message, bool echo) override
same a get_string() but uses libdar::secu_string instead of std::string
libdar5::user_interaction::dar_manager_statistics
virtual void dar_manager_statistics(U_I number, const infinint &data_count, const infinint &total_data, const infinint &ea_count, const infinint &total_ea)
libdar5::user_interaction::get_use_dar_manager_contents
bool get_use_dar_manager_contents() const
this is not a virtual method, it has not to be overwritten in inherited classes.
Definition: user_interaction5.hpp:253
libdar5::user_interaction::set_use_dar_manager_contents
void set_use_dar_manager_contents(bool val)
method to be called with true as argument if you have defined a dar_manager_contents() method.
Definition: user_interaction5.hpp:292
libdar5::user_interaction::set_use_dar_manager_show_version
void set_use_dar_manager_show_version(bool val)
method to be called with true as argument if you have defined a dar_manager_show_version() method.
Definition: user_interaction5.hpp:298
libdar5::user_interaction::warning_with_more
void warning_with_more(U_I num)
make a pause each N line of output when calling the warning method
Definition: user_interaction5.hpp:276
libdar5::user_interaction::pause2
virtual bool pause2(const std::string &message)
alternative method to the pause() method
Definition: user_interaction5.hpp:127
libdar5::user_interaction::clone
virtual user_interaction * clone() const =0
make a newly allocated object which has the same properties as "this".
libdar5::user_interaction::listing
virtual void listing(const std::string &flag, const std::string &perm, const std::string &uid, const std::string &gid, const std::string &size, const std::string &date, const std::string &filename, bool is_dir, bool has_children)
libdar5::user_interaction::get_use_listing
bool get_use_listing() const
this is not a virtual method, it has not to be overwritten in inherited classes.
Definition: user_interaction5.hpp:249
libdar5::user_interaction::inherited_pause
virtual bool inherited_pause(const std::string &message) override
method used to ask a boolean question to the user.
libdar5::user_interaction::pause
virtual void pause(const std::string &message)
method used to ask a boolean question to the user.
Definition: user_interaction5.hpp:113
libdar5::user_interaction::inherited_get_string
virtual std::string inherited_get_string(const std::string &message, bool echo) override
method used to ask a question that needs an arbitrary answer.
libdar5::user_interaction::dar_manager_show_version
virtual void dar_manager_show_version(U_I number, const std::string &data_date, const std::string &data_presence, const std::string &ea_date, const std::string &ea_presence)
libdar5::user_interaction::get_use_dar_manager_statistics
bool get_use_dar_manager_statistics() const
this is not a virtual method, it has not to be overwritten in inherited classes.
Definition: user_interaction5.hpp:255
libdar5::user_interaction::dar_manager_contents
virtual void dar_manager_contents(U_I number, const std::string &chemin, const std::string &archive_name)
libdar5::user_interaction::set_use_listing
void set_use_listing(bool val)
method to be called with true as argument if you have defined a listing() method.
Definition: user_interaction5.hpp:286
libdar5::user_interaction::get_use_dar_manager_show_files
bool get_use_dar_manager_show_files() const
this is not a virtual method, it has not to be overwritten in inherited classes.
Definition: user_interaction5.hpp:251
libdar5::user_interaction::get_string
virtual std::string get_string(const std::string &message, bool echo)=0
method used to ask a question that needs an arbitrary answer.
libdar5::user_interaction::get_use_dar_manager_show_version
bool get_use_dar_manager_show_version() const
this is not a virtual method, it has not to be overwritten in inherited classes.
Definition: user_interaction5.hpp:257
libdar5::user_interaction::warning
void warning(const std::string &msg)
method added for backward compatibility with API v5
Definition: user_interaction5.hpp:106
libdar5::user_interaction::printf
virtual void printf(const char *format,...) override
libdar uses this call to format output before send to message() method.
libdar5::user_interaction::set_use_dar_manager_show_files
void set_use_dar_manager_show_files(bool val)
method to be called with true as argument if you have defined a dar_manager_show_files() method.
Definition: user_interaction5.hpp:289
libdar5::user_interaction::set_use_dar_manager_statistics
void set_use_dar_manager_statistics(bool val)
method to be called with true as argument if you have defined a dar_manager_statistics() method.
Definition: user_interaction5.hpp:295
libdar::Ebug
exception used to signal a bug. A bug is triggered when reaching some code that should never be reach...
Definition: erreurs.hpp:163
libdar::Egeneric
this is the parent class of all exception classes.
Definition: erreurs.hpp:52
libdar::Elibcall
exception used to signal an error in the argument given to libdar call of the API
Definition: erreurs.hpp:348
libdar::Ememory
exception used when memory has been exhausted
Definition: erreurs.hpp:127
libdar::Euser_abort
exception used to signal that the user has aborted the operation
Definition: erreurs.hpp:293
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:62
libdar::secu_string
class secu_string
Definition: secu_string.hpp:54
libdar::user_interaction
This is a pure virtual class that is used by libdar when interaction with the user is required.
Definition: user_interaction.hpp:47
libdar5::user_interaction5_clone_to_shared_ptr
std::shared_ptr< user_interaction > user_interaction5_clone_to_shared_ptr(user_interaction &dialog)
convert a user_interaction to a shared_pointer on a clone of that user_interaction
libdar5
libdar5 namespace encapsulate all libdar symbols
Definition: archive5.hpp:37
secu_string.hpp
this file contains the definition of secu_string class, a std::string like class but allocated in sec...
user_interaction.hpp
defines the interaction interface between libdar and users.