Updated for IPhreeqc to use PHREEQC_CPP and PHREEQC_CLASS. Currently doesn't include gmp. MemDebug project still needs work. Needs to be tested on linux.

git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4145 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2010-03-05 21:20:09 +00:00
parent e180be69b0
commit 4b793aa95f
13 changed files with 1592 additions and 940 deletions

View File

@ -6,7 +6,8 @@
#include <cstdio> // std::fprintf
#include "phreeqcns.hxx"
class IErrorReporter {
class IErrorReporter
{
public:
virtual size_t AddError(const char* error_msg) = 0;
virtual void Clear(void) = 0;

File diff suppressed because it is too large Load Diff

87
IPhreeqc.hpp Normal file
View File

@ -0,0 +1,87 @@
#ifndef _INC_IPHREEQC_HPP
#define _INC_IPHREEQC_HPP
#include "Phreeqc.h" /* Phreeqc */
#include "IPhreeqcCallbacks.h" /* PFN_PRERUN_CALLBACK, PFN_POSTRUN_CALLBACK, PFN_CATCH_CALLBACK */
#include "Var.h" /* VRESULT */
#include "SelectedOutput.hxx"
class IErrorReporter;
struct PhreeqcStop{};
class IPhreeqc : public Phreeqc
{
public:
IPhreeqc(void);
~IPhreeqc(void);
public:
int LoadDatabase(const char* filename);
int LoadDatabaseString(const char* input);
void UnLoadDatabase(void);
void OutputLastError(void);
const char* GetLastErrorString(void);
VRESULT AccumulateLine(const char *line);
int Run(int output_on, int error_on, int log_on, int selected_output_on);
int RunFile(const char* filename, int output_on, int error_on, int log_on, int selected_output_on);
int RunString(const char* input, int output_on, int error_on, int log_on, int selected_output_on);
int GetSelectedOutputRowCount(void)const;
int GetSelectedOutputColumnCount(void)const;
VRESULT GetSelectedOutputValue(int row, int col, VAR* pVAR);
void OutputLines(void);
size_t AddError(const char* error_msg);
const std::string& GetAccumulatedLines(void);
void ClearAccumulatedLines(void);
// Singleton for library
static IPhreeqc* LibraryInstance();
// Callbacks
//
// IPhreeqc.cpp
static int handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args);
int output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args);
int open_handler(const int type, const char *file_name/*, void *cookie*/);
// module_files.c
static int module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args);
int module_isopen_handler(const int type);
int module_open_handler(const int type, const char *file_name);
// module_output.c
int output_isopen(const int type);
virtual int EndRow(void);
void AddSelectedOutput(const char* name, const char* format, va_list argptr);
void check_database(const char* sz_routine);
void do_run(const char* sz_routine, std::istream* pis, FILE* fp, int output_on, int error_on, int log_on, int selected_output_on, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie);
protected:
void Init(void);
protected:
// Data
IErrorReporter *ErrorReporter;
CSelectedOutput *SelectedOutput;
std::string PunchFileName;
bool DatabaseLoaded;
bool SelectedOutputOn;
std::string StringInput;
private:
static IPhreeqc* Instance;
};
#endif /* _INC_IPHREEQC_HPP */

View File

