975 |
17 Oct 07 |
peter |
1 |
#ifndef _theplu_yat_utility_option_file_ |
975 |
17 Oct 07 |
peter |
2 |
#define _theplu_yat_utility_option_file_ |
975 |
17 Oct 07 |
peter |
3 |
|
975 |
17 Oct 07 |
peter |
// $Id$ |
975 |
17 Oct 07 |
peter |
5 |
|
975 |
17 Oct 07 |
peter |
6 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2009 Peter Johansson |
975 |
17 Oct 07 |
peter |
10 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
975 |
17 Oct 07 |
peter |
12 |
|
975 |
17 Oct 07 |
peter |
The yat library is free software; you can redistribute it and/or |
975 |
17 Oct 07 |
peter |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
975 |
17 Oct 07 |
peter |
License, or (at your option) any later version. |
975 |
17 Oct 07 |
peter |
17 |
|
975 |
17 Oct 07 |
peter |
The yat library is distributed in the hope that it will be useful, |
975 |
17 Oct 07 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
975 |
17 Oct 07 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
975 |
17 Oct 07 |
peter |
General Public License for more details. |
975 |
17 Oct 07 |
peter |
22 |
|
975 |
17 Oct 07 |
peter |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
975 |
17 Oct 07 |
peter |
25 |
*/ |
975 |
17 Oct 07 |
peter |
26 |
|
975 |
17 Oct 07 |
peter |
27 |
#include "OptionArg.h" |
975 |
17 Oct 07 |
peter |
28 |
|
975 |
17 Oct 07 |
peter |
29 |
#include <string> |
975 |
17 Oct 07 |
peter |
30 |
|
975 |
17 Oct 07 |
peter |
31 |
namespace theplu { |
975 |
17 Oct 07 |
peter |
32 |
namespace yat { |
975 |
17 Oct 07 |
peter |
33 |
namespace utility { |
975 |
17 Oct 07 |
peter |
34 |
|
975 |
17 Oct 07 |
peter |
35 |
class CommandLine; |
975 |
17 Oct 07 |
peter |
36 |
/** |
975 |
17 Oct 07 |
peter |
\brief Class for file related options |
2046 |
02 Sep 09 |
peter |
38 |
|
2046 |
02 Sep 09 |
peter |
This class could be used for an option with argument when the |
2046 |
02 Sep 09 |
peter |
argument is a file. The class adds some convenience on top of |
2046 |
02 Sep 09 |
peter |
OptionArg<std::string> by utilizing the FileUtil class. Besides |
2046 |
02 Sep 09 |
peter |
setting the name and description of the option and whether the |
2046 |
02 Sep 09 |
peter |
option must appear in the command line, you can declare whether |
2046 |
02 Sep 09 |
peter |
the file must exist and whether it must fulfill certain file |
2046 |
02 Sep 09 |
peter |
permissions. If any of these requirements are not met, an |
2046 |
02 Sep 09 |
peter |
exception will be thrown during the validation phase in |
2046 |
02 Sep 09 |
peter |
CommandLine::parse. |
2046 |
02 Sep 09 |
peter |
48 |
|
2046 |
02 Sep 09 |
peter |
\see FileUtil |
975 |
17 Oct 07 |
peter |
50 |
*/ |
979 |
21 Oct 07 |
peter |
51 |
class OptionFile : public OptionArg<std::string> |
975 |
17 Oct 07 |
peter |
52 |
{ |
975 |
17 Oct 07 |
peter |
53 |
public: |
975 |
17 Oct 07 |
peter |
54 |
/** |
4200 |
19 Aug 22 |
peter |
\brief Constructor |
4200 |
19 Aug 22 |
peter |
56 |
|
975 |
17 Oct 07 |
peter |
\param cmd Commandline Option is associated with |
979 |
21 Oct 07 |
peter |
\param name string such as "file" for --file, "f" for -f or |
975 |
17 Oct 07 |
peter |
"f,file" for having both short and long option name |
975 |
17 Oct 07 |
peter |
\param desc string used in help display |
980 |
22 Oct 07 |
peter |
\param required If true option must be found in commandline or |
980 |
22 Oct 07 |
peter |
exception is thrown in validation |
2046 |
02 Sep 09 |
peter |
\param exist if true File must exist, see FileUtil::exists() |
979 |
21 Oct 07 |
peter |
\param bits used to check permission on file, see |
2046 |
02 Sep 09 |
peter |
FileUtil::permissions() |
975 |
17 Oct 07 |
peter |
66 |
*/ |
4200 |
19 Aug 22 |
peter |
67 |
OptionFile(CommandLine& cmd, std::string name, std::string desc, |
4200 |
19 Aug 22 |
peter |
68 |
bool required=false, bool exist=false, std::string bits=""); |
975 |
17 Oct 07 |
peter |
69 |
|
1014 |
01 Feb 08 |
peter |
70 |
/** |
1014 |
01 Feb 08 |
peter |
\brief Destructor |
1014 |
01 Feb 08 |
peter |
72 |
*/ |
1014 |
01 Feb 08 |
peter |
73 |
virtual ~OptionFile(void); |
975 |
17 Oct 07 |
peter |
74 |
|
975 |
17 Oct 07 |
peter |
75 |
private: |
980 |
22 Oct 07 |
peter |
76 |
void do_validate2() const; |
975 |
17 Oct 07 |
peter |
77 |
|
975 |
17 Oct 07 |
peter |
78 |
bool exist_; |
975 |
17 Oct 07 |
peter |
79 |
std::string bits_; |
4200 |
19 Aug 22 |
peter |
80 |
|
975 |
17 Oct 07 |
peter |
81 |
}; |
975 |
17 Oct 07 |
peter |
82 |
|
975 |
17 Oct 07 |
peter |
83 |
}}} // of namespace utility, yat, and theplu |
975 |
17 Oct 07 |
peter |
84 |
|
975 |
17 Oct 07 |
peter |
85 |
#endif |