MPD  0.20.6
OptionDef.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2003-2017 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef MPD_UTIL_OPTIONDEF_HXX
21 #define MPD_UTIL_OPTIONDEF_HXX
22 
26 class OptionDef
27 {
28  const char *long_option;
29  char short_option;
30  const char *desc;
31 public:
32  constexpr OptionDef(const char *_long_option, const char *_desc)
33  : long_option(_long_option),
34  short_option(0),
35  desc(_desc) { }
36 
37  constexpr OptionDef(const char *_long_option,
38  char _short_option, const char *_desc)
39  : long_option(_long_option),
40  short_option(_short_option),
41  desc(_desc) { }
42 
43  bool HasLongOption() const { return long_option != nullptr; }
44  bool HasShortOption() const { return short_option != 0; }
45  bool HasDescription() const { return desc != nullptr; }
46 
47  const char *GetLongOption() const {
48  assert(HasLongOption());
49  return long_option;
50  }
51 
52  char GetShortOption() const {
53  assert(HasShortOption());
54  return short_option;
55  }
56 
57  const char *GetDescription() const {
58  assert(HasDescription());
59  return desc;
60  }
61 };
62 
63 #endif
bool HasShortOption() const
Definition: OptionDef.hxx:44
Command line option definition.
Definition: OptionDef.hxx:26
constexpr OptionDef(const char *_long_option, const char *_desc)
Definition: OptionDef.hxx:32
constexpr OptionDef(const char *_long_option, char _short_option, const char *_desc)
Definition: OptionDef.hxx:37
char GetShortOption() const
Definition: OptionDef.hxx:52
bool HasDescription() const
Definition: OptionDef.hxx:45
const char * GetLongOption() const
Definition: OptionDef.hxx:47
bool HasLongOption() const
Definition: OptionDef.hxx:43
const char * GetDescription() const
Definition: OptionDef.hxx:57