passes all tests on win32; before changing to multiple instances

git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4201 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2010-04-02 00:14:16 +00:00
parent dafa59942f
commit 4463d41703
15 changed files with 4504 additions and 553 deletions

View File

@ -25,6 +25,11 @@ Project("{6989167D-11E4-40FE-8C1A-2192A86A7E90}") = "test_getline", "test_getlin
{F9C18E06-F73A-4EB0-92E0-AE1713EA7FD7} = {F9C18E06-F73A-4EB0-92E0-AE1713EA7FD7} {F9C18E06-F73A-4EB0-92E0-AE1713EA7FD7} = {F9C18E06-F73A-4EB0-92E0-AE1713EA7FD7}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testcpp", "testcpp\testcpp.vcproj", "{046110C9-CD5B-404D-B197-E295656CBF7F}"
ProjectSection(ProjectDependencies) = postProject
{F9C18E06-F73A-4EB0-92E0-AE1713EA7FD7} = {F9C18E06-F73A-4EB0-92E0-AE1713EA7FD7}
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32 Debug|Win32 = Debug|Win32
@ -68,6 +73,12 @@ Global
{D95AB257-163E-4ABD-8577-94FB8D1EF62C}.MemDebug|Win32.Build.0 = Debug|Win32 {D95AB257-163E-4ABD-8577-94FB8D1EF62C}.MemDebug|Win32.Build.0 = Debug|Win32
{D95AB257-163E-4ABD-8577-94FB8D1EF62C}.Release|Win32.ActiveCfg = Release|Win32 {D95AB257-163E-4ABD-8577-94FB8D1EF62C}.Release|Win32.ActiveCfg = Release|Win32
{D95AB257-163E-4ABD-8577-94FB8D1EF62C}.Release|Win32.Build.0 = Release|Win32 {D95AB257-163E-4ABD-8577-94FB8D1EF62C}.Release|Win32.Build.0 = Release|Win32
{046110C9-CD5B-404D-B197-E295656CBF7F}.Debug|Win32.ActiveCfg = Debug|Win32
{046110C9-CD5B-404D-B197-E295656CBF7F}.Debug|Win32.Build.0 = Debug|Win32
{046110C9-CD5B-404D-B197-E295656CBF7F}.MemDebug|Win32.ActiveCfg = Debug|Win32
{046110C9-CD5B-404D-B197-E295656CBF7F}.MemDebug|Win32.Build.0 = Debug|Win32
{046110C9-CD5B-404D-B197-E295656CBF7F}.Release|Win32.ActiveCfg = Release|Win32
{046110C9-CD5B-404D-B197-E295656CBF7F}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -117,7 +117,7 @@
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="$(DEV_GMP_INC);include;src;src/phreeqcpp;src/phreeqcpp/phreeqc" AdditionalIncludeDirectories="include;src;src/phreeqcpp;src/phreeqcpp/phreeqc"
PreprocessorDefinitions="_DEBUG;WIN32;_LIB;SWIG_SHARED_OBJ;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;PHREEQC_CPP;PHREEQC_CLASS;USE_PHRQ_ALLOC" PreprocessorDefinitions="_DEBUG;WIN32;_LIB;SWIG_SHARED_OBJ;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;PHREEQC_CPP;PHREEQC_CLASS;USE_PHRQ_ALLOC"
MinimalRebuild="true" MinimalRebuild="true"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
@ -317,6 +317,14 @@
RelativePath=".\src\IPhreeqc.cpp" RelativePath=".\src\IPhreeqc.cpp"
> >
</File> </File>
<File
RelativePath=".\src\IPhreeqc2.cpp"
>
</File>
<File
RelativePath=".\src\IPhreeqcLib.cpp"
>
</File>
<File <File
RelativePath=".\src\module_files.cpp" RelativePath=".\src\module_files.cpp"
> >
@ -800,6 +808,7 @@
> >
<FileConfiguration <FileConfiguration
Name="Release|Win32" Name="Release|Win32"
ExcludedFromBuild="true"
> >
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
@ -810,6 +819,7 @@
</FileConfiguration> </FileConfiguration>
<FileConfiguration <FileConfiguration
Name="Debug|Win32" Name="Debug|Win32"
ExcludedFromBuild="true"
> >
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
@ -820,6 +830,7 @@
</FileConfiguration> </FileConfiguration>
<FileConfiguration <FileConfiguration
Name="MemDebug|Win32" Name="MemDebug|Win32"
ExcludedFromBuild="true"
> >
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
@ -1313,26 +1324,26 @@
> >
<FileConfiguration <FileConfiguration
Name="Release|Win32" Name="Release|Win32"
ExcludedFromBuild="true"
> >
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
CompileAs="2"
/> />
</FileConfiguration> </FileConfiguration>
<FileConfiguration <FileConfiguration
Name="Debug|Win32" Name="Debug|Win32"
ExcludedFromBuild="true"
> >
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
CompileAs="2"
/> />
</FileConfiguration> </FileConfiguration>
<FileConfiguration <FileConfiguration
Name="MemDebug|Win32" Name="MemDebug|Win32"
ExcludedFromBuild="true"
> >
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
CompileAs="2"
/> />
</FileConfiguration> </FileConfiguration>
</File> </File>
@ -1443,7 +1454,6 @@
> >
<FileConfiguration <FileConfiguration
Name="Release|Win32" Name="Release|Win32"
ExcludedFromBuild="true"
> >
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
@ -1454,7 +1464,6 @@
</FileConfiguration> </FileConfiguration>
<FileConfiguration <FileConfiguration
Name="Debug|Win32" Name="Debug|Win32"
ExcludedFromBuild="true"
> >
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
@ -1465,7 +1474,6 @@
</FileConfiguration> </FileConfiguration>
<FileConfiguration <FileConfiguration
Name="MemDebug|Win32" Name="MemDebug|Win32"
ExcludedFromBuild="true"
> >
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
@ -2040,6 +2048,14 @@
RelativePath=".\src\IPhreeqc.hpp" RelativePath=".\src\IPhreeqc.hpp"
> >
</File> </File>
<File
RelativePath=".\IPhreeqc2.h"
>
</File>
<File
RelativePath=".\include\IPhreeqcLib.h"
>
</File>
<File <File
RelativePath="src\module_files.h" RelativePath="src\module_files.h"
> >

