1014 |
01 Feb 08 |
peter |
// $Id$ |
1014 |
01 Feb 08 |
peter |
2 |
|
1014 |
01 Feb 08 |
peter |
3 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2009, 2012 Peter Johansson |
1014 |
01 Feb 08 |
peter |
6 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
1014 |
01 Feb 08 |
peter |
8 |
|
1014 |
01 Feb 08 |
peter |
The yat library is free software; you can redistribute it and/or |
1014 |
01 Feb 08 |
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 |
1014 |
01 Feb 08 |
peter |
License, or (at your option) any later version. |
1014 |
01 Feb 08 |
peter |
13 |
|
1014 |
01 Feb 08 |
peter |
The yat library is distributed in the hope that it will be useful, |
1014 |
01 Feb 08 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1014 |
01 Feb 08 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1014 |
01 Feb 08 |
peter |
General Public License for more details. |
1014 |
01 Feb 08 |
peter |
18 |
|
1014 |
01 Feb 08 |
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/>. |
1014 |
01 Feb 08 |
peter |
21 |
*/ |
1014 |
01 Feb 08 |
peter |
22 |
|
2881 |
18 Nov 12 |
peter |
23 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
24 |
|
1014 |
01 Feb 08 |
peter |
25 |
#include "OptionInFile.h" |
1014 |
01 Feb 08 |
peter |
26 |
|
1014 |
01 Feb 08 |
peter |
27 |
#include <cassert> |
1014 |
01 Feb 08 |
peter |
28 |
#include <fstream> |
2046 |
02 Sep 09 |
peter |
29 |
#include <iostream> |
1014 |
01 Feb 08 |
peter |
30 |
#include <string> |
1014 |
01 Feb 08 |
peter |
31 |
|
1014 |
01 Feb 08 |
peter |
32 |
namespace theplu { |
1014 |
01 Feb 08 |
peter |
33 |
namespace yat { |
1014 |
01 Feb 08 |
peter |
34 |
namespace utility { |
1014 |
01 Feb 08 |
peter |
35 |
|
1014 |
01 Feb 08 |
peter |
36 |
|
4200 |
19 Aug 22 |
peter |
37 |
OptionInFile::OptionInFile(CommandLine& cmd, std::string flag, |
1014 |
01 Feb 08 |
peter |
38 |
std::string desc, bool required) |
1014 |
01 Feb 08 |
peter |
39 |
: OptionFile(cmd, flag, desc, required, true, "r"), is_(NULL) {} |
1014 |
01 Feb 08 |
peter |
40 |
|
1014 |
01 Feb 08 |
peter |
41 |
|
1014 |
01 Feb 08 |
peter |
42 |
OptionInFile::~OptionInFile(void) |
1014 |
01 Feb 08 |
peter |
43 |
{ |
1014 |
01 Feb 08 |
peter |
44 |
if (is_) { |
1014 |
01 Feb 08 |
peter |
45 |
is_->close(); |
1014 |
01 Feb 08 |
peter |
46 |
delete is_; |
1014 |
01 Feb 08 |
peter |
47 |
} |
1014 |
01 Feb 08 |
peter |
48 |
} |
1014 |
01 Feb 08 |
peter |
49 |
|
1014 |
01 Feb 08 |
peter |
50 |
|
1014 |
01 Feb 08 |
peter |
51 |
std::istream& OptionInFile::istream(void) |
1014 |
01 Feb 08 |
peter |
52 |
{ |
1014 |
01 Feb 08 |
peter |
53 |
if (!present()) |
1014 |
01 Feb 08 |
peter |
54 |
return std::cin; |
1014 |
01 Feb 08 |
peter |
55 |
if (!is_) { |
1014 |
01 Feb 08 |
peter |
56 |
assert(value().size()); |
1014 |
01 Feb 08 |
peter |
57 |
is_ = new std::ifstream(value().c_str()); |
1014 |
01 Feb 08 |
peter |
58 |
assert(is_->good()); |
1014 |
01 Feb 08 |
peter |
59 |
} |
1014 |
01 Feb 08 |
peter |
60 |
return *is_; |
1014 |
01 Feb 08 |
peter |
61 |
} |
1014 |
01 Feb 08 |
peter |
62 |
|
1014 |
01 Feb 08 |
peter |
63 |
|
1014 |
01 Feb 08 |
peter |
64 |
}}} // of namespace utility, yat, and theplu |