user_interaction5.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2023 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef USER_INTERACTION5_HPP
#define USER_INTERACTION5_HPP
#include "../my_config.h"
#include <string>
#include <memory>
#include "user_interaction.hpp"
#include "secu_string.hpp"
namespace libdar5
{
using libdar::secu_string;
using libdar::U_I;
using libdar::infinint;
using libdar::Euser_abort;
using libdar::Elibcall;
using libdar::Ebug;
using libdar::Egeneric;
using libdar::Ememory;
class user_interaction : public libdar::user_interaction
{
public:
user_interaction();
user_interaction(const user_interaction & ref) = default;
user_interaction(user_interaction && ref) noexcept = default;
user_interaction & operator = (const user_interaction & ref) = default;
user_interaction & operator = (user_interaction && ref) noexcept = default;
virtual ~user_interaction() = default;
void warning(const std::string & msg) { message(msg); };
virtual void pause(const std::string & message)
{
if(!pause2(message))
throw Euser_abort(message);
};
virtual bool pause2(const std::string & message)
{ throw Elibcall("user_interaction::pause2", "user_interaction::pause() or pause2() must be overwritten !"); };
virtual std::string get_string(const std::string & message, bool echo) = 0;
virtual secu_string get_secu_string(const std::string & message, bool echo) = 0;
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);
virtual void dar_manager_show_files(const std::string & filename,
bool data_change,
bool ea_change);
virtual void dar_manager_contents(U_I number,
const std::string & chemin,
const std::string & archive_name);
virtual void dar_manager_statistics(U_I number,
const infinint & data_count,
const infinint & total_data,
const infinint & ea_count,
const infinint & total_ea);
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);
bool get_use_listing() const { return use_listing; };
bool get_use_dar_manager_show_files() const { return use_dar_manager_show_files; };
bool get_use_dar_manager_contents() const { return use_dar_manager_contents; };
bool get_use_dar_manager_statistics() const { return use_dar_manager_statistics; };
bool get_use_dar_manager_show_version() const { return use_dar_manager_show_version; };
virtual void printf(const char *format, ...) override;
virtual user_interaction *clone() const = 0;
void warning_with_more(U_I num) { at_once = num; count = 0; };
protected:
void set_use_listing(bool val) { use_listing = val; };
void set_use_dar_manager_show_files(bool val) { use_dar_manager_show_files = val; };
void set_use_dar_manager_contents(bool val) { use_dar_manager_contents = val; };
void set_use_dar_manager_statistics(bool val) { use_dar_manager_statistics = val; };
void set_use_dar_manager_show_version(bool val) { use_dar_manager_show_version = val; };
// inherited from libdar::user_interaction
virtual void inherited_message(const std::string & message) override;
virtual bool inherited_pause(const std::string & message) override;
virtual std::string inherited_get_string(const std::string & message, bool echo) override;
virtual secu_string inherited_get_secu_string(const std::string & message, bool echo) override;
virtual void inherited_warning(const std::string & message) = 0;
private:
bool use_listing;
bool use_dar_manager_show_files;
bool use_dar_manager_contents;
bool use_dar_manager_statistics;
bool use_dar_manager_show_version;
U_I at_once, count;
};
extern std::shared_ptr<user_interaction> user_interaction5_clone_to_shared_ptr(user_interaction & dialog);
} // end of namespace
#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.