View File

@ -75,8 +75,6 @@ public:
// Singleton for library // Singleton for library
static IPhreeqc* LibraryInstance(void); static IPhreeqc* LibraryInstance(void);
static int Create(void);
static void Destroy(int n);
// Callbacks // Callbacks
// //
@ -101,7 +99,6 @@ public:
void do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie); void do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie);
protected: protected:
void init(void);
void update_errors(void); void update_errors(void);
protected: protected:

134
include/IPhreeqc2.h Normal file
View File

@ -0,0 +1,134 @@
#ifndef _INC_IPHREEQC2_HPP
#define _INC_IPHREEQC2_HPP
#include <exception>
#include <list>
#include <vector>
#include "IPhreeqcCallbacks.h" /* PFN_PRERUN_CALLBACK, PFN_POSTRUN_CALLBACK, PFN_CATCH_CALLBACK */
#include "Var.h" /* VRESULT */
// COMMENT: {3/31/2010 4:21:28 PM}#include "SelectedOutput.hxx"
class Phreeqc;
class IErrorReporter;
class CSelectedOutput;
class IPhreeqcStop : std::exception
{
};
class IPhreeqc2
{
public:
IPhreeqc2(void);
~IPhreeqc2(void);
public:
const char* GetLastErrorString(void);
const char* GetLastWarningString(void);
const char* GetDumpString(void);
int LoadDatabase(const char* filename);
int LoadDatabaseString(const char* input);
void UnLoadDatabase(void);
size_t AddError(const char* error_msg);
size_t AddWarning(const char* warning_msg);
int RunAccumulated(void);
int RunFile(const char* filename);
int RunString(const char* input);
int GetSelectedOutputRowCount(void)const;
int GetSelectedOutputColumnCount(void)const;
VRESULT GetSelectedOutputValue(int row, int col, VAR* pVAR);
void OutputLines(void);
const std::string& GetAccumulatedLines(void);
void ClearAccumulatedLines(void);
VRESULT AccumulateLine(const char *line);
int GetDumpLineCount(void)const;
const char* GetDumpLine(int n);
int GetErrorLineCount(void)const;
const char* GetErrorLine(int n);
std::list< std::string > ListComponents(void);
size_t GetComponentCount(void);
const char* GetComponent(int n);
bool GetDumpOn(void)const;
void SetDumpOn(bool bValue);
bool GetDumpStringOn(void)const;
void SetDumpStringOn(bool bValue);
bool GetErrorOn(void)const;
void SetErrorOn(bool bValue);
bool GetLogOn(void)const;
void SetLogOn(bool bValue);
bool GetOutputOn(void)const;
void SetOutputOn(bool bValue);
bool GetSelectedOutputOn(void)const;
void SetSelectedOutputOn(bool bValue);
// IPhreeqc.cpp
static int handler2(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args);
int output_handler2(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args);
int open_handler2(const int type, const char *file_name);
// module_files.c
static int module_handler2(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args);
int module_isopen_handler2(const int type);
int module_open_handler2(const int type, const char *file_name);
// module_output.c
int output_isopen2(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, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie);
protected:
void update_errors(void);
protected:
bool DatabaseLoaded;
bool SelectedOutputOn;
bool OutputOn;
bool LogOn;
bool ErrorOn;
bool DumpOn;
bool DumpStringOn;
IErrorReporter *ErrorReporter;
std::string LastErrorString;
std::vector< std::string > ErrorLines;
IErrorReporter *WarningReporter;
std::string LastWarningString;
std::vector< std::string > WarningLines;
CSelectedOutput *SelectedOutput;
std::string PunchFileName;
std::string StringInput;
std::string DumpString;
std::vector< std::string > DumpLines;
std::list < std::string > Components;
private:
friend class TestIPhreeqc;
Phreeqc* PhreeqcPtr;
};
#endif // _INC_IPHREEQC2_HPP

