1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
// Copyright Contributors to the DNF5 project.
// Copyright Contributors to the libdnf project.
// SPDX-License-Identifier: LGPL-2.1-or-later
//
// This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
//
// Libdnf is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 2.1 of the License, or
// (at your option) any later version.
//
// Libdnf 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#ifndef LIBDNF5_COMMON_MESSAGE_HPP
#define LIBDNF5_COMMON_MESSAGE_HPP
#include "impl_ptr.hpp"
#include "libdnf5/defs.h"
#include "libdnf5/utils/locale.hpp"
#include <string>
namespace libdnf5 {
/// A base class for passing a message whose formatting, including localization
/// (translation, argument format) is done at the destination.
/// Usage: The user creates a child of this class and implements the `format` method.
class LIBDNF_API Message {
public:
Message();
Message(const Message & src);
Message(Message && src) noexcept;
virtual ~Message();
Message & operator=(const Message & src);
Message & operator=(Message && src) noexcept;
/// Formats the contained message according to the specified arguments and returns the result as a string.
///
/// @param translate If `true`, it will attempt to translate the message to the requested locale.
/// @param locale requested locale for translation and argument formating, nullptr = use global/thread locale
/// @return A string object holding the formatted result.
virtual std::string format(bool translate, const libdnf5::utils::Locale * locale = nullptr) const = 0;
private:
class LIBDNF_LOCAL Impl;
ImplPtr<Impl> p_impl;
};
/// Class for passing an empty message.
class LIBDNF_API EmptyMessage final : public Message {
public:
EmptyMessage();
EmptyMessage(const EmptyMessage & src);
EmptyMessage(EmptyMessage && src) noexcept;
~EmptyMessage() override;
EmptyMessage & operator=(const EmptyMessage & src);
EmptyMessage & operator=(EmptyMessage && src) noexcept;
/// Returns empty string
///
/// @param translate ignored
/// @param locale ignored
/// @return empty string object
std::string format(bool translate, const libdnf5::utils::Locale * locale = nullptr) const override;
};
} // namespace libdnf5
#endif // LIBDNF5_COMMON_MESSAGE_HPP
|