mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-16 08:38:23 +01:00
Error implementation w/o unit testing
git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/ErrorHandling@6068 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
parent
0b16f6a237
commit
a69da2dd27
41
IPhreeqc.cpp
41
IPhreeqc.cpp
@ -26,11 +26,12 @@ IPhreeqc::IPhreeqc(void)
|
||||
, SelectedOutputOn(false)
|
||||
, OutputFileOn(false)
|
||||
, LogFileOn(false)
|
||||
, ErrorOn(false)
|
||||
, ErrorFileOn(false)
|
||||
, DumpOn(false)
|
||||
, DumpStringOn(false)
|
||||
, OutputStringOn(false)
|
||||
, LogStringOn(false)
|
||||
, ErrorStringOn(true)
|
||||
, ErrorReporter(0)
|
||||
, WarningReporter(0)
|
||||
, SelectedOutput(0)
|
||||
@ -191,13 +192,23 @@ bool IPhreeqc::GetDumpStringOn(void)const
|
||||
return this->DumpStringOn;
|
||||
}
|
||||
|
||||
const char* IPhreeqc::GetErrorFileName(void)const
|
||||
{
|
||||
return this->ErrorFileName.c_str();
|
||||
}
|
||||
|
||||
bool IPhreeqc::GetErrorFileOn(void)const
|
||||
{
|
||||
return this->ErrorOn;
|
||||
return this->ErrorFileOn;
|
||||
}
|
||||
|
||||
const char* IPhreeqc::GetErrorString(void)
|
||||
{
|
||||
static const char err_msg[] = "GetErrorString: ErrorStringOn not set.\n";
|
||||
if (!this->ErrorStringOn)
|
||||
{
|
||||
return err_msg;
|
||||
}
|
||||
this->ErrorString = ((CErrorReporter<std::ostringstream>*)this->ErrorReporter)->GetOS()->str();
|
||||
return this->ErrorString.c_str();
|
||||
}
|
||||
@ -217,6 +228,11 @@ int IPhreeqc::GetErrorStringLineCount(void)const
|
||||
return (int)this->ErrorLines.size();
|
||||
}
|
||||
|
||||
bool IPhreeqc::GetErrorStringOn(void)const
|
||||
{
|
||||
return this->ErrorStringOn;
|
||||
}
|
||||
|
||||
int IPhreeqc::GetId(void)const
|
||||
{
|
||||
return (int)this->Index;
|
||||
@ -648,9 +664,22 @@ void IPhreeqc::SetDumpStringOn(bool bValue)
|
||||
this->DumpStringOn = bValue;
|
||||
}
|
||||
|
||||
void IPhreeqc::SetErrorFileName(const char *filename)
|
||||
{
|
||||
if (filename && ::strlen(filename))
|
||||
{
|
||||
this->ErrorFileName = filename;
|
||||
}
|
||||
}
|
||||
|
||||
void IPhreeqc::SetErrorFileOn(bool bValue)
|
||||
{
|
||||
this->ErrorOn = bValue;
|
||||
this->ErrorFileOn = bValue;
|
||||
}
|
||||
|
||||
void IPhreeqc::SetErrorStringOn(bool bValue)
|
||||
{
|
||||
this->ErrorStringOn = bValue;
|
||||
}
|
||||
|
||||
void IPhreeqc::SetLogFileName(const char *filename)
|
||||
@ -1118,7 +1147,7 @@ void IPhreeqc::log_msg(const char * str)
|
||||
|
||||
void IPhreeqc::error_msg(const char *str, bool stop)
|
||||
{
|
||||
ASSERT(!(this->ErrorOn ^ (this->error_ostream != 0)));
|
||||
ASSERT(!(this->ErrorFileOn ^ (this->error_ostream != 0)));
|
||||
this->PHRQ_io::error_msg(str);
|
||||
|
||||
this->AddError(str);
|
||||
@ -1135,7 +1164,7 @@ void IPhreeqc::error_msg(const char *str, bool stop)
|
||||
|
||||
void IPhreeqc::warning_msg(const char *str)
|
||||
{
|
||||
ASSERT(!(this->ErrorOn ^ (this->error_ostream != 0)));
|
||||
ASSERT(!(this->ErrorFileOn ^ (this->error_ostream != 0)));
|
||||
this->PHRQ_io::warning_msg(str);
|
||||
|
||||
std::ostringstream oss;
|
||||
@ -1179,7 +1208,7 @@ void IPhreeqc::open_output_files(const char* sz_routine)
|
||||
this->warning_msg(oss.str().c_str());
|
||||
}
|
||||
}
|
||||
if (this->ErrorOn)
|
||||
if (this->ErrorFileOn)
|
||||
{
|
||||
if (this->error_ostream != NULL)
|
||||
{
|
||||
|
||||
92
IPhreeqc.h
92
IPhreeqc.h
@ -373,6 +373,26 @@ extern "C" {
|
||||
IPQ_DLL_EXPORT int GetDumpStringOn(int id);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the name of the error file. The default name is <B><I>phreeqc.id.err</I></B>.
|
||||
* @param id The instance id returned from \ref CreateIPhreeqc.
|
||||
* @return filename The name of the error file.
|
||||
* @see GetErrorFileOn, GetErrorString, GetErrorStringOn, GetErrorStringLine, GetErrorStringLineCount, SetErrorFileName, SetErrorFileOn, SetErrorStringOn
|
||||
* @par Fortran90 Interface:
|
||||
* @htmlonly
|
||||
* <CODE>
|
||||
* <PRE>
|
||||
* SUBROUTINE GetErrorFileName(ID,FILENAME)
|
||||
* INTEGER(KIND=4), INTENT(IN) :: ID
|
||||
* CHARACTER(LEN=*), INTENT(OUT) :: FILENAME
|
||||
* END SUBROUTINE GetErrorFileName
|
||||
* </PRE>
|
||||
* </CODE>
|
||||
* @endhtmlonly
|
||||
*/
|
||||
IPQ_DLL_EXPORT const char* GetErrorFileName(int id);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the current value of the error file switch.
|
||||
* @param id The instance id returned from \ref CreateIPhreeqc.
|
||||
@ -446,6 +466,26 @@ extern "C" {
|
||||
*/
|
||||
IPQ_DLL_EXPORT int GetErrorStringLineCount(int id);
|
||||
|
||||
/**
|
||||
* Retrieves the current value of the error string switch.
|
||||
* @param id The instance id returned from \ref CreateIPhreeqc.
|
||||
* @return Non-zero if output is stored, 0 (zero) otherwise.
|
||||
* @see GetErrorFileOn, GetErrorString, GetErrorStringLine, GetErrorStringLineCount, SetErrorFileOn, SetErrorStringOn
|
||||
* @par Fortran90 Interface:
|
||||
* @htmlonly
|
||||
* <CODE>
|
||||
* <PRE>
|
||||
* FUNCTION GetErrorStringOn(ID)
|
||||
* INTEGER(KIND=4), INTENT(IN) :: ID
|
||||
* LOGICAL(KIND=4) :: GetErrorStringOn
|
||||
* END FUNCTION GetErrorStringOn
|
||||
* </PRE>
|
||||
* </CODE>
|
||||
* @endhtmlonly
|
||||
*/
|
||||
IPQ_DLL_EXPORT int GetErrorStringOn(int id);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the name of the log file. The default name is <B><I>phreeqc.id.log</I></B>.
|
||||
* @param id The instance id returned from \ref CreateIPhreeqc.
|
||||
@ -1283,6 +1323,27 @@ Headings
|
||||
*/
|
||||
IPQ_DLL_EXPORT IPQ_RESULT SetDumpStringOn(int id, int dump_string_on);
|
||||
|
||||
/**
|
||||
* Sets the name of the error file. The default value is <B><I>phreeqc.id.err</I></B>.
|
||||
* @param id The instance id returned from \ref CreateIPhreeqc.
|
||||
* @param filename The name of the error file.
|
||||
* @retval IPQ_OK Success.
|
||||
* @retval IPQ_BADINSTANCE The given id is invalid.
|
||||
* @see GetErrorFileName, GetErrorFileOn, GetErrorString, GetErrorStringOn, GetErrorStringLine, GetErrorStringLineCount, SetErrorFileOn, SetErrorStringOn
|
||||
* @par Fortran90 Interface:
|
||||
* @htmlonly
|
||||
* <CODE>
|
||||
* <PRE>
|
||||
* FUNCTION SetErrorFileName(ID,FILENAME)
|
||||
* INTEGER(KIND=4), INTENT(IN) :: ID
|
||||
* CHARACTER(LEN=*), INTENT(OUT) :: FILENAME
|
||||
* INTEGER(KIND=4) :: SetErrorFileName
|
||||
* END FUNCTION SetErrorFileName
|
||||
* </PRE>
|
||||
* </CODE>
|
||||
* @endhtmlonly
|
||||
*/
|
||||
IPQ_DLL_EXPORT IPQ_RESULT SetErrorFileName(int id, const char* filename);
|
||||
|
||||
/**
|
||||
* Sets the error file switch on or off. This switch controls whether or not
|
||||
@ -1308,6 +1369,37 @@ Headings
|
||||
*/
|
||||
IPQ_DLL_EXPORT IPQ_RESULT SetErrorFileOn(int id, int error_on);
|
||||
|
||||
/**
|
||||
* Sets the error string switch on or off. This switch controls whether or not the data normally sent
|
||||
* to the error file are stored in a buffer for retrieval. The initial setting after calling
|
||||
* \ref CreateIPhreeqc is off.
|
||||
* @param id The instance id returned from \ref CreateIPhreeqc.
|
||||
* @param output_string_on If non-zero, captures the error output into a string buffer;
|
||||
* if zero, error output is not captured to a string buffer.
|
||||
* @retval IPQ_OK Success.
|
||||
* @retval IPQ_BADINSTANCE The given id is invalid.
|
||||
* @see GetErrorFileOn, GetErrorStringOn, GetErrorString, GetErrorStringLine, GetErrorStringLineCount, SetErrorFileOn
|
||||
* @par Fortran90 Interface:
|
||||
* @htmlonly
|
||||
* <CODE>
|
||||
* <PRE>
|
||||
* FUNCTION SetErrorStringOn(ID,ERR_STRING_ON)
|
||||
* INTEGER(KIND=4), INTENT(IN) :: ID
|
||||
* LOGICAL(KIND=4), INTENT(IN) :: ERR_STRING_ON
|
||||
* INTEGER(KIND=4) :: SetErrorStringOn
|
||||
* END FUNCTION SetErrorStringOn
|
||||
* </PRE>
|
||||
* </CODE>
|
||||
* @endhtmlonly
|
||||
*
|
||||
* @par C Example:
|
||||
* see \ref GetErrorString_c "GetErrorString"
|
||||
*
|
||||
* @par Fortran90 Example:
|
||||
* see \ref GetErrorStringLine_f90 "GetErrorStringLine"
|
||||
*/
|
||||
IPQ_DLL_EXPORT IPQ_RESULT SetErrorStringOn(int id, int error_string_on);
|
||||
|
||||
/**
|
||||
* Sets the name of the log file. The default value is <B><I>phreeqc.id.log</I></B>.
|
||||
* @param id The instance id returned from \ref CreateIPhreeqc.
|
||||
|
||||
33
IPhreeqc.hpp
33
IPhreeqc.hpp
@ -168,6 +168,13 @@ public:
|
||||
*/
|
||||
bool GetDumpStringOn(void)const;
|
||||
|
||||
/**
|
||||
* Retrieves the name of the error file. The default value is <B><I>phreeqc.id.err</I></B>, where id is obtained from \ref GetId.
|
||||
* @return filename The name of the file to write to.
|
||||
* @see GetErrorFileOn, GetErrorString, GetErrorStringOn, GetErrorStringLine, GetErrorStringLineCount, SetErrorFileName, SetErrorFileOn, SetErrorStringOn
|
||||
*/
|
||||
const char* GetErrorFileName(void)const;
|
||||
|
||||
/**
|
||||
* Retrieves the current value of the error file switch.
|
||||
* @retval true Errors are written to the <B><I>phreeqc.id.err</I></B> (where id is obtained from \ref GetId) file.
|
||||
@ -198,6 +205,14 @@ public:
|
||||
*/
|
||||
int GetErrorStringLineCount(void)const;
|
||||
|
||||
/**
|
||||
* Retrieves the current value of the error string switch.
|
||||
* @retval true Error output is stored.
|
||||
* @retval false No error output is stored.
|
||||
* @see GetErrorFileOn, GetErrorString, GetErrorStringLine, GetErrorStringLineCount, SetErrorFileOn, SetErrorStringOn
|
||||
*/
|
||||
bool GetErrorStringOn(void)const;
|
||||
|
||||
/**
|
||||
* Retrieves the id of this object. Each instance receives an id which is incremented for each instance
|
||||
* starting with the value zero.
|
||||
@ -611,6 +626,13 @@ public:
|
||||
*/
|
||||
void SetDumpStringOn(bool bValue);
|
||||
|
||||
/**
|
||||
* Sets the name of the error file. The default value is <B><I>phreeqc.id.err</I></B>, where id is obtained from \ref GetId.
|
||||
* @param filename The name of the file to write error output to.
|
||||
* @see GetErrorFileName, GetErrorFileOn, GetErrorString, GetErrorStringOn, GetErrorStringLine, GetErrorStringLineCount, SetErrorFileOn, SetErrorStringOn
|
||||
*/
|
||||
void SetErrorFileName(const char *filename);
|
||||
|
||||
/**
|
||||
* Sets the error file switch on or off. This switch controls whether or not
|
||||
* error messages are written to the <B><I>phreeqc.id.err</I></B> (where id is obtained from \ref GetId) file.
|
||||
@ -620,6 +642,14 @@ public:
|
||||
*/
|
||||
void SetErrorFileOn(bool bValue);
|
||||
|
||||
/**
|
||||
* Sets the error string switch on or off. This switch controls whether or not the data normally sent
|
||||
* to the error file are stored in a buffer for retrieval. The initial setting is false.
|
||||
* @param bValue If true, captures error output into a string buffer; if false, error output is not captured to a string buffer.
|
||||
* @see GetErrorFileOn, GetErrorString, GetErrorStringOn, GetErrorStringLine, GetErrorStringLineCount, SetErrorFileOn
|
||||
*/
|
||||
void SetErrorStringOn(bool bValue);
|
||||
|
||||
/**
|
||||
* Sets the name of the log file. The default value is <B><I>phreeqc.id.log</I></B>, where id is obtained from \ref GetId.
|
||||
* @param filename The name of the file to write log output to.
|
||||
@ -723,7 +753,7 @@ protected:
|
||||
bool OutputFileOn;
|
||||
|
||||
bool LogFileOn;
|
||||
bool ErrorOn;
|
||||
bool ErrorFileOn;
|
||||
bool DumpOn;
|
||||
|
||||
bool DumpStringOn;
|
||||
@ -736,6 +766,7 @@ protected:
|
||||
std::string LogString;
|
||||
std::vector< std::string > LogLines;
|
||||
|
||||
bool ErrorStringOn;
|
||||
IErrorReporter *ErrorReporter;
|
||||
std::string ErrorString;
|
||||
std::vector< std::string > ErrorLines;
|
||||
|
||||
@ -187,6 +187,18 @@ GetDumpStringOn(int id)
|
||||
return IPQ_BADINSTANCE;
|
||||
}
|
||||
|
||||
const char*
|
||||
GetErrorFileName(int id)
|
||||
{
|
||||
static const char empty[] = "";
|
||||
IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
|
||||
if (IPhreeqcPtr)
|
||||
{
|
||||
return IPhreeqcPtr->GetErrorFileName();
|
||||
}
|
||||
return empty;
|
||||
}
|
||||
|
||||
int
|
||||
GetErrorFileOn(int id)
|
||||
{
|
||||
@ -240,6 +252,24 @@ GetErrorStringLineCount(int id)
|
||||
return IPQ_BADINSTANCE;
|
||||
}
|
||||
|
||||
int
|
||||
GetErrorStringOn(int id)
|
||||
{
|
||||
IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
|
||||
if (IPhreeqcPtr)
|
||||
{
|
||||
if (IPhreeqcPtr->GetErrorStringOn())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return IPQ_BADINSTANCE;
|
||||
}
|
||||
|
||||
const char*
|
||||
GetLogFileName(int id)
|
||||
{
|
||||
@ -632,6 +662,18 @@ SetDumpStringOn(int id, int value)
|
||||
return IPQ_BADINSTANCE;
|
||||
}
|
||||
|
||||
IPQ_RESULT
|
||||
SetErrorFileName(int id, const char* filename)
|
||||
{
|
||||
IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
|
||||
if (IPhreeqcPtr)
|
||||
{
|
||||
IPhreeqcPtr->SetErrorFileName(filename);
|
||||
return IPQ_OK;
|
||||
}
|
||||
return IPQ_BADINSTANCE;
|
||||
}
|
||||
|
||||
IPQ_RESULT
|
||||
SetErrorFileOn(int id, int value)
|
||||
{
|
||||
@ -644,6 +686,18 @@ SetErrorFileOn(int id, int value)
|
||||
return IPQ_BADINSTANCE;
|
||||
}
|
||||
|
||||
IPQ_RESULT
|
||||
SetErrorStringOn(int id, int value)
|
||||
{
|
||||
IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
|
||||
if (IPhreeqcPtr)
|
||||
{
|
||||
IPhreeqcPtr->SetErrorStringOn(value != 0);
|
||||
return IPQ_OK;
|
||||
}
|
||||
return IPQ_BADINSTANCE;
|
||||
}
|
||||
|
||||
IPQ_RESULT
|
||||
SetLogFileName(int id, const char* filename)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user