changes req'd for multi_punch

git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/multi_punch@7967 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2013-08-27 05:07:46 +00:00
parent a0db8567c1
commit 2ae3e40889
2 changed files with 128 additions and 45 deletions

View File

@ -42,7 +42,7 @@ IPhreeqc::IPhreeqc(void)
, WarningStringOn(true) , WarningStringOn(true)
, WarningReporter(0) , WarningReporter(0)
, CurrentSelectedOutputUserNumber(1) , CurrentSelectedOutputUserNumber(1)
, PtrSelectedOutput(0) // COMMENT: {8/23/2013 9:33:02 PM}, PtrSelectedOutput(0)
, SelectedOutputStringOn(false) , SelectedOutputStringOn(false)
, PhreeqcPtr(0) , PhreeqcPtr(0)
, input_file(0) , input_file(0)
@ -52,7 +52,7 @@ IPhreeqc::IPhreeqc(void)
this->ErrorReporter = new CErrorReporter<std::ostringstream>; this->ErrorReporter = new CErrorReporter<std::ostringstream>;
this->WarningReporter = new CErrorReporter<std::ostringstream>; this->WarningReporter = new CErrorReporter<std::ostringstream>;
this->PtrSelectedOutput = new CSelectedOutput(); // COMMENT: {8/23/2013 9:33:08 PM} this->PtrSelectedOutput = new CSelectedOutput();
this->PhreeqcPtr = new Phreeqc(this); this->PhreeqcPtr = new Phreeqc(this);
ASSERT(this->PhreeqcPtr->phast == 0); ASSERT(this->PhreeqcPtr->phast == 0);
@ -86,10 +86,16 @@ IPhreeqc::~IPhreeqc(void)
this->OutputFileOn = false; this->OutputFileOn = false;
#endif #endif
delete this->PhreeqcPtr; delete this->PhreeqcPtr;
delete this->PtrSelectedOutput;
delete this->WarningReporter; delete this->WarningReporter;
delete this->ErrorReporter; delete this->ErrorReporter;
std::map< int, CSelectedOutput* >::iterator sit = this->SelectedOutputMap.begin();
for (; sit != this->SelectedOutputMap.end(); ++sit)
{
delete (*sit).second;
}
this->SelectedOutputMap.clear();
mutex_lock(&map_lock); mutex_lock(&map_lock);
std::map<size_t, IPhreeqc*>::iterator it = IPhreeqc::Instances.find(this->Index); std::map<size_t, IPhreeqc*>::iterator it = IPhreeqc::Instances.find(this->Index);
if (it != IPhreeqc::Instances.end()) if (it != IPhreeqc::Instances.end())
@ -332,7 +338,14 @@ bool IPhreeqc::GetOutputStringOn(void)const
int IPhreeqc::GetSelectedOutputColumnCount(void)const int IPhreeqc::GetSelectedOutputColumnCount(void)const
{ {
return (int)this->PtrSelectedOutput->GetColCount(); std::map< int, CSelectedOutput* >::const_iterator ci = this->SelectedOutputMap.find(this->CurrentSelectedOutputUserNumber);
if (ci != this->SelectedOutputMap.end())
{
return (int)(*ci).second->GetColCount();
}
return 0;
// COMMENT: {8/23/2013 9:16:26 PM} this->CurrentSelectedOutputMap[]
// COMMENT: {8/23/2013 9:16:26 PM} return (int)this->PtrSelectedOutput->GetColCount();
} }
const char* IPhreeqc::GetSelectedOutputFileName(void)const const char* IPhreeqc::GetSelectedOutputFileName(void)const
@ -353,7 +366,12 @@ bool IPhreeqc::GetSelectedOutputFileOn(void)const
int IPhreeqc::GetSelectedOutputRowCount(void)const int IPhreeqc::GetSelectedOutputRowCount(void)const
{ {
return (int)this->PtrSelectedOutput->GetRowCount(); std::map< int, CSelectedOutput* >::const_iterator ci = this->SelectedOutputMap.find(this->CurrentSelectedOutputUserNumber);
if (ci != this->SelectedOutputMap.end())
{
return (int)(*ci).second->GetRowCount();
}
return 0;
} }
const char* IPhreeqc::GetSelectedOutputString(void)const const char* IPhreeqc::GetSelectedOutputString(void)const
@ -406,7 +424,7 @@ VRESULT IPhreeqc::GetSelectedOutputValue(int row, int col, VAR* pVAR)
return VR_INVALIDARG; return VR_INVALIDARG;
} }
VRESULT v = this->PtrSelectedOutput->Get(row, col, pVAR); VRESULT v = this->SelectedOutputMap[this->CurrentSelectedOutputUserNumber]->Get(row, col, pVAR);
switch (v) switch (v)
{ {
case VR_OK: case VR_OK:
@ -514,7 +532,12 @@ int IPhreeqc::LoadDatabase(const char* filename)
// cleanup // cleanup
// //
this->UnLoadDatabase(); this->UnLoadDatabase();
this->PtrSelectedOutput->Clear(); std::map< int, CSelectedOutput* >::iterator it = this->SelectedOutputMap.begin();
for (; it != this->SelectedOutputMap.end(); ++it)
{
delete (*it).second;
}
this->SelectedOutputMap.clear();
// open file // open file
// //
@ -563,8 +586,12 @@ int IPhreeqc::LoadDatabaseString(const char* input)
// cleanup // cleanup
// //
this->UnLoadDatabase(); this->UnLoadDatabase();
std::map< int, CSelectedOutput* >::iterator it = this->SelectedOutputMap.begin();
this->PtrSelectedOutput->Clear(); for (; it != this->SelectedOutputMap.end(); ++it)
{
delete (*it).second;
}
this->SelectedOutputMap.clear();
std::string s(input); std::string s(input);
std::istringstream iss(s); std::istringstream iss(s);
@ -868,11 +895,14 @@ void IPhreeqc::UnLoadDatabase(void)
// clear selectedoutput // clear selectedoutput
// //
ASSERT(this->PtrSelectedOutput); std::map< int, CSelectedOutput* >::iterator itt = this->SelectedOutputMap.begin();
this->PtrSelectedOutput->Clear(); for (; itt != this->SelectedOutputMap.end(); ++itt)
{
std::map< int, std::string >::iterator mit = SelectedOutputStringMap.begin(); delete (*itt).second;
for (; mit != SelectedOutputStringMap.begin(); ++mit) }
this->SelectedOutputMap.clear();
std::map< int, std::string >::iterator mit = this->SelectedOutputStringMap.begin();
for (; mit != this->SelectedOutputStringMap.begin(); ++mit)
{ {
(*mit).second.clear(); (*mit).second.clear();
} }
@ -899,25 +929,54 @@ void IPhreeqc::UnLoadDatabase(void)
int IPhreeqc::EndRow(void) int IPhreeqc::EndRow(void)
{ {
if (this->PtrSelectedOutput->GetRowCount() <= 1) if (this->CurrentSelectedOutputMap[this->PhreeqcPtr->current_selected_output]->GetRowCount() <= 1)
{ {
// ensure all user_punch headings are included // ensure all user_punch headings are included
ASSERT(this->PhreeqcPtr->n_user_punch_index >= 0); ASSERT(this->PhreeqcPtr->n_user_punch_index >= 0);
if (this->PhreeqcPtr->current_user_punch != NULL) if (this->CurrentSelectedOutputMap[this->PhreeqcPtr->current_selected_output] != NULL)
{ {
for (size_t i = this->PhreeqcPtr->n_user_punch_index; i < this->PhreeqcPtr->current_user_punch->Get_headings().size(); ++i) if (this->PhreeqcPtr->current_user_punch)
{ {
this->PtrSelectedOutput->PushBackEmpty(this->PhreeqcPtr->current_user_punch->Get_headings()[i].c_str()); for (size_t i = this->PhreeqcPtr->n_user_punch_index; i < this->PhreeqcPtr->current_user_punch->Get_headings().size(); ++i)
{
this->CurrentSelectedOutputMap[this->PhreeqcPtr->current_selected_output]->PushBackEmpty(this->PhreeqcPtr->current_user_punch->Get_headings()[i].c_str());
}
} }
} }
} }
return this->PtrSelectedOutput->EndRow(); return this->CurrentSelectedOutputMap[this->PhreeqcPtr->current_selected_output]->EndRow();
} }
void IPhreeqc::check_database(const char* sz_routine) void IPhreeqc::check_database(const char* sz_routine)
{ {
this->ErrorReporter->Clear(); this->ErrorReporter->Clear();
this->PtrSelectedOutput->Clear();
std::map< int, CSelectedOutput* >::iterator it = this->SelectedOutputMap.begin();
for (; it != this->SelectedOutputMap.end(); ++it)
{
delete (*it).second;
}
this->SelectedOutputMap.clear();
this->CurrentSelectedOutputMap.clear();
///{{{ REPLACE WITH A CLEAR ROUTINE
// release
this->LogString.clear();
this->LogLines.clear();
this->OutputString.clear();
this->OutputLines.clear();
std::map< int, std::string >::iterator mit = SelectedOutputStringMap.begin();
for (; mit != SelectedOutputStringMap.begin(); ++mit)
{
(*mit).second.clear();
}
std::map< int, std::vector< std::string > >::iterator lit = this->SelectedOutputLinesMap.begin();
for (; lit != this->SelectedOutputLinesMap.begin(); ++lit)
{
(*lit).second.clear();
}
///}}}
if (!this->DatabaseLoaded) if (!this->DatabaseLoaded)
{ {
@ -932,6 +991,25 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
{ {
char token[MAX_LENGTH]; char token[MAX_LENGTH];
// COMMENT: {8/26/2013 10:32:34 PM} ///{{{ REPLACE WITH A CLEAR ROUTINE
// COMMENT: {8/26/2013 10:32:34 PM} // release
// COMMENT: {8/26/2013 10:32:34 PM} this->LogString.clear();
// COMMENT: {8/26/2013 10:32:34 PM} this->LogLines.clear();
// COMMENT: {8/26/2013 10:32:34 PM} this->OutputString.clear();
// COMMENT: {8/26/2013 10:32:34 PM} this->OutputLines.clear();
// COMMENT: {8/26/2013 10:32:34 PM}
// COMMENT: {8/26/2013 10:32:34 PM} std::map< int, std::string >::iterator mit = SelectedOutputStringMap.begin();
// COMMENT: {8/26/2013 10:32:34 PM} for (; mit != SelectedOutputStringMap.begin(); ++mit)
// COMMENT: {8/26/2013 10:32:34 PM} {
// COMMENT: {8/26/2013 10:32:34 PM} (*mit).second.clear();
// COMMENT: {8/26/2013 10:32:34 PM} }
// COMMENT: {8/26/2013 10:32:34 PM} std::map< int, std::vector< std::string > >::iterator it = this->SelectedOutputLinesMap.begin();
// COMMENT: {8/26/2013 10:32:34 PM} for (; it != this->SelectedOutputLinesMap.begin(); ++it)
// COMMENT: {8/26/2013 10:32:34 PM} {
// COMMENT: {8/26/2013 10:32:34 PM} (*it).second.clear();
// COMMENT: {8/26/2013 10:32:34 PM} }
// COMMENT: {8/26/2013 10:32:34 PM} ///}}}
/* /*
* call pre-run callback * call pre-run callback
*/ */
@ -940,24 +1018,24 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
pfn_pre(cookie); pfn_pre(cookie);
} }
///{{{ REPLACE WITH A CLEAR ROUTINE // COMMENT: {8/26/2013 10:30:49 PM} ///{{{ REPLACE WITH A CLEAR ROUTINE
// release // COMMENT: {8/26/2013 10:30:49 PM} // release
this->LogString.clear(); // COMMENT: {8/26/2013 10:30:49 PM} this->LogString.clear();
this->LogLines.clear(); // COMMENT: {8/26/2013 10:30:49 PM} this->LogLines.clear();
this->OutputString.clear(); // COMMENT: {8/26/2013 10:30:49 PM} this->OutputString.clear();
this->OutputLines.clear(); // COMMENT: {8/26/2013 10:30:49 PM} this->OutputLines.clear();
// COMMENT: {8/26/2013 10:30:49 PM}
std::map< int, std::string >::iterator mit = SelectedOutputStringMap.begin(); // COMMENT: {8/26/2013 10:30:49 PM} std::map< int, std::string >::iterator mit = SelectedOutputStringMap.begin();
for (; mit != SelectedOutputStringMap.begin(); ++mit) // COMMENT: {8/26/2013 10:30:49 PM} for (; mit != SelectedOutputStringMap.begin(); ++mit)
{ // COMMENT: {8/26/2013 10:30:49 PM} {
(*mit).second.clear(); // COMMENT: {8/26/2013 10:30:49 PM} (*mit).second.clear();
} // COMMENT: {8/26/2013 10:30:49 PM} }
std::map< int, std::vector< std::string > >::iterator it = this->SelectedOutputLinesMap.begin(); // COMMENT: {8/26/2013 10:30:49 PM} std::map< int, std::vector< std::string > >::iterator it = this->SelectedOutputLinesMap.begin();
for (; it != this->SelectedOutputLinesMap.begin(); ++it) // COMMENT: {8/26/2013 10:30:49 PM} for (; it != this->SelectedOutputLinesMap.begin(); ++it)
{ // COMMENT: {8/26/2013 10:30:49 PM} {
(*it).second.clear(); // COMMENT: {8/26/2013 10:30:49 PM} (*it).second.clear();
} // COMMENT: {8/26/2013 10:30:49 PM} }
///}}} // COMMENT: {8/26/2013 10:30:49 PM} ///}}}
/* /*
* set read callback * set read callback
@ -998,19 +1076,24 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
{ {
if (this->CurrentSelectedOutputMap.find(&(*mit).second) == this->CurrentSelectedOutputMap.end()) if (this->CurrentSelectedOutputMap.find(&(*mit).second) == this->CurrentSelectedOutputMap.end())
{ {
// int -> CSelectedOutput*
std::map< int, CSelectedOutput* >::value_type item((*mit).first, new CSelectedOutput()); std::map< int, CSelectedOutput* >::value_type item((*mit).first, new CSelectedOutput());
this->SelectedOutputMap.insert(item); this->SelectedOutputMap.insert(item);
// SelectedOutput // SelectedOutput* -> CSelectedOutput*
this->CurrentSelectedOutputMap.insert( this->CurrentSelectedOutputMap.insert(
std::map< SelectedOutput*, CSelectedOutput* >::value_type( std::map< SelectedOutput*, CSelectedOutput* >::value_type(
&(*mit).second, item.second)); &(*mit).second, item.second));
// SelectedOutputString // SelectedOutput* -> std::string*
this->CurrentToStringMap.insert( this->CurrentToStringMap.insert(
std::map< SelectedOutput*, std::string* >::value_type( std::map< SelectedOutput*, std::string* >::value_type(
&(*mit).second, &this->SelectedOutputStringMap[(*mit).first])); &(*mit).second, &this->SelectedOutputStringMap[(*mit).first]));
} }
else
{
ASSERT(this->SelectedOutputMap[(*mit).first] == this->CurrentSelectedOutputMap[&(*mit).second]);
}
if (this->PhreeqcPtr->simulation > 1 && save_punch_in && (*mit).second.Get_new_def() && !bWarning) if (this->PhreeqcPtr->simulation > 1 && save_punch_in && (*mit).second.Get_new_def() && !bWarning)
{ {
std::ostringstream oss; std::ostringstream oss;
@ -1587,7 +1670,7 @@ void IPhreeqc::fpunchf(const char *name, const char *format, double d)
{ {
PHRQ_io::fpunchf_helper(this->CurrentToStringMap[this->PhreeqcPtr->current_selected_output], format, d); PHRQ_io::fpunchf_helper(this->CurrentToStringMap[this->PhreeqcPtr->current_selected_output], format, d);
} }
this->PtrSelectedOutput->PushBackDouble(name, d); this->CurrentSelectedOutputMap[this->PhreeqcPtr->current_selected_output]->PushBackDouble(name, d);
} }
catch (std::bad_alloc) catch (std::bad_alloc)
{ {
@ -1604,7 +1687,7 @@ void IPhreeqc::fpunchf(const char *name, const char *format, char *s)
{ {
PHRQ_io::fpunchf_helper(this->CurrentToStringMap[this->PhreeqcPtr->current_selected_output], format, s); PHRQ_io::fpunchf_helper(this->CurrentToStringMap[this->PhreeqcPtr->current_selected_output], format, s);
} }
this->PtrSelectedOutput->PushBackString(name, s); this->CurrentSelectedOutputMap[this->PhreeqcPtr->current_selected_output]->PushBackString(name, s);
} }
catch (std::bad_alloc) catch (std::bad_alloc)
{ {
@ -1621,7 +1704,7 @@ void IPhreeqc::fpunchf(const char *name, const char *format, int i)
{ {
PHRQ_io::fpunchf_helper(this->CurrentToStringMap[this->PhreeqcPtr->current_selected_output], format, i); PHRQ_io::fpunchf_helper(this->CurrentToStringMap[this->PhreeqcPtr->current_selected_output], format, i);
} }
this->PtrSelectedOutput->PushBackLong(name, (long)i); this->CurrentSelectedOutputMap[this->PhreeqcPtr->current_selected_output]->PushBackLong(name, (long)i);
} }
catch (std::bad_alloc) catch (std::bad_alloc)
{ {

View File

@ -873,11 +873,11 @@ protected:
std::vector< std::string > WarningLines; std::vector< std::string > WarningLines;
int CurrentSelectedOutputUserNumber; int CurrentSelectedOutputUserNumber;
CSelectedOutput *PtrSelectedOutput; // COMMENT: {8/26/2013 10:29:19 PM} CSelectedOutput *PtrSelectedOutput;
std::map< int, CSelectedOutput* > SelectedOutputMap; std::map< int, CSelectedOutput* > SelectedOutputMap;
std::map< SelectedOutput*, CSelectedOutput* > CurrentSelectedOutputMap; std::map< SelectedOutput*, CSelectedOutput* > CurrentSelectedOutputMap;
std::map< SelectedOutput*, std::string* > CurrentToStringMap; std::map< SelectedOutput*, std::string* > CurrentToStringMap;
std::map< class SelectedOutput*, int > InverseSelectedOutputMap; // COMMENT: {8/26/2013 10:27:53 PM} std::map< class SelectedOutput*, int > InverseSelectedOutputMap;
std::string StringInput; std::string StringInput;
std::string DumpString; std::string DumpString;