source: trunk/yat/utility/OptionOutFile.cc @ 1679

Last change on this file since 1679 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: OptionOutFile.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 "OptionOutFile.h"
23
24#include <cassert>
25#include <fstream>
26#include <iostream>
27#include <string>
28
29namespace theplu {
30namespace yat {
31namespace utility {
32
33
34  OptionOutFile::OptionOutFile(CommandLine& cmd, std::string flag, 
35                               std::string desc, bool required)
36    : OptionFile(cmd, flag, desc, required, false, "w"), os_(NULL) {}
37
38
39  OptionOutFile::~OptionOutFile(void)
40  {
41    if (os_) {
42      os_->close();
43      delete os_;
44    }
45  }
46
47
48  std::ostream& OptionOutFile::ostream(void)
49  {
50    if (!present())
51      return std::cout;
52    if (!os_){
53      assert(value().size());
54      os_ = new std::ofstream(value().c_str());
55      assert(os_->good());
56    }
57    return *os_;
58  }
59
60
61}}} // of namespace utility, yat, and theplu
Note: See TracBrowser for help on using the repository browser.