@ -1,35 +0,0 @@
#if !defined(__PHREEQC_PARSER_HXX_INC)
#define __PHREEQC_PARSER_HXX_INC
// COMMENT: {11/10/2004 10:35:56 PM}#include <string>
// COMMENT: {11/10/2004 10:35:56 PM}//#include <iosfwd>
// COMMENT: {11/10/2004 10:35:56 PM}
// COMMENT: {11/10/2004 10:35:56 PM}
// COMMENT: {11/10/2004 10:35:56 PM}struct PhreeqcStop{};
// COMMENT: {11/10/2004 10:35:56 PM}
// COMMENT: {11/10/2004 10:35:56 PM}
// COMMENT: {11/10/2004 10:35:56 PM}class CPhreeqcParser
// COMMENT: {11/10/2004 10:35:56 PM}{
// COMMENT: {11/10/2004 10:35:56 PM}public:
// COMMENT: {11/10/2004 10:35:56 PM} CPhreeqcParser(std::istream& input);
// COMMENT: {11/10/2004 10:35:56 PM} virtual ~CPhreeqcParser(void);
// COMMENT: {11/10/2004 10:35:56 PM}
// COMMENT: {11/10/2004 10:35:56 PM} // const char* GetErrorMsg(void);
// COMMENT: {11/10/2004 10:35:56 PM}
// COMMENT: {11/10/2004 10:35:56 PM} // overrides
// COMMENT: {11/10/2004 10:35:56 PM} int get_logical_line(int *l);
// COMMENT: {11/10/2004 10:35:56 PM} int get_line(void);
// COMMENT: {11/10/2004 10:35:56 PM} // int error_msg (const char *err_str, const int stop);
// COMMENT: {11/10/2004 10:35:56 PM}
// COMMENT: {11/10/2004 10:35:56 PM}
// COMMENT: {11/10/2004 10:35:56 PM}protected:
// COMMENT: {11/10/2004 10:35:56 PM} std::istream& m_input_stream;
// COMMENT: {11/10/2004 10:35:56 PM} //std::ostream& m_output_stream;
// COMMENT: {11/10/2004 10:35:56 PM} //std::ostream& m_error_stream;
// COMMENT: {11/10/2004 10:35:56 PM}
// COMMENT: {11/10/2004 10:35:56 PM} //std::string m_errors;
// COMMENT: {11/10/2004 10:35:56 PM}};
#endif // __PHREEQC_PARSER_HXX_INC

View File