96
include/IPhreeqcLib.h Normal file
View File

@ -0,0 +1,96 @@
#ifndef __IPHREEQC_LIB_H
#define __IPHREEQC_LIB_H
#include <map>
#include "Var.h"
/*! \brief Enumeration used to return error codes.
*/
typedef enum {
IPL_OK = 0,
IPL_OUTOFMEMORY = -1,
IPL_BADINSTANCE = -2,
IPL_BADVARTYPE = -3,
IPL_INVALIDARG = -4,
IPL_INVALIDROW = -5,
IPL_INVALIDCOL = -6,
} IPL_RESULT;
class IPhreeqc2;
#if defined(__cplusplus)
extern "C" {
#endif
int AddErrorM(int id, const char* error_msg);
int CreateIPhreeqc(void);
IPL_RESULT DestroyIPhreeqc(int id);
int LoadDatabaseM(int id, const char* filename);
int LoadDatabaseStringM(int id, const char* input);
int UnLoadDatabaseM(int id);
const char* GetLastErrorStringM(int id);
const char* GetDumpStringM(int id);
int GetDumpLineCountM(int id);
const char* GetDumpLineM(int id, int n);
IPL_RESULT AccumulateLineM(int id, const char *line);
int GetSelectedOutputOnM(int id);
IPL_RESULT SetSelectedOutputOnM(int id, int value);
int GetOutputOnM(int id);
IPL_RESULT SetOutputOnM(int id, int value);
int GetErrorOnM(int id);
IPL_RESULT SetErrorOnM(int id, int value);
int GetLogOnM(int id);
IPL_RESULT SetLogOnM(int id, int value);
int GetDumpOnM(int id);
IPL_RESULT SetDumpOnM(int id, int value);
int GetDumpStringOnM(int id);
IPL_RESULT SetDumpStringOnM(int id, int value);
int RunAccumulatedM(int id);
int RunFileM(int id, const char* filename);
int GetSelectedOutputRowCountM(int id);
int GetSelectedOutputColumnCountM(int id);
IPL_RESULT GetSelectedOutputValueM(int id, int row, int col, VAR* pVAR);
int GetComponentCountM(int id);
const char* GetComponentM(int id, int n);
#if defined(__cplusplus)
}
#endif
class IPhreeqcLib
{
public:
static int CreateIPhreeqc(void);
static IPL_RESULT DestroyIPhreeqc(int n);
static IPhreeqc2* GetInstance(int n);
private:
static std::map<size_t, IPhreeqc2*> Instances;
static size_t InstancesIndex;
};
#endif // __IPHREEQC_LIB_H

File diff suppressed because it is too large Load Diff

1257
src/IPhreeqc2.cpp Normal file

File diff suppressed because it is too large Load Diff

468
src/IPhreeqcLib.cpp Normal file
View File

