1 | #ifndef _theplu_yat_utility_option_ |
---|
2 | #define _theplu_yat_utility_option_ |
---|
3 | |
---|
4 | // $Id: Option.h 680 2006-10-11 17:49:03Z jari $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2006 Peter Johansson, Jari Hakkinen |
---|
8 | |
---|
9 | This file is part of the yat library, http://lev.thep.lu.se/trac/yat |
---|
10 | |
---|
11 | The yat library is free software; you can redistribute it and/or |
---|
12 | modify it under the terms of the GNU General Public License as |
---|
13 | published by the Free Software Foundation; either version 2 of the |
---|
14 | License, or (at your option) any later version. |
---|
15 | |
---|
16 | The yat library is distributed in the hope that it will be useful, |
---|
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
19 | General Public License for more details. |
---|
20 | |
---|
21 | You should have received a copy of the GNU General Public License |
---|
22 | along with this program; if not, write to the Free Software |
---|
23 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
24 | 02111-1307, USA. |
---|
25 | */ |
---|
26 | |
---|
27 | #include <string> |
---|
28 | |
---|
29 | namespace theplu { |
---|
30 | namespace yat { |
---|
31 | namespace utility { |
---|
32 | |
---|
33 | /// |
---|
34 | /// @brief Container of variables for an option. @see CommandLine |
---|
35 | /// |
---|
36 | class Option |
---|
37 | { |
---|
38 | public: |
---|
39 | |
---|
40 | /// |
---|
41 | /// different types of arguments to an option |
---|
42 | /// |
---|
43 | enum argument_type { |
---|
44 | no_arg, string_arg, int_arg, double_arg |
---|
45 | }; |
---|
46 | |
---|
47 | |
---|
48 | /// |
---|
49 | /// @brief Constructor |
---|
50 | /// |
---|
51 | /// @param short_name one character key such as 'h' for -h flag |
---|
52 | /// @param long_name string key such as "help" for --help flag |
---|
53 | /// @param arg telling what kind argument this option expects |
---|
54 | /// @param desc string used in help display |
---|
55 | /// |
---|
56 | Option(char short_name, std::string long_name, |
---|
57 | argument_type arg, std::string desc); |
---|
58 | |
---|
59 | |
---|
60 | /// |
---|
61 | /// @return argument type for option |
---|
62 | /// |
---|
63 | inline const argument_type& arg_type(void) const { return arg_type_; } |
---|
64 | |
---|
65 | /// |
---|
66 | /// @return long name unless long name is empty in which case the |
---|
67 | /// short one character name is returned. |
---|
68 | /// |
---|
69 | inline std::string name(void) const |
---|
70 | { return !long_name_.empty() ? long_name_ : std::string(&short_name_) ; } |
---|
71 | |
---|
72 | /// |
---|
73 | /// @return short name |
---|
74 | /// |
---|
75 | inline char short_name(void) const { return short_name_; } |
---|
76 | |
---|
77 | /// |
---|
78 | /// @return long name |
---|
79 | /// |
---|
80 | inline const std::string& long_name(void) const { return long_name_; } |
---|
81 | |
---|
82 | /// |
---|
83 | /// sends output to std::cerr of type |
---|
84 | /// |
---|
85 | /// -v, --verbose explain what is going on |
---|
86 | /// |
---|
87 | void print(void) const; |
---|
88 | |
---|
89 | /// |
---|
90 | /// @return true if option has been detected in parsing |
---|
91 | /// |
---|
92 | inline bool& present(void) { return present_; } |
---|
93 | |
---|
94 | /// |
---|
95 | /// @return argument value |
---|
96 | /// |
---|
97 | inline std::string& value(void) { return value_; } |
---|
98 | |
---|
99 | |
---|
100 | private: |
---|
101 | argument_type arg_type_; |
---|
102 | std::string long_name_; |
---|
103 | std::string mess_; |
---|
104 | char short_name_; |
---|
105 | bool present_; |
---|
106 | std::string value_; |
---|
107 | }; |
---|
108 | |
---|
109 | }}} // of namespace utility, yat and theplu |
---|
110 | |
---|
111 | #endif |
---|