source: trunk/yat/utility/OptionInFile.cc @ 1703

Last change on this file since 1703 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
1// $Id: OptionInFile.cc 1487 2008-09-10 08:41:36Z jari $
2
3/*
4  Copyright (C) 2008 Peter Johansson
5
6  This file is part of the yat library, http://dev.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 3 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with yat. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "OptionInFile.h"
23
24#include <cassert>
25#include <fstream>
26#include <string>
27
28namespace theplu {
29namespace yat {
30namespace utility {
31
32
33  OptionInFile::OptionInFile(CommandLine& cmd, std::string flag, 
34                             std::string desc, bool required)
35    : OptionFile(cmd, flag, desc, required, true, "r"), is_(NULL) {}
36
37
38  OptionInFile::~OptionInFile(void)
39  {
40    if (is_) {
41      is_->close();
42      delete is_;
43    }
44  }
45
46
47  std::istream& OptionInFile::istream(void)
48  {
49    if (!present())
50      return std::cin;
51    if (!is_) {
52      assert(value().size());
53      is_ = new std::ifstream(value().c_str());
54      assert(is_->good());
55    }
56    return *is_;
57  }
58
59
60}}} // of namespace utility, yat, and theplu
Note: See TracBrowser for help on using the repository browser.