@ -0,0 +1,468 @@
#include "IPhreeqcLib.h"
#include "IPhreeqc2.h"
#include <cassert>
int
CreateIPhreeqc(void)
{
return IPhreeqcLib::CreateIPhreeqc();
}
IPL_RESULT
DestroyIPhreeqc(int n)
{
return IPhreeqcLib::DestroyIPhreeqc(n);
}
int
LoadDatabaseM(int n, const char* filename)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
return IPhreeqcPtr->LoadDatabase(filename);
}
return IPL_BADINSTANCE;
}
int
LoadDatabaseStringM(int n, const char* input)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
return IPhreeqcPtr->LoadDatabaseString(input);
}
return IPL_BADINSTANCE;
}
int
UnLoadDatabaseM(int n)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
IPhreeqcPtr->UnLoadDatabase();
return IPL_OK;
}
return IPL_BADINSTANCE;
}
const char*
GetLastErrorStringM(int n)
{
static const char err_msg[] = "GetLastErrorString: Bad instance.\n";
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
return IPhreeqcPtr->GetLastErrorString();
}
return err_msg;
}
const char*
GetDumpStringM(int n)
{
static const char empty[] = "";
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
return IPhreeqcPtr->GetDumpString();
}
return empty;
}
int
GetDumpLineCountM(int n)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
return IPhreeqcPtr->GetDumpLineCount();
}
return 0;
}
const char*
GetDumpLineM(int id, int n)
{
static const char err_msg[] = "GetDumpLine: Bad instance.\n";
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
if (IPhreeqcPtr)
{
return IPhreeqcPtr->GetDumpLine(n);
}
return err_msg;
}
int
GetComponentCountM(int id)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
if (IPhreeqcPtr)
{
return IPhreeqcPtr->ListComponents().size();
}
return 0;
}
const char*
GetComponentM(int id, int n)
{
static const char err_msg[] = "GetComponent: Bad instance.\n";
static const char empty[] = "";
static std::string comp;
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
if (IPhreeqcPtr)
{
std::list< std::string > comps = IPhreeqcPtr->ListComponents();
if (n < 0 || n >= (int)comps.size())
{
return empty;
}
std::list< std::string >::iterator it = comps.begin();
for(int i = 0; i < n; ++i)
{
++it;
}
comp = (*it);
return comp.c_str();
}
return err_msg;
}
IPL_RESULT
AccumulateLineM(int n, const char *line)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
switch (IPhreeqcPtr->AccumulateLine(line))
{
case VR_OK:
return IPL_OK;
case VR_OUTOFMEMORY:
return IPL_OUTOFMEMORY;
default:
assert(false);
}
}
return IPL_BADINSTANCE;
}
int
GetSelectedOutputOnM(int n)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
if (IPhreeqcPtr->GetSelectedOutputOn())
{
return 1;
}
else
{
return 0;
}
}
return IPL_BADINSTANCE;
}
IPL_RESULT
SetSelectedOutputOnM(int n, int value)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
IPhreeqcPtr->SetSelectedOutputOn(value != 0);
return IPL_OK;
}
return IPL_BADINSTANCE;
}
int
GetOutputOnM(int n)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
if (IPhreeqcPtr->GetOutputOn())
{
return 1;
}
else
{
return 0;
}
}
return IPL_BADINSTANCE;
}
IPL_RESULT
SetOutputOnM(int n, int value)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
IPhreeqcPtr->SetOutputOn(value != 0);
return IPL_OK;
}
return IPL_BADINSTANCE;
}
int
GetErrorOnM(int n)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
if (IPhreeqcPtr->GetErrorOn())
{
return 1;
}
else
{
return 0;
}
}
return IPL_BADINSTANCE;
}
IPL_RESULT
SetErrorOnM(int n, int value)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
IPhreeqcPtr->SetErrorOn(value != 0);
return IPL_OK;
}
return IPL_BADINSTANCE;
}
int
GetLogOnM(int n)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
if (IPhreeqcPtr->GetLogOn())
{
return 1;
}
else
{
return 0;
}
}
return IPL_BADINSTANCE;
}
IPL_RESULT
SetLogOnM(int n, int value)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
IPhreeqcPtr->SetLogOn(value != 0);
return IPL_OK;
}
return IPL_BADINSTANCE;
}
int
GetDumpOnM(int n)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
if (IPhreeqcPtr->GetDumpOn())
{
return 1;
}
else
{
return 0;
}
}
return IPL_BADINSTANCE;
}
IPL_RESULT
SetDumpOnM(int n, int value)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
IPhreeqcPtr->SetDumpOn(value != 0);
return IPL_OK;
}
return IPL_BADINSTANCE;
}
int
GetDumpStringOnM(int n)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
if (IPhreeqcPtr->GetDumpStringOn())
{
return 1;
}
else
{
return 0;
}
}
return IPL_BADINSTANCE;
}
IPL_RESULT
SetDumpStringOnM(int n, int value)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
IPhreeqcPtr->SetDumpStringOn(value != 0);
return IPL_OK;
}
return IPL_BADINSTANCE;
}
int
RunAccumulatedM(int n)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
return IPhreeqcPtr->RunAccumulated();
}
return IPL_BADINSTANCE;
}
int
RunFileM(int n, const char* filename)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
return IPhreeqcPtr->RunFile(filename);
}
return IPL_BADINSTANCE;
}
int
GetSelectedOutputRowCountM(int n)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
return IPhreeqcPtr->GetSelectedOutputRowCount();
}
return IPL_BADINSTANCE;
}
int
GetSelectedOutputColumnCountM(int n)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
return IPhreeqcPtr->GetSelectedOutputColumnCount();
}
return IPL_BADINSTANCE;
}
IPL_RESULT
GetSelectedOutputValueM(int n, int row, int col, VAR* pVAR)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
switch(IPhreeqcPtr->GetSelectedOutputValue(row, col, pVAR))
{
case VR_OK: return IPL_OK;
case VR_OUTOFMEMORY: return IPL_OUTOFMEMORY;
case VR_BADVARTYPE: return IPL_BADVARTYPE;
case VR_INVALIDARG: return IPL_INVALIDARG;
case VR_INVALIDROW: return IPL_INVALIDROW;
case VR_INVALIDCOL: return IPL_INVALIDCOL;
default:
assert(false);
}
}
return IPL_BADINSTANCE;
}
int
AddErrorM(int n, const char* error_msg)
{
IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n);
if (IPhreeqcPtr)
{
return (int)IPhreeqcPtr->AddError(error_msg);
}
return IPL_BADINSTANCE;
}
std::map<size_t, IPhreeqc2*> IPhreeqcLib::Instances;
size_t IPhreeqcLib::InstancesIndex = 0;
int
IPhreeqcLib::CreateIPhreeqc(void)
{
int n = IPL_OUTOFMEMORY;
try
{
IPhreeqc2* IPhreeqcPtr = new IPhreeqc2;
if (IPhreeqcPtr)
{
std::map<size_t, IPhreeqc2*>::value_type instance(IPhreeqcLib::InstancesIndex, IPhreeqcPtr);
std::pair<std::map<size_t, IPhreeqc2*>::iterator, bool> pr = IPhreeqcLib::Instances.insert(instance);
if (pr.second)
{
n = (int) (*pr.first).first;
++IPhreeqcLib::InstancesIndex;
}
}
}
catch(...)
{
return IPL_OUTOFMEMORY;
}
return n;
}
IPL_RESULT
IPhreeqcLib::DestroyIPhreeqc(int n)
{
IPL_RESULT retval = IPL_BADINSTANCE;
if (n >= 0)
{
std::map<size_t, IPhreeqc2*>::iterator it = IPhreeqcLib::Instances.find(size_t(n));
if (it != IPhreeqcLib::Instances.end())
{
delete (*it).second;
IPhreeqcLib::Instances.erase(it);
retval = IPL_OK;
}
}
return retval;
}
IPhreeqc2*
IPhreeqcLib::GetInstance(int n)
{
std::map<size_t, IPhreeqc2*>::iterator it = IPhreeqcLib::Instances.find(size_t(n));
if (it != IPhreeqcLib::Instances.end())
{
return (*it).second;
}
return 0;
}

