From 3be1ca8d40e00f3e5d90d9c53f1b2ab0ddb2b938 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 24 Jan 2014 03:46:46 +0000 Subject: [PATCH] Added additional check to LoadDatabase git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/trunk@8399 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- src/IPhreeqc.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++------ src/IPhreeqc.hpp | 4 +++ 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/IPhreeqc.cpp b/src/IPhreeqc.cpp index 29562310..8eebb95f 100644 --- a/src/IPhreeqc.cpp +++ b/src/IPhreeqc.cpp @@ -571,12 +571,8 @@ std::list< std::string > IPhreeqc::ListComponents(void) return this->Components; } -int IPhreeqc::LoadDatabase(const char* filename) +int IPhreeqc::load_db(const char* filename) { - bool bSaveOutputOn = this->OutputFileOn; - this->OutputFileOn = false; - bool bSaveLogFileOn = this->LogFileOn; - this->LogFileOn = false; try { // cleanup @@ -604,6 +600,7 @@ int IPhreeqc::LoadDatabase(const char* filename) // read input // + ASSERT(this->PhreeqcPtr->phrq_io->get_istream() == NULL); this->PhreeqcPtr->phrq_io->push_istream(&ifs, false); this->PhreeqcPtr->read_database(); } @@ -625,12 +622,34 @@ int IPhreeqc::LoadDatabase(const char* filename) } this->PhreeqcPtr->phrq_io->clear_istream(); this->DatabaseLoaded = (this->PhreeqcPtr->get_input_errors() == 0); - this->OutputFileOn = bSaveOutputOn; - this->LogFileOn = bSaveLogFileOn; return this->PhreeqcPtr->get_input_errors(); } -int IPhreeqc::LoadDatabaseString(const char* input) +int IPhreeqc::LoadDatabase(const char* filename) +{ + // save I/O state + bool bSaveErrorFileOn = this->ErrorFileOn; + bool bSaveOutputOn = this->OutputFileOn; + bool bSaveLogFileOn = this->LogFileOn; + this->ErrorFileOn = false; + this->OutputFileOn = false; + this->LogFileOn = false; + + int n = this->load_db(filename); + if (n == 0) + { + n = this->test_db(); + } + + // restore I/O state + this->ErrorFileOn = bSaveErrorFileOn; + this->OutputFileOn = bSaveOutputOn; + this->LogFileOn = bSaveLogFileOn; + + return n; +} + +int IPhreeqc::load_db_str(const char* input) { try { @@ -676,6 +695,30 @@ int IPhreeqc::LoadDatabaseString(const char* input) return this->PhreeqcPtr->get_input_errors(); } +int IPhreeqc::LoadDatabaseString(const char* input) +{ + // save I/O state + bool bSaveErrorFileOn = this->ErrorFileOn; + bool bSaveOutputOn = this->OutputFileOn; + bool bSaveLogFileOn = this->LogFileOn; + this->ErrorFileOn = false; + this->OutputFileOn = false; + this->LogFileOn = false; + + int n = this->load_db_str(input); + if (n == 0) + { + n = this->test_db(); + } + + // restore I/O state + this->ErrorFileOn = bSaveErrorFileOn; + this->OutputFileOn = bSaveOutputOn; + this->LogFileOn = bSaveLogFileOn; + + return n; +} + void IPhreeqc::OutputAccumulatedLines(void) { std::cout << this->StringInput.c_str() << std::endl; @@ -943,6 +986,18 @@ void IPhreeqc::SetSelectedOutputStringOn(bool bValue) this->SelectedOutputStringOn = bValue; } +int IPhreeqc::test_db(void) +{ + std::ostringstream oss; + int sn = this->PhreeqcPtr->next_user_number(Keywords::KEY_SOLUTION); + oss << "SOLUTION " << sn <<"; DELETE; -solution " << sn; + + this->PhreeqcPtr->set_reading_database(TRUE); + int n = this->RunString(oss.str().c_str()); + this->PhreeqcPtr->set_reading_database(FALSE); + return n; +} + void IPhreeqc::UnLoadDatabase(void) { // init IPhreeqc diff --git a/src/IPhreeqc.hpp b/src/IPhreeqc.hpp index a6f574e3..6d081c1e 100644 --- a/src/IPhreeqc.hpp +++ b/src/IPhreeqc.hpp @@ -882,6 +882,10 @@ protected: void update_errors(void); + int load_db(const char* filename); + int load_db_str(const char* filename); + int test_db(void); + bool get_sel_out_file_on(int n)const; std::string sel_file_name(int n_user);