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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/* Copyright (C) 2004 The glibmm Development Team
*
* This library 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.
*
* This library 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 this library. If not, see <http://www.gnu.org/licenses/>.
*/
_DEFS(glibmm,glib)
#include <glibmm/ustring.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { typedef struct _GOptionEntry GOptionEntry; }
#endif
namespace Glib
{
/** An OptionEntry defines a single option. To have an effect, it must be added to an OptionGroup with
* OptionGroup::add_entry().
*
* The long name of an option can be used to specify it in a commandline as --long_name.
* Every option must have a long name. To resolve conflicts if multiple option groups contain the same long name, it is also
* possible to specify the option as --groupname-long_name.
*
* If an option has a short name, it can be specified as -short_name in a commandline.
*
* The description for the option is shown in the --help output.
*
* The arg_descripton is the placeholder to use for the extra argument parsed by the option in --help output.
*/
class GLIBMM_API OptionEntry
{
_CLASS_GENERIC(OptionEntry, GOptionEntry)
public:
_WRAP_ENUM(Flags, GOptionFlags, NO_GTYPE, decl_prefix GLIBMM_API)
OptionEntry();
OptionEntry(const OptionEntry& src);
OptionEntry(OptionEntry&& other) noexcept;
OptionEntry& operator=(OptionEntry&& other) noexcept;
virtual ~OptionEntry();
OptionEntry& operator=(const OptionEntry& src);
// We do not use nullptr for an empty string in set_long_name(),
// because G_OPTION_REMAINING is actually a "", so it has a distinct meaning.
// TODO: Wrap G_OPTION_REMAINING in C++ somehow, maybe as an overloaded
// set_long_name(void) or set_is_remaining()? murrayc.
#m4 _CONVERSION(`Glib::ustring',`const char*',`($3).c_str()')
_MEMBER_GET(long_name, long_name, Glib::ustring, const char*)
_MEMBER_SET_STR(long_name, long_name, Glib::ustring, const char*)
_MEMBER_GET(short_name, short_name, gchar, gchar)
_MEMBER_SET(short_name, short_name, gchar, gchar)
#m4 _CONVERSION(`int',`Flags',`static_cast<Flags>($3)')
_MEMBER_GET(flags, flags, Flags, int)
#m4 _CONVERSION(`Flags',`int',`static_cast<int>($3)')
/** Set one or more OptionEntry::Flags.
* Do not set Flags::FILENAME. Character encoding is chosen when the OptionEntry
* is added to an OptionGroup.
*/
_MEMBER_SET(flags, flags, Flags, int)
// We use nullptr for an empty string in set_description() and set_arg_description().
#m4 _CONVERSION(`Glib::ustring',`const char*',`Glib::c_str_or_nullptr($3)')
_MEMBER_GET(description, description, Glib::ustring, const char*)
_MEMBER_SET_STR(description, description, Glib::ustring, const char*)
_MEMBER_GET(arg_description, arg_description, Glib::ustring, const char*)
_MEMBER_SET_STR(arg_description, arg_description, Glib::ustring, const char*)
GOptionEntry* gobj() { return gobject_; }
const GOptionEntry* gobj() const { return gobject_; }
private:
void release_gobject() noexcept;
protected:
GOptionEntry* gobject_;
};
} // namespace Glib
|