1 | // $Id: Option.cc 715 2006-12-22 08:42:39Z jari $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2006 Peter Johansson |
---|
5 | |
---|
6 | This file is part of the yat library, http://lev.thep.lu.se/trac/yat |
---|
7 | |
---|
8 | The yat library is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License as |
---|
10 | published by the Free Software Foundation; either version 2 of the |
---|
11 | License, or (at your option) any later version. |
---|
12 | |
---|
13 | The yat library is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
21 | 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | #include "Option.h" |
---|
25 | |
---|
26 | #include <fstream> |
---|
27 | #include <iostream> |
---|
28 | #include <string> |
---|
29 | |
---|
30 | namespace theplu { |
---|
31 | namespace yat { |
---|
32 | namespace utility { |
---|
33 | |
---|
34 | |
---|
35 | Option::Option(char short_name, std::string long_name, argument_type arg, |
---|
36 | std::string mess) |
---|
37 | : arg_type_(arg), long_name_(long_name), mess_(mess), |
---|
38 | short_name_(short_name), present_(false) |
---|
39 | { |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | Option::argument_type Option::arg_type(void) const |
---|
44 | { |
---|
45 | return arg_type_; |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | std::string Option::long_name(void) const |
---|
50 | { |
---|
51 | return long_name_; |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | std::string Option::name(void) const |
---|
56 | { |
---|
57 | return !long_name_.empty() ? long_name_ : std::string(&short_name_) ; |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | bool& Option::present(void) |
---|
62 | { |
---|
63 | return present_; |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | void Option::print(void) const |
---|
68 | { |
---|
69 | using std::cerr; |
---|
70 | if (short_name_!='\0'){ |
---|
71 | cerr << " -" << short_name_; |
---|
72 | if (!long_name_.empty()) |
---|
73 | cerr << ","; |
---|
74 | else |
---|
75 | cerr << " "; |
---|
76 | } |
---|
77 | else |
---|
78 | cerr << " "; |
---|
79 | if (!long_name_.empty()){ |
---|
80 | cerr << " --" << long_name_; |
---|
81 | if (arg_type_!=no_arg) |
---|
82 | cerr << "=VALUE"; |
---|
83 | } |
---|
84 | cerr << "\t" << mess_ << "\n"; |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | char Option::short_name(void) const |
---|
89 | { |
---|
90 | return short_name_; |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | std::string Option::value(void) |
---|
95 | { |
---|
96 | return value_; |
---|
97 | } |
---|
98 | |
---|
99 | }}} // of namespace utility, yat, and theplu |
---|