yat/utility/OptionFile.h

Code
Comments
Other
Rev Date Author Line
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 4 // $Id$
975 17 Oct 07 peter 5
975 17 Oct 07 peter 6 /*
4359 23 Aug 23 peter 7   Copyright (C) 2007 Peter Johansson
4359 23 Aug 23 peter 8   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
4359 23 Aug 23 peter 9   Copyright (C) 2009 Peter Johansson
975 17 Oct 07 peter 10
1437 25 Aug 08 peter 11   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 13   The yat library is free software; you can redistribute it and/or
975 17 Oct 07 peter 14   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 15   published by the Free Software Foundation; either version 3 of the
975 17 Oct 07 peter 16   License, or (at your option) any later version.
975 17 Oct 07 peter 17
975 17 Oct 07 peter 18   The yat library is distributed in the hope that it will be useful,
975 17 Oct 07 peter 19   but WITHOUT ANY WARRANTY; without even the implied warranty of
975 17 Oct 07 peter 20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
975 17 Oct 07 peter 21   General Public License for more details.
975 17 Oct 07 peter 22
975 17 Oct 07 peter 23   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 24   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 37      \brief Class for file related options
2046 02 Sep 09 peter 38
2046 02 Sep 09 peter 39      This class could be used for an option with argument when the
2046 02 Sep 09 peter 40      argument is a file. The class adds some convenience on top of
2046 02 Sep 09 peter 41      OptionArg<std::string> by utilizing the FileUtil class. Besides
2046 02 Sep 09 peter 42      setting the name and description of the option and whether the
2046 02 Sep 09 peter 43      option must appear in the command line, you can declare whether
2046 02 Sep 09 peter 44      the file must exist and whether it must fulfill certain file
2046 02 Sep 09 peter 45      permissions. If any of these requirements are not met, an
2046 02 Sep 09 peter 46      exception will be thrown during the validation phase in
2046 02 Sep 09 peter 47      CommandLine::parse.
2046 02 Sep 09 peter 48
2046 02 Sep 09 peter 49      \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 55        \brief Constructor
4200 19 Aug 22 peter 56
975 17 Oct 07 peter 57        \param cmd Commandline Option is associated with
979 21 Oct 07 peter 58        \param name string such as "file" for --file, "f" for -f or
975 17 Oct 07 peter 59        "f,file" for having both short and long option name
975 17 Oct 07 peter 60        \param desc string used in help display
980 22 Oct 07 peter 61        \param required If true option must be found in commandline or
980 22 Oct 07 peter 62        exception is thrown in validation
2046 02 Sep 09 peter 63        \param exist if true File must exist, see FileUtil::exists()
979 21 Oct 07 peter 64        \param bits used to check permission on file, see
2046 02 Sep 09 peter 65        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 71        \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