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

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

adding convenient classes for options File

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1// $Id: OptionInFile.cc 1014 2008-02-01 16:06:51Z peter $
2
3/*
4  Copyright (C) 2008 Peter Johansson
5
6  This file is part of the yat library, http://trac.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 2 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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "OptionInFile.h"
25
26#include <cassert>
27#include <fstream>
28#include <string>
29
30namespace theplu {
31namespace yat {
32namespace utility {
33
34
35  OptionInFile::OptionInFile(CommandLine& cmd, std::string flag, 
36                             std::string desc, bool required)
37    : OptionFile(cmd, flag, desc, required, true, "r"), is_(NULL) {}
38
39
40  OptionInFile::~OptionInFile(void)
41  {
42    if (is_) {
43      is_->close();
44      delete is_;
45    }
46  }
47
48
49  std::istream& OptionInFile::istream(void)
50  {
51    if (!present())
52      return std::cin;
53    if (!is_) {
54      assert(value().size());
55      is_ = new std::ifstream(value().c_str());
56      assert(is_->good());
57    }
58    return *is_;
59  }
60
61
62}}} // of namespace utility, yat, and theplu
Note: See TracBrowser for help on using the repository browser.