E-MailRelay

goption.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2024 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file goption.h
19///
20
21#ifndef G_OPTION_H
22#define G_OPTION_H
23
24#include "gdef.h"
25#include "gstringarray.h"
26#include <string>
27#include <utility>
28
29 namespace G
30{
31 struct Option ;
32}
33
34//| \class G::Option
35/// A structure representing a G::Options command-line option.
36///
37 struct G::Option
38{
39 enum class Multiplicity { zero , zero_or_one , one , many , error } ;
40 char c ;
41 std::string name ;
42 std::string description ;
43 std::string description_extra ;
44 Multiplicity value_multiplicity ;
45 bool hidden ;
46 std::string value_description ;
47 unsigned int level ;
48 unsigned int main_tag ; // principal category
49 unsigned int tag_bits ; // all categories
50
51 Option( char c , const std::string & name , const std::string & description ,
52 const std::string & description_extra , Multiplicity value_multiplicity ,
53 const std::string & vd , unsigned int level ) ;
54 ///< Constructor taking strings.
55
56 Option( char c , const char * name , const char * description ,
57 const char * description_extra , Multiplicity value_multiplicity ,
58 const char * vd , unsigned int level ,
59 unsigned int main_tag , unsigned int tag_bits ) ;
60 ///< Constructor taking c-strings and tags.
61
62 static Multiplicity decode( const std::string & ) ;
63 ///< Decodes a multiplicity string into its enumeration.
64 ///< Returns 'error' on error.
65
66 bool valued() const ;
67 bool defaulting() const ;
68 bool multivalued() const ;
69 bool visible() const ;
70 bool visible( std::pair<unsigned,unsigned> level_range , unsigned int main_tag = 0U , unsigned int tag_bits = 0U ) const ;
71} ;
72
73 inline bool G::Option::valued() const { return value_multiplicity != Multiplicity::zero ; }
74 inline bool G::Option::defaulting() const { return value_multiplicity == Option::Multiplicity::zero_or_one ; }
75 inline bool G::Option::multivalued() const { return value_multiplicity == Option::Multiplicity::many ; }
76 inline bool G::Option::visible() const { return visible( {1U,99U} ) ; }
77 inline bool G::Option::visible( std::pair<unsigned,unsigned> level_range , unsigned int main_tag_in , unsigned int tag_bits_in ) const
78{
79 return
80 !hidden &&
81 level >= level_range.first &&
82 level <= level_range.second &&
83 ( main_tag_in == 0U || main_tag_in == main_tag ) &&
84 ( tag_bits_in == 0U || ( tag_bits_in & tag_bits ) != 0U ) ;
85}
86
87#endif
gstringarray.h
G
Low-level classes.
Definition: garg.h:36
G::Option
A structure representing a G::Options command-line option.
Definition: goption.h:38
G::Option::Option
Option(char c, const std::string &name, const std::string &description, const std::string &description_extra, Multiplicity value_multiplicity, const std::string &vd, unsigned int level)
Constructor taking strings.
Definition: goption.cpp:24
G::Option::decode
static Multiplicity decode(const std::string &)
Decodes a multiplicity string into its enumeration.
Definition: goption.cpp:57