iphreeqc/PHRQ_io.h
David L Parkhurst 6fa41ac02e Rewrote PHRQ_io. Removed handlers.
Now 1-1 correspondence between phreeqc output methods and PHRQ_io output methods.

Removed error_msg and output_msg from Parser.

Moved prototype for fpnunchf, _user, _end_row, to output.h.

Scott needs to finalize as interface.

Next will remove dead code from PHRQ_io, PHRQ_io_output.cpp, and Parse.cxx.

git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5665 1feff8c3-07ed-0310-ac33-dd36852eb9cd
2011-09-30 18:36:28 +00:00

172 lines
3.4 KiB
C++

#ifndef _PHRQIO_H
#define _PHRQIO_H
#include <sstream>
class PhreeqcStop : std::exception
{
};
class PHRQ_io
{
public:
typedef enum
{
OUTPUT_ERROR,
OUTPUT_WARNING,
OUTPUT_MESSAGE,
OUTPUT_PUNCH,
OUTPUT_SCREEN,
OUTPUT_LOG,
OUTPUT_CHECKLINE,
OUTPUT_GUI_ERROR,
OUTPUT_BASIC,
OUTPUT_CVODE,
OUTPUT_DUMP,
OUTPUT_STDERR,
OUTPUT_SEND_MESSAGE,
OUTPUT_ECHO,
OUTPUT_PUNCH_END_ROW
} output_type;
typedef enum
{
ACTION_OPEN,
ACTION_OUTPUT,
ACTION_CLOSE,
ACTION_REWIND,
ACTION_FLUSH
} action_type;
// constructors
PHRQ_io(void);
virtual ~ PHRQ_io();
// methods
//int phreeqc_handler(const int action, const int type, const char *err_str, const bool stop, const char *, va_list args);
//int open_handler(const int type, const char *file_name);
//bool isopen_handler(const int type);
//int fileop_handler(const int type, int (*PFN) (FILE *));
//int output_handler(const int type, const char *err_str,
// const bool stop, const char *format,
// va_list args);
//static int rewind_wrapper(FILE * file_ptr);
static void safe_close(FILE * file_ptr);
int close_input_files(void);
int close_output_files(void);
static int istream_getc(void *cookie);
void output_string(const int type, std::string str);
int output_open(int type, const char *file_name);
void error_msg(const char *err_str, bool stop);
void warning_msg(const char *err_str);
void output_msg(int type, const char *format, va_list args);
void output_fflush(int type);
void output_rewind(int type);
void output_close(int type);
bool output_isopen(int type);
void fpunchf(const char *name, const char *format, va_list args);
void Set_io_error_count(int i)
{
this->io_error_count = i;
}
int Get_io_error_count(void)
{
return this->io_error_count;
}
void Set_input_file(FILE * in)
{
if (this->input_file != NULL &&
this->input_file != stderr &&
this->input_file != stdout)
{
fclose(this->input_file);
}
this->input_file = in;
}
void Set_output_file(FILE * out)
{
if (this->output_file != NULL &&
this->output_file != stderr &&
this->output_file != stdout)
{
fclose(this->output_file);
}
this->output_file = out;
}
void Set_database_file(FILE * in)
{
if (this->database_file != NULL &&
this->database_file != stdin)
{
fclose(this->database_file);
}
this->database_file = in;
}
void close_input(void)
{
if (input_file != stdin)
{
fclose(input_file);
}
}
void Set_output_file_on(bool tf)
{
this->output_file_on = tf;
}
void Set_log_file_on(bool tf)
{
this->log_file_on = tf;
}
void Set_punch_file_on(bool tf)
{
this->punch_file_on = tf;
}
void Set_error_file_on(bool tf)
{
this->error_file_on = tf;
}
void Set_dump_file_on(bool tf)
{
this->dump_file_on = tf;
}
bool Get_output_file_on(void)
{
return this->output_file_on;
}
bool Get_log_file_on(void)
{
return this->log_file_on;
}
bool Get_punch_file_on(void)
{
return this->punch_file_on;
}
bool Get_error_file_on(void)
{
return this->error_file_on;
}
bool Get_dump_file_on(void)
{
return this->dump_file_on;
}
// data
private:
FILE *input_file;
FILE *database_file;
FILE *output_file; /* OUTPUT_MESSAGE */
FILE *log_file; /* OUTPUT_LOG */
FILE *punch_file; /* OUTPUT_PUNCH */
FILE *error_file; /* OUTPUT_ERROR */
FILE *dump_file; /* OUTPUT_DUMP */
int io_error_count;
bool output_file_on;
bool log_file_on;
bool punch_file_on;
bool error_file_on;
bool dump_file_on;
};
#endif /* _PHRQIO_H */