Loading...
Searching...
No Matches
user_interaction_callback.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2024 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_INTERACTION_CALLBACK_HPP
#define USER_INTERACTION_CALLBACK_HPP
#include "../my_config.h"
#include <string>
#include "user_interaction.hpp"
#include "secu_string.hpp"
namespace libdar
{
class user_interaction_callback : public user_interaction
{
public:
using message_callback = void (*)(const std::string &x, void *context);
using pause_callback = bool (*)(const std::string &x, void *context);
using get_string_callback = std::string (*)(const std::string &x, bool echo, void *context);
using get_secu_string_callback = secu_string (*)(const std::string &x, bool echo, void *context);
user_interaction_callback(message_callback x_message_callback,
pause_callback x_answer_callback,
get_string_callback x_string_callback,
get_secu_string_callback x_secu_string_callback,
void *context_value);
user_interaction_callback(const user_interaction_callback & ref) = default;
user_interaction_callback(user_interaction_callback && ref) noexcept = default;
user_interaction_callback & operator = (const user_interaction_callback & ref) = default;
user_interaction_callback & operator = (user_interaction_callback && ref) noexcept = default;
~user_interaction_callback() = default;
protected:
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;
void change_context_value(void *new_value) { context_val = new_value; };
private:
message_callback message_cb;
pause_callback pause_cb;
get_string_callback get_string_cb;
get_secu_string_callback get_secu_string_cb;
void *context_val;
};
} // end of namespace
#endif
libdar::secu_string
class secu_string
Definition secu_string.hpp:54
libdar::user_interaction_callback
full implemented class for user_interaction based on callback functions.
Definition user_interaction_callback.hpp:58
libdar::user_interaction_callback::inherited_get_secu_string
virtual secu_string inherited_get_secu_string(const std::string &message, bool echo) override
overwritting method from parent class.
libdar::user_interaction_callback::inherited_pause
virtual bool inherited_pause(const std::string &message) override
overwritting method from parent class.
libdar::user_interaction_callback::inherited_get_string
virtual std::string inherited_get_string(const std::string &message, bool echo) override
overwritting method from parent class.
libdar::user_interaction_callback::user_interaction_callback
user_interaction_callback(message_callback x_message_callback, pause_callback x_answer_callback, get_string_callback x_string_callback, get_secu_string_callback x_secu_string_callback, void *context_value)
constructor which receive the callback functions.
libdar::user_interaction_callback::inherited_message
virtual void inherited_message(const std::string &message) override
listing callback can be now passed directly to archive::get_children_of()
libdar::user_interaction_callback::change_context_value
void change_context_value(void *new_value)
change the context value of the object that will be given to callback functions
Definition user_interaction_callback.hpp:114
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
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47
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.