1 /*
2 * Copyright (C) 2018 Red Hat, Inc.
3 *
4 * Licensed under the GNU Lesser General Public License Version 2.1
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _LIBDNF_OPTION_HPP
22 #define _LIBDNF_OPTION_HPP
23
24 #ifdef LIBDNF_UNSTABLE_API
25
26 #include <stdexcept>
27 #include <string>
28
29 namespace libdnf {
30
31 class Option {
32 public:
33 enum class Priority {
34 EMPTY = 0,
35 DEFAULT = 10,
36 MAINCONFIG = 20,
37 AUTOMATICCONFIG = 30,
38 REPOCONFIG = 40,
39 PLUGINDEFAULT = 50,
40 PLUGINCONFIG = 60,
41 DROPINCONFIG = 65,
42 COMMANDLINE = 70,
43 RUNTIME = 80
44 };
45
46 struct Exception : public std::runtime_error {
Exceptionlibdnf::Option::Exception47 Exception(const std::string & msg) : runtime_error(msg) {}
Exceptionlibdnf::Option::Exception48 Exception(const char * msg) : runtime_error(msg) {}
49 };
50 struct InvalidValue : Exception {
InvalidValuelibdnf::Option::InvalidValue51 InvalidValue(const std::string & msg) : Exception(msg) {}
InvalidValuelibdnf::Option::InvalidValue52 InvalidValue(const char * msg) : Exception(msg) {}
53 };
54 struct ValueNotSet : Exception {
ValueNotSetlibdnf::Option::ValueNotSet55 ValueNotSet(const std::string & msg) : Exception(msg) {}
ValueNotSetlibdnf::Option::ValueNotSet56 ValueNotSet(const char * msg) : Exception(msg) {}
57 };
58
59 Option(Priority priority = Priority::EMPTY);
60 virtual Option * clone() const = 0;
61 virtual Priority getPriority() const;
62 virtual void set(Priority priority, const std::string & value) = 0;
63 virtual std::string getValueString() const = 0;
64 virtual bool empty() const noexcept;
65 /// Resets the option to its initial state.
66 virtual void reset() = 0;
67 virtual ~Option() = default;
68
69 protected:
70 Priority priority;
71 };
72
Option(Priority priority)73 inline Option::Option(Priority priority)
74 : priority(priority) {}
75
getPriority() const76 inline Option::Priority Option::getPriority() const
77 {
78 return priority;
79 }
80
empty() const81 inline bool Option::empty() const noexcept
82 {
83 return priority == Priority::EMPTY;
84 }
85
86 }
87
88 #endif
89
90 #endif
91