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

Last change on this file since 965 was 965, checked in by Peter, 14 years ago

Adding CommandLine? class. finishes #240

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