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

Last change on this file since 1268 was 1268, checked in by Peter, 13 years ago

fixing some doxygen warnings - and let make distcheck work again

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1#ifndef _theplu_yat_utility_option_
2#define _theplu_yat_utility_option_
3
4// $Id: Option.h 1268 2008-04-09 14:13:49Z peter $
5
6/*
7  Copyright (C) 2007 Peter Johansson
8
9  This file is part of the yat library, http://trac.thep.lu.se/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 <iostream>
28#include <string>
29#include <vector>
30
31namespace theplu {
32namespace yat {
33namespace utility {
34
35  class CommandLine;
36  ///
37  /// @brief Container of variables for an option. @see CommandLine
38  ///
39  class Option
40  {
41  public:
42    /**
43       @brief Constructor
44       
45       \param cmd Commandline to be hooked up with.
46       @param name string such as "help" for --help, "h" for -h or
47       "h,help" for having both short and long option name
48       @param desc string used in help display
49    */
50    Option(CommandLine& cmd, std::string name, std::string desc); 
51
52    /**
53       @brief destructor
54    */
55    virtual ~Option(void);
56   
57    /**
58       @return description
59    */
60    std::string description(void) const;
61
62    /**
63       \return long name e.g. 'help' for --help option.
64    */
65    std::string long_name(void) const;
66
67    /**
68       \brief parsing the commandline
69     */
70    void parse(std::vector<std::string>::iterator, 
71               std::vector<std::string>::iterator);
72
73    /**
74       @brief Get if option was found in cmd.
75       
76       @return true if option has been detected in parsing
77    */
78    bool present(void) const;
79
80    /**
81       \brief print help output
82     */
83    std::string print(void);
84
85    /**
86       \brief sets present to false
87    */
88    void reset(void);
89
90    /**
91       \return short name e.g. 'h' for -h option.
92    */
93    char short_name(void) const;
94
95    /**
96       \brief Validate the Option
97
98       This function is called after commandline is parsed.
99     */
100    void validate(void);
101
102  protected:
103    /**
104       \return const reference to CommandLine Option belongs to.
105     */
106    const CommandLine& cmd(void) const;
107
108  private:
109    virtual void do_parse(std::vector<std::string>::iterator, 
110                          std::vector<std::string>::iterator)=0;
111
112    /**
113     */
114    virtual std::string print1(void) const;
115
116    /**
117     */
118    virtual std::string print2(void) const;
119
120    /**
121     */
122    virtual std::string print3(void) const;
123
124    /**
125     */
126    virtual std::string print4(void) const;
127
128    /**
129     */
130    virtual void do_validate(void) const=0;
131
132
133    const CommandLine& cmd_;
134    std::string description_;
135    std::string long_name_;
136    bool present_;
137    char short_name_;
138
139    // copy not allowed
140    Option(const Option&);
141    Option& operator=(const Option&);
142  };
143
144}}} // of namespace utility, yat, and theplu
145
146#endif
Note: See TracBrowser for help on using the repository browser.