View File

@ -2,12 +2,15 @@
#if defined(R_SO) #if defined(R_SO)
#include "phreeqc_files.inl" #include "phreeqc_files.inl"
#else #else
#include "phreeqcpp/phreeqc/phreeqc_files.c" // COMMENT: {3/25/2010 12:36:14 PM}#include "phreeqcpp/phreeqc/phreeqc_files.c"
#endif #endif
// 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_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); // COMMENT: {3/2/2010 4:06:35 PM}static int module_open_handler(const int type, const char *file_name);
//{{{3/25/2010 12:37:19 PM}
#include <cassert>
//}}{3/25/2010 12:37:19 PM}
#include "IPhreeqc.hpp" #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) 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)

View File

@ -5,7 +5,7 @@
#if defined(R_SO) #if defined(R_SO)
#include "output.inl" #include "output.inl"
#else #else
#include "phreeqcpp/phreeqc/output.c" // COMMENT: {3/25/2010 12:36:24 PM}#include "phreeqcpp/phreeqc/output.c"
#endif #endif

71
testcpp/ex1 Normal file
View File

@ -0,0 +1,71 @@
TITLE Example 1.--Add uranium and speciate seawater.
SOLUTION 1 SEAWATER FROM NORDSTROM ET AL. (1979)
units ppm
pH 8.22
pe 8.451
density 1.023
temp 25.0
redox O(0)/O(-2)
Ca 412.3
Mg 1291.8
Na 10768.0
K 399.1
Fe 0.002
Mn 0.0002 pe
Si 4.28
Cl 19353.0
Alkalinity 141.682 as HCO3
S(6) 2712.0
N(5) 0.29 gfw 62.0
N(-3) 0.03 as NH4
U 3.3 ppb N(5)/N(-3)
O(0) 1.0 O2(g) -0.7
SOLUTION_MASTER_SPECIES
U U+4 0.0 238.0290 238.0290
U(4) U+4 0.0 238.0290
U(5) UO2+ 0.0 238.0290
U(6) UO2+2 0.0 238.0290
SOLUTION_SPECIES
#primary master species for U
#is also secondary master species for U(4)
U+4 = U+4
log_k 0.0
U+4 + 4 H2O = U(OH)4 + 4 H+
log_k -8.538
delta_h 24.760 kcal
U+4 + 5 H2O = U(OH)5- + 5 H+
log_k -13.147
delta_h 27.580 kcal
#secondary master species for U(5)
U+4 + 2 H2O = UO2+ + 4 H+ + e-
log_k -6.432
delta_h 31.130 kcal
#secondary master species for U(6)
U+4 + 2 H2O = UO2+2 + 4 H+ + 2 e-
log_k -9.217
delta_h 34.430 kcal
UO2+2 + H2O = UO2OH+ + H+
log_k -5.782
delta_h 11.015 kcal
2UO2+2 + 2H2O = (UO2)2(OH)2+2 + 2H+
log_k -5.626
delta_h -36.04 kcal
3UO2+2 + 5H2O = (UO2)3(OH)5+ + 5H+
log_k -15.641
delta_h -44.27 kcal
UO2+2 + CO3-2 = UO2CO3
log_k 10.064
delta_h 0.84 kcal
UO2+2 + 2CO3-2 = UO2(CO3)2-2
log_k 16.977
delta_h 3.48 kcal
UO2+2 + 3CO3-2 = UO2(CO3)3-4
log_k 21.397
delta_h -8.78 kcal
PHASES
Uraninite
UO2 + 4 H+ = U+4 + 2 H2O
log_k -3.490
delta_h -18.630 kcal
END