@ -5,236 +5,253 @@
#pragma warning(disable : 4786) // disable truncation warning
#include <sstream> // std::ostringstream
#include <windows.h> // ::OutputDebugString
#else
#if defined(PHREEQC_CLASS)
#include <windows.h> // ::OutputDebugString
#endif
#endif
#include <stdarg.h>
#include <stdio.h>
#if defined(PHREEQC_CLASS)
#include "phrqtype.h"
#include "p2c.h"
#include "global_structures.h"
#include "basic.h"
#include "Phreeqc.h"
// COMMENT: {2/24/2010 6:01:56 PM}extern int user_punch_count_headings;
// COMMENT: {2/24/2010 6:01:56 PM}extern char **user_punch_headings;
#endif
#include "SelectedOutput.hxx"
#include "phreeqcns.hxx"
const size_t RESERVE_ROWS = 80;
const size_t RESERVE_COLS = 80;
int EndRow(void);
// COMMENT: {3/3/2010 5:31:34 PM}int EndRow(void);
void AddSelectedOutput(const char* name, const char* format, va_list argptr);
int warning_msg (const char *err_str);
int EndRow(void)
{
if (CSelectedOutput::Instance()->GetRowCount() <= 1) {
// ensure all user_punch headings are included
for (int i = n_user_punch_index; i < user_punch_count_headings; ++i) {
CSelectedOutput::Instance()->PushBackEmpty(user_punch_headings[i]);
}
}
return CSelectedOutput::Instance()->EndRow();
}
// COMMENT: {3/3/2010 8:55:29 PM}int Phreeqc::EndRow(void)
// COMMENT: {3/3/2010 8:55:29 PM}{
// COMMENT: {3/3/2010 8:55:29 PM}// COMMENT: {3/3/2010 7:29:42 PM} if (CSelectedOutput::Instance()->GetRowCount() <= 1)
// COMMENT: {3/3/2010 8:55:29 PM} if (this->SelectedOutput.GetRowCount() <= 1)
// COMMENT: {3/3/2010 8:55:29 PM} {
// COMMENT: {3/3/2010 8:55:29 PM} // ensure all user_punch headings are included
// COMMENT: {3/3/2010 8:55:29 PM} for (int i = n_user_punch_index; i < user_punch_count_headings; ++i)
// COMMENT: {3/3/2010 8:55:29 PM} {
// COMMENT: {3/3/2010 8:55:29 PM} CSelectedOutput::Instance()->PushBackEmpty(user_punch_headings[i]);
// COMMENT: {3/3/2010 8:55:29 PM} }
// COMMENT: {3/3/2010 8:55:29 PM} }
// COMMENT: {3/3/2010 8:55:29 PM} return CSelectedOutput::Instance()->EndRow();
// COMMENT: {3/3/2010 8:55:29 PM}}
int PushBackDouble(const char* key, double dVal)
{
return CSelectedOutput::Instance()->PushBackDouble(key, dVal);
}
int PushBackLong(const char* key, long lVal)
{
return CSelectedOutput::Instance()->PushBackLong(key, lVal);
}
int PushBackString(const char* key, const char* sVal)
{
return CSelectedOutput::Instance()->PushBackString(key, sVal);
}
int PushBackEmpty(const char* key)
{
return CSelectedOutput::Instance()->PushBackEmpty(key);
}
// COMMENT: {3/3/2010 8:55:40 PM}int PushBackDouble(const char* key, double dVal)
// COMMENT: {3/3/2010 8:55:40 PM}{
// COMMENT: {3/3/2010 8:55:40 PM} return CSelectedOutput::Instance()->PushBackDouble(key, dVal);
// COMMENT: {3/3/2010 8:55:40 PM}}
// COMMENT: {3/3/2010 8:55:40 PM}
// COMMENT: {3/3/2010 8:55:40 PM}int PushBackLong(const char* key, long lVal)
// COMMENT: {3/3/2010 8:55:40 PM}{
// COMMENT: {3/3/2010 8:55:40 PM} return CSelectedOutput::Instance()->PushBackLong(key, lVal);
// COMMENT: {3/3/2010 8:55:40 PM}}
// COMMENT: {3/3/2010 8:55:40 PM}
// COMMENT: {3/3/2010 8:55:40 PM}int PushBackString(const char* key, const char* sVal)
// COMMENT: {3/3/2010 8:55:40 PM}{
// COMMENT: {3/3/2010 8:55:40 PM} return CSelectedOutput::Instance()->PushBackString(key, sVal);
// COMMENT: {3/3/2010 8:55:40 PM}}
// COMMENT: {3/3/2010 8:55:40 PM}
// COMMENT: {3/3/2010 8:55:40 PM}int PushBackEmpty(const char* key)
// COMMENT: {3/3/2010 8:55:40 PM}{
// COMMENT: {3/3/2010 8:55:40 PM} return CSelectedOutput::Instance()->PushBackEmpty(key);
// COMMENT: {3/3/2010 8:55:40 PM}}
void AddSelectedOutput(const char* name, const char* format, va_list argptr)
{
int bInt;
int bDouble;
int bString;
// COMMENT: {3/3/2010 8:58:25 PM}void AddSelectedOutput(const char* name, const char* format, va_list argptr)
// COMMENT: {3/3/2010 8:58:25 PM}{
// COMMENT: {3/3/2010 8:58:25 PM} int bInt;
// COMMENT: {3/3/2010 8:58:25 PM} int bDouble;
// COMMENT: {3/3/2010 8:58:25 PM} int bString;
// COMMENT: {3/3/2010 8:58:25 PM}
// COMMENT: {3/3/2010 8:58:25 PM} int state;
// COMMENT: {3/3/2010 8:58:25 PM} int bLongDouble;
// COMMENT: {3/3/2010 8:58:25 PM} char ch;
// COMMENT: {3/3/2010 8:58:25 PM}
// COMMENT: {3/3/2010 8:58:25 PM}
// COMMENT: {3/3/2010 8:58:25 PM} /* state values
// COMMENT: {3/3/2010 8:58:25 PM} 0 Haven't found start(%)
// COMMENT: {3/3/2010 8:58:25 PM} 1 Just read start(%)
// COMMENT: {3/3/2010 8:58:25 PM} 2 Just read Flags(-0+ #) (zero or more)
// COMMENT: {3/3/2010 8:58:25 PM} 3 Just read Width
// COMMENT: {3/3/2010 8:58:25 PM} 4 Just read Precision start (.)
// COMMENT: {3/3/2010 8:58:25 PM} 5 Just read Size modifier
// COMMENT: {3/3/2010 8:58:25 PM} 6 Just read Type
// COMMENT: {3/3/2010 8:58:25 PM} */
// COMMENT: {3/3/2010 8:58:25 PM}
// COMMENT: {3/3/2010 8:58:25 PM} if (name == NULL) {
// COMMENT: {3/3/2010 8:58:25 PM} return;
// COMMENT: {3/3/2010 8:58:25 PM} }
// COMMENT: {3/3/2010 8:58:25 PM}
// COMMENT: {3/3/2010 8:58:25 PM} bDouble = 0;
// COMMENT: {3/3/2010 8:58:25 PM} bInt = 0;
// COMMENT: {3/3/2010 8:58:25 PM} bString = 0;
// COMMENT: {3/3/2010 8:58:25 PM}
// COMMENT: {3/3/2010 8:58:25 PM} bLongDouble = 0;
// COMMENT: {3/3/2010 8:58:25 PM}
// COMMENT: {3/3/2010 8:58:25 PM} state = 0;
// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++;
// COMMENT: {3/3/2010 8:58:25 PM} while (ch != '\0') {
// COMMENT: {3/3/2010 8:58:25 PM} switch (state) {
// COMMENT: {3/3/2010 8:58:25 PM} case 0: /* looking for Start specification (%) */
// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) {
// COMMENT: {3/3/2010 8:58:25 PM} case '%':
// COMMENT: {3/3/2010 8:58:25 PM} state = 1;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} default:
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} }
// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} case 1: /* reading Flags (zero or more(-,+,0,# or space)) */
// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) {
// COMMENT: {3/3/2010 8:58:25 PM} case '-': case '0': case '+': case ' ': case '#':
// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} default:
// COMMENT: {3/3/2010 8:58:25 PM} state = 2;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} }
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} case 2: /* reading Minimum field width (decimal integer constant) */
// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) {
// COMMENT: {3/3/2010 8:58:25 PM} case '.':
// COMMENT: {3/3/2010 8:58:25 PM} state = 3;
// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} default:
// COMMENT: {3/3/2010 8:58:25 PM} state = 4;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} }
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} case 3: /* reading Precision specification (period already read) */
// COMMENT: {3/3/2010 8:58:25 PM} switch (ch)
// COMMENT: {3/3/2010 8:58:25 PM} {
// COMMENT: {3/3/2010 8:58:25 PM} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} default:
// COMMENT: {3/3/2010 8:58:25 PM} state = 4;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} }
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} case 4: /* reading Size modifier */
// COMMENT: {3/3/2010 8:58:25 PM} switch (ch)
// COMMENT: {3/3/2010 8:58:25 PM} {
// COMMENT: {3/3/2010 8:58:25 PM} case 'l':
// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} case 'L':
// COMMENT: {3/3/2010 8:58:25 PM} bLongDouble = 1;
// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} case 'h':
// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} }
// COMMENT: {3/3/2010 8:58:25 PM} state = 5;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} case 5: /* reading Conversion letter */
// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) {
// COMMENT: {3/3/2010 8:58:25 PM} case 'c':
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} case 'd':
// COMMENT: {3/3/2010 8:58:25 PM} case 'i':
// COMMENT: {3/3/2010 8:58:25 PM} bInt = 1;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} case 'n':
// COMMENT: {3/3/2010 8:58:25 PM} case 'o':
// COMMENT: {3/3/2010 8:58:25 PM} case 'p':
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} case 's':
// COMMENT: {3/3/2010 8:58:25 PM} bString = 1;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} case 'u':
// COMMENT: {3/3/2010 8:58:25 PM} case 'x':
// COMMENT: {3/3/2010 8:58:25 PM} case 'X':
// COMMENT: {3/3/2010 8:58:25 PM} case '%':
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} case 'f':
// COMMENT: {3/3/2010 8:58:25 PM} case 'e':
// COMMENT: {3/3/2010 8:58:25 PM} case 'E':
// COMMENT: {3/3/2010 8:58:25 PM} case 'g':
// COMMENT: {3/3/2010 8:58:25 PM} case 'G':
// COMMENT: {3/3/2010 8:58:25 PM} bDouble = 1;
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} default:
// COMMENT: {3/3/2010 8:58:25 PM} ASSERT(false);
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} }
// COMMENT: {3/3/2010 8:58:25 PM} ch = '\0'; /* done */
// COMMENT: {3/3/2010 8:58:25 PM} break;
// COMMENT: {3/3/2010 8:58:25 PM} }
// COMMENT: {3/3/2010 8:58:25 PM} }
// COMMENT: {3/3/2010 8:58:25 PM}
// COMMENT: {3/3/2010 8:58:25 PM} if (bDouble) {
// COMMENT: {3/3/2010 8:58:25 PM} double valDouble;
// COMMENT: {3/3/2010 8:58:25 PM}
// COMMENT: {3/3/2010 8:58:25 PM} if (bLongDouble) {
// COMMENT: {3/3/2010 8:58:25 PM} valDouble = (double)va_arg(argptr, long double);
// COMMENT: {3/3/2010 8:58:25 PM} }
// COMMENT: {3/3/2010 8:58:25 PM} else {
// COMMENT: {3/3/2010 8:58:25 PM} valDouble = va_arg(argptr, double);
// COMMENT: {3/3/2010 8:58:25 PM} }
// COMMENT: {3/3/2010 8:58:25 PM}
// COMMENT: {3/3/2010 8:58:25 PM} CSelectedOutput::Instance()->PushBackDouble(name, valDouble);
// COMMENT: {3/3/2010 8:58:25 PM} }
// COMMENT: {3/3/2010 8:58:25 PM} else if (bInt) {
// COMMENT: {3/3/2010 8:58:25 PM} int valInt;
// COMMENT: {3/3/2010 8:58:25 PM} valInt = va_arg(argptr, int);
// COMMENT: {3/3/2010 8:58:25 PM}
// COMMENT: {3/3/2010 8:58:25 PM} CSelectedOutput::Instance()->PushBackLong(name, (long)valInt);
// COMMENT: {3/3/2010 8:58:25 PM} }
// COMMENT: {3/3/2010 8:58:25 PM} else if (bString) {
// COMMENT: {3/3/2010 8:58:25 PM} char* valString;
// COMMENT: {3/3/2010 8:58:25 PM} valString = (char *)va_arg(argptr, char *);
// COMMENT: {3/3/2010 8:58:25 PM}
// COMMENT: {3/3/2010 8:58:25 PM} CSelectedOutput::Instance()->PushBackString(name, valString);
// COMMENT: {3/3/2010 8:58:25 PM} }
// COMMENT: {3/3/2010 8:58:25 PM} else {
// COMMENT: {3/3/2010 8:58:25 PM} ASSERT(false);
// COMMENT: {3/3/2010 8:58:25 PM} CSelectedOutput::Instance()->PushBackEmpty(name);
// COMMENT: {3/3/2010 8:58:25 PM} }
// COMMENT: {3/3/2010 8:58:25 PM}}
int state;
int bLongDouble;
char ch;
/* state values
0 Haven't found start(%)
1 Just read start(%)
2 Just read Flags(-0+ #) (zero or more)
3 Just read Width
4 Just read Precision start (.)
5 Just read Size modifier
6 Just read Type
*/
if (name == NULL) {
return;
}
bDouble = 0;
bInt = 0;
bString = 0;
bLongDouble = 0;
state = 0;
ch = *format++;
while (ch != '\0') {
switch (state) {
case 0: /* looking for Start specification (%) */
switch (ch) {
case '%':
state = 1;
break;
default:
break;
}
ch = *format++;
break;
case 1: /* reading Flags (zero or more(-,+,0,# or space)) */
switch (ch) {
case '-': case '0': case '+': case ' ': case '#':
ch = *format++;
break;
default:
state = 2;
break;
}
break;
case 2: /* reading Minimum field width (decimal integer constant) */
switch (ch) {
case '.':
state = 3;
ch = *format++;
break;
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
ch = *format++;
break;
default:
state = 4;
break;
}
break;
case 3: /* reading Precision specification (period already read) */
switch (ch)
{
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
ch = *format++;
break;
default:
state = 4;
break;
}
break;
case 4: /* reading Size modifier */
switch (ch)
{
case 'l':
ch = *format++;
break;
case 'L':
bLongDouble = 1;
ch = *format++;
break;
case 'h':
ch = *format++;
break;
}
state = 5;
break;
case 5: /* reading Conversion letter */
switch (ch) {
case 'c':
break;
case 'd':
case 'i':
bInt = 1;
break;
case 'n':
case 'o':
case 'p':
break;
case 's':
bString = 1;
break;
case 'u':
case 'x':
case 'X':
case '%':
break;
case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
bDouble = 1;
break;
default:
ASSERT(false);
break;
}
ch = '\0'; /* done */
break;
}
}
if (bDouble) {
double valDouble;
if (bLongDouble) {
valDouble = (double)va_arg(argptr, long double);
}
else {
valDouble = va_arg(argptr, double);
}
CSelectedOutput::Instance()->PushBackDouble(name, valDouble);
}
else if (bInt) {
int valInt;
valInt = va_arg(argptr, int);
CSelectedOutput::Instance()->PushBackLong(name, (long)valInt);
}
else if (bString) {
char* valString;
valString = (char *)va_arg(argptr, char *);
CSelectedOutput::Instance()->PushBackString(name, valString);
}
else {
ASSERT(false);
CSelectedOutput::Instance()->PushBackEmpty(name);
}
}
// COMMENT: {11/16/2004 10:18:22 PM}CSelectedOutput CSelectedOutput::singleton;
CSelectedOutput* CSelectedOutput::s_instance = 0;
CSelectedOutput* CSelectedOutput::Instance()
{
if (s_instance == 0)
{
s_instance = new CSelectedOutput;
}
return s_instance;
}
void CSelectedOutput::Release()
{
if (s_instance)
{
delete s_instance;
s_instance = 0;
}
}
// COMMENT: {3/3/2010 8:56:03 PM}// COMMENT: {11/16/2004 10:18:22 PM}CSelectedOutput CSelectedOutput::singleton;
// COMMENT: {3/3/2010 8:56:03 PM}CSelectedOutput* CSelectedOutput::s_instance = 0;
// COMMENT: {3/3/2010 8:56:03 PM}
// COMMENT: {3/3/2010 8:56:03 PM}CSelectedOutput* CSelectedOutput::Instance()
// COMMENT: {3/3/2010 8:56:03 PM}{
// COMMENT: {3/3/2010 8:56:03 PM} if (s_instance == 0)
// COMMENT: {3/3/2010 8:56:03 PM} {
// COMMENT: {3/3/2010 8:56:03 PM} s_instance = new CSelectedOutput;
// COMMENT: {3/3/2010 8:56:03 PM} }
// COMMENT: {3/3/2010 8:56:03 PM} return s_instance;
// COMMENT: {3/3/2010 8:56:03 PM}}
// COMMENT: {3/3/2010 8:56:03 PM}
// COMMENT: {3/3/2010 8:56:03 PM}void CSelectedOutput::Release()
// COMMENT: {3/3/2010 8:56:03 PM}{
// COMMENT: {3/3/2010 8:56:03 PM} if (s_instance)
// COMMENT: {3/3/2010 8:56:03 PM} {
// COMMENT: {3/3/2010 8:56:03 PM} delete s_instance;
// COMMENT: {3/3/2010 8:56:03 PM} s_instance = 0;
// COMMENT: {3/3/2010 8:56:03 PM} }
// COMMENT: {3/3/2010 8:56:03 PM}}
CSelectedOutput::CSelectedOutput()
: m_nRowCount(0)

