iphreeqc/PHRQ_io.h
David L Parkhurst 02797e6934 Added PHRQ_base and PHRQ_io to project.
PHRQ_base has not been added to the C++ classes yet.

PHRQ_io is implemented enough to run. Need to work on 
reimplementing logic by moving some things that were in
phreeqc_files.cpp (now implemented as PHRQ_io class) to PHRQ_io_output, which is derived from output.cpp.

PHRQ_io_output has methods of Phreeqc class and knows the data in the phreeqc class. PHRQ_io does not know about the phreeqc class.

The ifdef USE_OLD_IO should cause io to revert to the old way of doing it. 

I have only worked on ClrClass_debug to now.

git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5627 1feff8c3-07ed-0310-ac33-dd36852eb9cd
2011-09-08 23:07:14 +00:00

113 lines
2.1 KiB
C++

#ifndef _PHRQIO_H
#define _PHRQIO_H
#include <sstream>
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);
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);
int close_input_files(void);
int close_output_files(void);
static int istream_getc(void *cookie);
void Set_error_count(int i)
{
this->error_count = i;
}
int Get_error_count(void)
{
return this->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);
}
}
// 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 error_count;
};
#endif /* _PHRQIO_H */