1 /* 2 * Copyright 2003-2021 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 23 #include <cassert> 24 25 /** 26 * Command line option definition. 27 */ 28 class OptionDef 29 { 30 const char *long_option; 31 char short_option; 32 bool has_value = false; 33 const char *desc; 34 public: OptionDef(const char * _long_option,const char * _desc)35 constexpr OptionDef(const char *_long_option, const char *_desc) 36 : long_option(_long_option), 37 short_option(0), 38 desc(_desc) { } 39 OptionDef(const char * _long_option,char _short_option,const char * _desc)40 constexpr OptionDef(const char *_long_option, 41 char _short_option, const char *_desc) 42 : long_option(_long_option), 43 short_option(_short_option), 44 desc(_desc) { } 45 OptionDef(const char * _long_option,char _short_option,bool _has_value,const char * _desc)46 constexpr OptionDef(const char *_long_option, 47 char _short_option, bool _has_value, 48 const char *_desc) noexcept 49 :long_option(_long_option), 50 short_option(_short_option), 51 has_value(_has_value), 52 desc(_desc) {} 53 HasLongOption() const54 constexpr bool HasLongOption() const { return long_option != nullptr; } HasShortOption() const55 constexpr bool HasShortOption() const { return short_option != 0; } 56 HasValue() const57 constexpr bool HasValue() const noexcept { 58 return has_value; 59 } 60 HasDescription() const61 constexpr bool HasDescription() const { return desc != nullptr; } 62 GetLongOption() const63 const char *GetLongOption() const { 64 assert(HasLongOption()); 65 return long_option; 66 } 67 GetShortOption() const68 char GetShortOption() const { 69 assert(HasShortOption()); 70 return short_option; 71 } 72 GetDescription() const73 const char *GetDescription() const { 74 assert(HasDescription()); 75 return desc; 76 } 77 }; 78 79 #endif 80