root/src/io_errorStream.cpp

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. close
  2. cannot_open_file

   1 /*! \file io_errorStream.cpp
   2     \brief Implementation of io_errorStream.h 
   3 
   4     Revision history
   5     --------------------------------------------------
   6 
   7          Revised by Christian Power April 2016
   8          Revised by Christian Power February 2016
   9          Originally written by Christian Power
  10               (power22c@gmail.com) Januar 2016
  11 
  12     Idea
  13     --------------------------------------------------
  14 
  15     No special idea
  16 
  17     \author Christian Power
  18     \date 25. April 2016
  19     \copyright Copyright (c) 2016 Christian Power.  All rights reserved.
  20  */
  21 
  22 #include <sstream>
  23 #include "io_errorStream.h"
  24 #include "io_parameter.h"
  25 
  26 #ifdef DEBUG
  27 #include <iostream>
  28 #endif 
  29 
  30 void cannot_open_file(const std::string& fname);
  31 
  32 Esfem::Io::Error_stream::Error_stream(const std::string& fname)
  33   :ofs {fname, std::ios_base::app}
  34 {
  35 #ifdef DEBUG
  36   std::clog << "Opening " << fname << " for Error_stream" << std::endl;
  37 #endif
  38   if(!ofs) cannot_open_file(fname);
  39 }
  40 Esfem::Io::Error_stream::Error_stream(const Parameter& d)
  41   :Error_stream {d.error_log()}
  42 {}
  43 Esfem::Io::Error_stream::Error_stream(const std::string& suffix, const Parameter& d)
  44   :Error_stream {d.error_log() + suffix}
  45 {}
  46 Esfem::Io::Error_stream& Esfem::Io::Error_stream::operator<<(StdManip manip){
  47 #if DEBUG > 8
  48   std::clog << "Using operator<<(StdManip)." << std::endl;
  49 #endif
  50   manip(ofs);
  51   return *this;
  52 }
  53 Esfem::Io::Error_stream& Esfem::Io::Error_stream::close(){
  54   ofs.close();
  55   return *this;
  56 }
  57 
  58 // ----------------------------------------------------------------------
  59 // Internal implementation
  60 
  61 void cannot_open_file(const std::string& fname){
  62   std::ostringstream err_msg;
  63   err_msg << "Error in constructor of Error_stream. "
  64     "Could not open file: " << fname;
  65   throw std::runtime_error {err_msg.str()};
  66 }
  67 
  68 /*! Log:
  69     19.02.16: Fixed bug in with cannot_open_file().  runtime_error was not
  70      throwing.  
  71  */

/* [<][>][^][v][top][bottom][index][help] */