1556
testcpp/phreeqc.dat Normal file

File diff suppressed because it is too large Load Diff

24
testcpp/testcpp.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <iostream>
#include <IPhreeqc2.h>
#define IPhreeqc IPhreeqc2
int main(int argc, char* argv[])
{
IPhreeqc obj;
obj.SetOutputOn(true);
if (obj.LoadDatabase("phreeqc.dat"))
{
goto error;
}
if (obj.RunFile("ex1"))
{
goto error;
}
std::cout << "Ok\n";
return 0;
error:
std::cout << obj.GetLastErrorString();
return 1;
}

204
testcpp/testcpp.vcproj Normal file
View File

@ -0,0 +1,204 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="testcpp"
ProjectGUID="{046110C9-CD5B-404D-B197-E295656CBF7F}"
RootNamespace="testcpp"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="IPhreeqcd.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="../lib"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="IPhreeqc.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="../lib"
IgnoreDefaultLibraryNames=""
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\testcpp.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioUserFile
ProjectType="Visual C++"
Version="8.00"
ShowAllFiles="false"
>
<Configurations>
<Configuration
Name="Debug|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="IGSKAHHWWSNY5H1"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
<Configuration
Name="Release|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="IGSKAHHWWSNY5H1"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
</Configurations>
</VisualStudioUserFile>