mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-16 16:44:49 +01:00
fixed checks for successful opening of std::ofstream
git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7661 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
parent
28d649ab93
commit
8e3394ca8c
39
PHRQ_io.cpp
39
PHRQ_io.cpp
@ -44,16 +44,25 @@ PHRQ_io::
|
||||
// ---------------------------------------------------------------------- */
|
||||
// output ostream methods
|
||||
// ---------------------------------------------------------------------- */
|
||||
|
||||
bool PHRQ_io::
|
||||
ofstream_open(std::ostream **os, const char *file_name, std::ios_base::openmode mode)
|
||||
{
|
||||
std::ofstream *ofs = new std::ofstream(file_name, mode);
|
||||
if (ofs && ofs->is_open())
|
||||
{
|
||||
*os = ofs;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
bool PHRQ_io::
|
||||
output_open(const char *file_name, std::ios_base::openmode mode)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
if ((output_ostream = new std::ofstream(file_name, mode)) == NULL)
|
||||
{
|
||||
return false; // error
|
||||
}
|
||||
return true;
|
||||
return ofstream_open(&output_ostream, file_name, mode);
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void PHRQ_io::
|
||||
@ -90,11 +99,7 @@ bool PHRQ_io::
|
||||
log_open(const char *file_name, std::ios_base::openmode mode)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
if ((log_ostream = new std::ofstream(file_name, mode)) == NULL)
|
||||
{
|
||||
return false; // error
|
||||
}
|
||||
return true;
|
||||
return ofstream_open(&log_ostream, file_name, mode);
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void PHRQ_io::
|
||||
@ -130,11 +135,7 @@ bool PHRQ_io::
|
||||
punch_open(const char *file_name, std::ios_base::openmode mode)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
if ((punch_ostream = new std::ofstream(file_name, mode)) == NULL)
|
||||
{
|
||||
return false; // error
|
||||
}
|
||||
return true;
|
||||
return ofstream_open(&punch_ostream, file_name, mode);
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void PHRQ_io::
|
||||
@ -174,7 +175,7 @@ error_open(const char *file_name, std::ios_base::openmode mode)
|
||||
{
|
||||
if (file_name != NULL)
|
||||
{
|
||||
if ((error_ostream = new std::ofstream(file_name, mode)) == NULL)
|
||||
if (!ofstream_open(&error_ostream, file_name, mode))
|
||||
{
|
||||
error_ostream = &std::cerr;
|
||||
return false;
|
||||
@ -362,11 +363,7 @@ bool PHRQ_io::
|
||||
dump_open(const char *file_name, std::ios_base::openmode mode)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
if ((dump_ostream = new std::ofstream(file_name, mode)) == NULL)
|
||||
{
|
||||
return false; // error
|
||||
}
|
||||
return true;
|
||||
return ofstream_open(&dump_ostream, file_name, mode);
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void PHRQ_io::
|
||||
|
||||
@ -54,6 +54,9 @@ public:
|
||||
void push_istream(std::istream * cookie, bool auto_delete = true);
|
||||
void clear_istream(void);
|
||||
|
||||
// helper
|
||||
bool ofstream_open(std::ostream **os, const char *file_name, std::ios_base::openmode mode = std::ios_base::out);
|
||||
|
||||
// output_ostream
|
||||
virtual bool output_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out);
|
||||
void output_flush(void);
|
||||
|
||||
4
read.cpp
4
read.cpp
@ -4700,7 +4700,7 @@ read_selected_output(void)
|
||||
strcpy(file_name, next_char);
|
||||
have_punch_name = TRUE;
|
||||
punch_close();
|
||||
if (punch_open(file_name) != OK)
|
||||
if (!punch_open(file_name))
|
||||
{
|
||||
error_string = sformatf( "Can`t open file, %s.", file_name);
|
||||
input_error++;
|
||||
@ -5036,7 +5036,7 @@ read_selected_output(void)
|
||||
if (!have_punch_name)
|
||||
{
|
||||
punch_close();
|
||||
if (punch_open("selected.out") != OK)
|
||||
if (!punch_open("selected.out"))
|
||||
{
|
||||
error_string = sformatf( "Can`t open file, %s.", "selected.out");
|
||||
input_error++;
|
||||
|
||||
@ -969,6 +969,14 @@ dump_cpp(void)
|
||||
phreeqc2cxxStorageBin(phreeqcBin);
|
||||
|
||||
std::ofstream fs(dump_file_name_cpp.c_str());
|
||||
if (!fs.is_open())
|
||||
{
|
||||
error_string = sformatf( "Can`t open file, %s.", dump_file_name_cpp.c_str());
|
||||
input_error++;
|
||||
error_msg(error_string, CONTINUE);
|
||||
return (OK);
|
||||
}
|
||||
|
||||
fs << "# Dumpfile" << "\n" << "# Transport simulation " << simul_tr << " Shift " << transport_step << "\n" << "#" << "\n";
|
||||
phreeqcBin.dump_raw(fs, 0);
|
||||
fs << "END" << "\n";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user