source: trunk/yat/utility/Option.h @ 743

Last change on this file since 743 was 743, checked in by Peter, 15 years ago

Changed function to return reference to member variable string. This is needed because function is used to change the member variable in CommandLine?. We should add a test to avoid changes like the previous one that introduced a severe and nasty bug in CommandLine?.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1#ifndef _theplu_yat_utility_option_
2#define _theplu_yat_utility_option_
3
4// $Id: Option.h 743 2007-01-15 14:12:31Z peter $
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
29namespace theplu {
30namespace yat {
31namespace 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    /// @return argument type for option
61    ///
62    argument_type arg_type(void) const;
63   
64    ///
65    /// @return long name
66    ///
67    std::string long_name(void) const;
68
69    ///
70    /// @return long name unless long name is empty in which case the
71    /// short one character name is returned.
72    ///
73    std::string name(void) const;
74
75    ///
76    /// @brief Get or set the present status.
77    ///
78    /// @return true if option has been detected in parsing
79    ///
80    bool& present(void);
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 short name
91    ///
92    char short_name(void) const;
93
94    ///
95    /// @return reference to argument value
96    ///
97    std::string& value(void);
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
Note: See TracBrowser for help on using the repository browser.