View File

@ -18,15 +18,10 @@
// TODO: templatize
class CSelectedOutput
{
protected:
CSelectedOutput(void);
public:
static CSelectedOutput* Instance();
static void Release();
CSelectedOutput(void);
virtual ~CSelectedOutput(void);
int EndRow(void);
void Clear(void);

4
Var.c
View File

@ -8,7 +8,9 @@
//
void VarInit(VAR* pvar)
{
pvar->type = TT_EMPTY;
pvar->type = TT_EMPTY;
pvar->sVal = 0;
pvar->vresult = VR_OK;
}
VRESULT VarClear(VAR* pvar)

View File

@ -4,9 +4,7 @@
#include <assert.h> /* assert */
#include <stdio.h> /* printf */
#define EXTERNAL extern
#include "phreeqcpp/phreeqc/global.h"
#undef EXTERNAL
#include "phrqtype.h"
struct buffer {
char *name;
@ -35,8 +33,7 @@ extern int store_tally_table(double *array, int row_dim, int col_dim);
extern int warning_msg (const char *err_str);
extern int zero_tally_table(void);
#include "../include/IPhreeqc.h"
#include "IPhreeqc.h"
/*******************************
When using GNU gcc/g++/g77

View File

@ -1,5 +0,0 @@
#define EXTERNAL
#define MAIN
// TEST RMWEBB WRITE ACCESS
#include "global.h"
#include "phqalloc.h"

View File

@ -5,33 +5,35 @@
#include "phreeqcpp/phreeqc/phreeqc_files.c"
#endif
static int module_isopen_handler(const int type);
static int module_open_handler(const int type, const char *file_name);
// COMMENT: {3/2/2010 4:06:35 PM}static int module_isopen_handler(const int type);
// COMMENT: {3/2/2010 4:06:35 PM}static int module_open_handler(const int type, const char *file_name);
int
module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args)
#include "IPhreeqc.hpp"
int IPhreeqc::module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args)
{
IPhreeqc* pThis = (IPhreeqc*) cookie;
switch (action) {
case ACTION_OPEN:
return module_open_handler(type, err_str);
return pThis->module_open_handler(type, err_str);
break;
case ACTION_ISOPEN:
return module_isopen_handler(type);
return pThis->module_isopen_handler(type);
break;
default:
return phreeqc_handler(action, type, err_str, stop, cookie, format, args);
return pThis->phreeqc_handler(action, type, err_str, stop, cookie, format, args);
break;
}
return ERROR;
}
static int
module_isopen_handler(const int type)
int IPhreeqc::module_isopen_handler(const int type)
{
switch (type)
{
case OUTPUT_PUNCH:
if (punch_file) return 1;
if (this->punch_file) return 1;
break;
default:
assert(0);
@ -39,51 +41,52 @@ module_isopen_handler(const int type)
return 0;
}
static int
module_open_handler(const int type, const char *file_name)
int IPhreeqc::module_open_handler(const int type, const char *file_name)
{
assert(file_name && strlen(file_name));
assert(file_name && ::strlen(file_name));
switch (type)
{
case OUTPUT_MESSAGE:
if (output != NULL)
if (this->output != NULL)
{
fclose(output);
output = NULL;
::fclose(this->output);
this->output = NULL;
}
if ( (output = fopen(file_name, "w")) == NULL)
if ( (this->output = ::fopen(file_name, "w")) == NULL)
{
return ERROR;
}
break;
case OUTPUT_ERROR:
assert(error_file != stderr);
if (error_file != NULL)
assert(this->error_file != stderr);
if (this->error_file != NULL)
{
fclose(error_file);
error_file = NULL;
::fclose(this->error_file);
this->error_file = NULL;
}
if ( (error_file = fopen(file_name, "w")) == NULL)
if ( (this->error_file = ::fopen(file_name, "w")) == NULL)
{
return ERROR;
}
break;
case OUTPUT_LOG:
if (log_file != NULL)
if (this->log_file != NULL)
{
fclose(log_file);
log_file = NULL;
::fclose(this->log_file);
this->log_file = NULL;
}
if ( (log_file = fopen(file_name, "w")) == NULL)
if ( (this->log_file = ::fopen(file_name, "w")) == NULL)
{
return ERROR;
}
break;
default:
return open_handler(type, file_name);
return this->Phreeqc::open_handler(type, file_name);
break;
}
return(OK);
}

View File

@ -9,8 +9,8 @@
extern "C" {
#endif
int module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args);
int output_isopen(const int type);
// COMMENT: {3/2/2010 4:07:45 PM}int module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args);
// COMMENT: {3/2/2010 4:07:45 PM}int output_isopen(const int type);
typedef enum {

View File

@ -1,5 +1,7 @@
#include "module_files.h"
#include "IPhreeqc.hpp"
#if defined(R_SO)
#include "output.inl"
#else
@ -7,14 +9,13 @@
#endif
/* ---------------------------------------------------------------------- */
int output_isopen(const int type)
/* ---------------------------------------------------------------------- */
int IPhreeqc::output_isopen(const int type)
{
size_t i;
int isopen;
for (i = 0; i < count_output_callback; ++i) {
isopen = (output_callbacks[i].callback)(ACTION_ISOPEN, type, NULL, CONTINUE, output_callbacks[i].cookie, NULL, NULL);
for (i = 0; i < this->count_output_callback; ++i)
{
isopen = (this->output_callbacks[i].callback)(ACTION_ISOPEN, type, NULL, CONTINUE, this->output_callbacks[i].cookie, NULL, NULL);
if (isopen) return 1;
}
return 0;

View File

@ -11,6 +11,7 @@
#include <math.h>
#if !defined(PHREEQC_CLASS)
#define EXTERNAL extern
#include "global.h"
@ -21,6 +22,7 @@
EXTERNAL int n_user_punch_index;
#undef EXTERNAL
#endif
#endif /* _INC_GLOBALNS */