made istream_getc static;

made some routines virtual;
added virtual getc method;

git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6355 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2012-04-04 04:53:03 +00:00
parent 8ea8082fa4
commit 8e9a4e0c3e
2 changed files with 26 additions and 28 deletions

View File

@ -67,7 +67,7 @@ void PHRQ_io::
output_close(void)
/* ---------------------------------------------------------------------- */
{
safe_close(&log_ostream);
safe_close(&output_ostream);
}
/* ---------------------------------------------------------------------- */
void PHRQ_io::
@ -449,11 +449,10 @@ dump_msg(const char * str)
}
}
int PHRQ_io::
istream_getc(void *cookie) //istream_getc is *** static ***
getc(void)
{
if (cookie)
if (std::istream* is = get_istream())
{
std::istream* is = (std::istream*)cookie;
int n = is->get();
if (n == 13 && is->peek() == 10)
{
@ -654,15 +653,13 @@ get_line(void)
int i;
bool empty;
std::string stdtoken;
void *cookie;
bool continue_loop = true;;
PHRQ_io::LINE_TYPE return_value;
// loop for include files
for (;;)
{
cookie = this->get_istream();
if (cookie == NULL)
if (this->get_istream() == NULL)
{
break;
}
@ -679,7 +676,7 @@ get_line(void)
*/
continue_loop = false;
if (get_logical_line(cookie) == LT_EOF)
if (get_logical_line() == LT_EOF)
{
//pop next file
this->pop_istream();
@ -754,7 +751,12 @@ get_line(void)
{
std::ostringstream errstr;
errstr << "Could not open include file " << file_name;
#if defined(PHREEQCI_GUI)
warning_msg(errstr.str().c_str());
continue;
#else
error_msg(errstr.str().c_str(), OT_STOP);
#endif
}
this->push_istream(next_stream);
continue;
@ -775,18 +777,14 @@ get_line(void)
OK otherwise
*/
PHRQ_io::LINE_TYPE PHRQ_io::
get_logical_line(void * cookie)
get_logical_line(void)
{
int
j;
unsigned int
pos;
char
c;
if (!cookie)
return LT_EOF;
int j;
unsigned int pos;
char c;
m_line_save.erase(m_line_save.begin(), m_line_save.end()); // m_line_save.clear();
while ((j = istream_getc(cookie)) != EOF)
while ((j = getc()) != EOF)
{
c = (char) j;
if (c == '#')
@ -801,7 +799,7 @@ get_logical_line(void * cookie)
}
m_line_save += c;
}
while ((j = istream_getc(cookie)) != EOF);
while ((j = getc()) != EOF);
}
if (c == ';')
break;
@ -813,7 +811,7 @@ get_logical_line(void * cookie)
{
pos = (int) m_line_save.size();
m_line_save += c;
while ((j = PHRQ_io::istream_getc(cookie)) != EOF)
while ((j = getc()) != EOF)
{
c = (char) j;
if (c == '\\')

View File

@ -13,7 +13,7 @@
#include "Keywords.h"
#include <time.h>
class PhreeqcStop : std::exception
class PhreeqcStop : public std::exception
{
};
@ -39,7 +39,6 @@ public:
virtual ~ PHRQ_io();
// methods
static int istream_getc(void *cookie);
static void safe_close(std::ostream **stream_ptr);
static void safe_close(FILE **file_ptr);
void close_ostreams(void);
@ -64,7 +63,7 @@ public:
bool Get_output_on(void) {return this->output_on;};
// log_ostream
bool log_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out);
virtual bool log_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out);
void log_flush(void);
void log_close(void);
virtual void log_msg(const char * str);
@ -85,7 +84,7 @@ public:
// error_ostream
#ifdef ERROR_OSTREAM
bool error_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out);
virtual bool error_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out);
void error_flush(void);
void error_close(void);
virtual void error_msg(const char * str, bool stop=false);
@ -95,7 +94,7 @@ public:
bool Get_error_on(void) {return this->error_on;}
virtual void warning_msg(const char *err_str);
#else
bool error_open(const char *file_name, const char * mode = "w");
virtual bool error_open(const char *file_name, const char * mode = "w");
void error_flush(void);
void error_close(void);
virtual void error_msg(const char * str, bool stop=false);
@ -107,10 +106,10 @@ public:
#endif
// dump_ostream
bool dump_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out);
virtual bool dump_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out);
void dump_flush(void);
void dump_close(void);
void dump_msg(const char * str);
virtual void dump_msg(const char * str);
void Set_dump_ostream(std::ostream * out) {this->dump_ostream = out;};
std::ostream *Get_dump_ostream(void) {return this->dump_ostream;};
void Set_dump_on(bool tf) {this->dump_on = tf;};
@ -127,8 +126,9 @@ public:
bool Get_screen_on(void) {return this->screen_on;};
// input methods
virtual int getc(void);
LINE_TYPE get_line(void);
LINE_TYPE get_logical_line(void * cookie);
LINE_TYPE get_logical_line(void);
bool check_key(std::string::iterator begin, std::string::iterator end);
std::string & Get_m_line() {return m_line;}
std::string & Get_m_line_save() {return m_line_save;}