Skip to content

Commit

Permalink
add a C api for SBMLErrorLog
Browse files Browse the repository at this point in the history
  • Loading branch information
skeating committed Aug 19, 2023
1 parent 9a80581 commit f850dbd
Show file tree
Hide file tree
Showing 7 changed files with 483 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/sbml/SBMLDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2485,6 +2485,13 @@ SBMLDocument_getError (SBMLDocument_t *d, unsigned int n)
return (d != NULL) ? d->getError(n) : NULL;
}

LIBSBML_EXTERN
const SBMLErrorLog_t *
SBMLDocument_getErrorLog(SBMLDocument_t *d)
{
return (d != NULL) ? d->getErrorLog() : NULL;
}

LIBSBML_EXTERN
const SBMLError_t *
SBMLDocument_getErrorWithSeverity(SBMLDocument_t *d, unsigned int n, unsigned int severity)
Expand Down
9 changes: 7 additions & 2 deletions src/sbml/SBMLDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -2472,8 +2472,8 @@ SBMLDocument_checkL2v2Compatibility (SBMLDocument_t *d);
* @memberof SBMLDocument_t
*/
LIBSBML_EXTERN
unsigned int
SBMLDocument_checkL2v3Compatibility (SBMLDocument_t *d);
unsigned int
SBMLDocument_checkL2v3Compatibility(SBMLDocument_t *d);


/**
Expand Down Expand Up @@ -2588,6 +2588,11 @@ const SBMLError_t *
SBMLDocument_getError (SBMLDocument_t *d, unsigned int n);


LIBSBML_EXTERN
const SBMLErrorLog_t *
SBMLDocument_getErrorLog(SBMLDocument_t *d);


/**
* Returns the nth error or warning with the given severity
* encountered during parsing, consistency checking, or attempted
Expand Down
112 changes: 110 additions & 2 deletions src/sbml/SBMLErrorLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ SBMLErrorLog::getError (unsigned int n) const
* @return the nth SBMLError in this log.
*/
const SBMLError*
SBMLErrorLog::getErrorWithSeverity(unsigned int n, unsigned int severity) const
SBMLErrorLog::getErrorWithSeverity(unsigned int n, unsigned int severity, unsigned int fromCAPI) const
{
unsigned int count = 0;
MatchSeverity matcher(severity);
Expand All @@ -406,7 +406,17 @@ SBMLErrorLog::getErrorWithSeverity(unsigned int n, unsigned int severity) const
{
if (matcher(*it))
{
if (count == n) return dynamic_cast<const SBMLError*>(*it);
if (count == n)
{
if (fromCAPI == 0)
{
return dynamic_cast<const SBMLError*>(*it);
}
else
{
return static_cast<const SBMLError*>(*it);
}
}
++count;
}
}
Expand All @@ -417,6 +427,104 @@ SBMLErrorLog::getErrorWithSeverity(unsigned int n, unsigned int severity) const


/** @cond doxygenIgnored */

LIBSBML_EXTERN
SBMLErrorLog_t*
SBMLErrorLog_create(void)
{
return new(nothrow) SBMLErrorLog;
}


LIBSBML_EXTERN
void
SBMLErrorLog_free(SBMLErrorLog_t* log)
{
delete log;
}


LIBSBML_EXTERN
void
SBMLErrorLog_add(SBMLErrorLog_t *log, const SBMLError_t *error)
{
if (log == NULL || error == NULL) return;
log->add(*error);
}


LIBSBML_EXTERN
const SBMLError_t *
SBMLErrorLog_getError(const SBMLErrorLog_t *log, unsigned int n)
{
if (log == NULL)
return NULL;

return (const SBMLError_t*)(XMLErrorLog_getError((const XMLErrorLog_t*)(log), n));
}


LIBSBML_EXTERN
const SBMLError_t *
SBMLErrorLog_getErrorWithSeverity(const SBMLErrorLog_t *log, unsigned int n, unsigned int severity)
{
return (log != NULL) ? log->getErrorWithSeverity(n, severity, 1) : NULL;
}

LIBSBML_EXTERN
unsigned int
SBMLErrorLog_getNumFailsWithSeverity(const SBMLErrorLog_t *log, unsigned int severity)
{
return (log != NULL) ? log->getNumFailsWithSeverity(severity) : 0;
}

LIBSBML_EXTERN
unsigned int
SBMLErrorLog_getNumErrors(const SBMLErrorLog_t *log)
{
return (log != NULL) ? log->getNumErrors() : 0;
}


LIBSBML_EXTERN
bool
SBMLErrorLog_contains(const SBMLErrorLog_t *log, unsigned int errorId)
{
return (log != NULL) ? log->contains(errorId) : false;
}

LIBSBML_EXTERN
void
SBMLErrorLog_remove(SBMLErrorLog_t *log, unsigned int errorId)
{
if (log != NULL)
{
log->remove(errorId);
}
}

LIBSBML_EXTERN
void
SBMLErrorLog_removeAll(SBMLErrorLog_t *log, unsigned int errorId)
{
if (log != NULL)
{
log->removeAll(errorId);
}
}

LIBSBML_EXTERN
void
SBMLErrorLog_clearLog(SBMLErrorLog_t *log)
{
if (log != NULL)
{
log->clearLog();
}
}



/** @endcond */
LIBSBML_CPP_NAMESPACE_END

183 changes: 182 additions & 1 deletion src/sbml/SBMLErrorLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class LIBSBML_EXTERN SBMLErrorLog : public XMLErrorLog
*
* @see getNumFailsWithSeverity(unsigned int severity)
*/
const SBMLError* getErrorWithSeverity(unsigned int n, unsigned int severity) const;
const SBMLError* getErrorWithSeverity(unsigned int n, unsigned int severity, unsigned int fromCAPI=0) const;


/**
Expand Down Expand Up @@ -360,4 +360,185 @@ class LIBSBML_EXTERN SBMLErrorLog : public XMLErrorLog
LIBSBML_CPP_NAMESPACE_END

#endif /* __cplusplus */

#ifndef SWIG

LIBSBML_CPP_NAMESPACE_BEGIN
BEGIN_C_DECLS

/**
* Creates a new empty SBMLErrorLog_t structure and returns it.
*
* @return the new SBMLErrorLog_t structure.
*
* @memberof SBMLErrorLog_t
*/
LIBSBML_EXTERN
SBMLErrorLog_t*
SBMLErrorLog_create(void);


/**
* Frees the SBMLErrorLog_t structure.
*
* @memberof SBMLErrorLog_t
*/
LIBSBML_EXTERN
void
SBMLErrorLog_free(SBMLErrorLog_t*);


/**
* Logs the given XMLError_t structure.
*
* @param log SBMLErrorLog_t, the error log to be added to.
* @param error XMLError_t, the error to be logged.
*
* @memberof SBMLErrorLog_t
*/
LIBSBML_EXTERN
void
SBMLErrorLog_add(SBMLErrorLog_t *log, const SBMLError_t *error);


/**
* Returns the nth SBMLError_t in this log.
*
* @param log SBMLErrorLog_t, the error log to be queried.
* @param n unsigned int number of the error to retrieve.
*
* @return the nth SBMLError_t in this log.
* If the index @p n is invalid, @c NULL is returned.
*
* @memberof SBMLErrorLog_t
*/
LIBSBML_EXTERN
const SBMLError_t *
SBMLErrorLog_getError(const SBMLErrorLog_t *log, unsigned int n);


/**
* Returns the <i>n</i>th SBMLError object with given severity in this log.
*
* Index @p n is counted from 0. Callers should first inquire about the
* number of items in the log by using the
* @if java SBMLErrorLog::getNumFailsWithSeverity(long severity)@else getNumFailsWithSeverity()@endif@~ method.
* Attempts to use an error index number that exceeds the actual number
* of errors in the log will result in a @c NULL being returned.
*
* @param log SBMLErrorLog_t, the error log to be queried.
* @param n the index number of the error to retrieve (with 0 being the
* first error).
* @param severity the severity of the error to retrieve.
*
* @return the <i>n</i>th SBMLError in this log, or @c NULL if @p n is
* greater than or equal to
* @if java SBMLErrorLog::getNumFailsWithSeverity(long severity)@else getNumFailsWithSeverity()@endif.
*
* @see getNumFailsWithSeverity(unsigned int severity)
*
* @memberof SBMLErrorLog_t
*/
LIBSBML_EXTERN
const SBMLError_t *
SBMLErrorLog_getErrorWithSeverity(const SBMLErrorLog_t *log, unsigned int n, unsigned int severity);


/**
* Returns the number of errors that have been logged with the given
* severity code.
*
* @copydetails doc_errorlog_what_are_severities
*
* @param log SBMLErrorLog_t, the error log to be queried.
* @if clike @param severity a value from
* #SBMLErrorSeverity_t @endif@if java @param severity a
* value from the set of <code>LIBSBML_SEV_</code> constants defined by
* the interface class <code><a
* href="libsbmlConstants.html">libsbmlConstants</a></code> @endif@if python @param severity a
* value from the set of <code>LIBSBML_SEV_</code> constants defined by
* the interface class @link libsbml libsbml@endlink. @endif@~
*
* @return a count of the number of errors with the given severity code.
*
* @see getNumErrors()
*
* @memberof SBMLErrorLog_t
*/
LIBSBML_EXTERN
unsigned int
SBMLErrorLog_getNumFailsWithSeverity(const SBMLErrorLog_t *log, unsigned int severity);


/**
* Returns the number of errors that have been logged.
*
* @param log SBMLErrorLog_t, the error log to be queried.
*
* @return the number of errors that have been logged.
*
* @memberof SBMLErrorLog_t
*/
LIBSBML_EXTERN
unsigned int
SBMLErrorLog_getNumErrors(const SBMLErrorLog_t *log);


/**
* Returns @c true if SBMLErrorLog contains an errorId
*
* @param log SBMLErrorLog_t, the error log to be queried.
* @param errorId the error identifier of the error to be found.
*
* @memberof SBMLErrorLog_t
*/
LIBSBML_EXTERN
bool
SBMLErrorLog_contains(const SBMLErrorLog_t *log, unsigned int errorId);


/**
* Removes an error having errorId from the SBMLError list.
*
* Only the first item will be removed if there are multiple errors
* with the given errorId.
*
* @param log SBMLErrorLog_t, the error log to be cleared.
* @param errorId the error identifier of the error to be removed.
*
* @memberof SBMLErrorLog_t
*/
LIBSBML_EXTERN
void
SBMLErrorLog_remove(SBMLErrorLog_t *log, unsigned int errorId);


/**
* Removes all errors having errorId from the SBMLError list.
*
* @param log SBMLErrorLog_t, the error log to be cleared.
* @param errorId the error identifier of the error to be removed.
*
* @memberof SBMLErrorLog_t
*/
LIBSBML_EXTERN
void
SBMLErrorLog_removeAll(SBMLErrorLog_t *log, unsigned int errorId);


/**
* Removes all errors from this log.
*
* @param log SBMLErrorLog_t, the error log to be cleared.
*
* @memberof SBMLErrorLog_t
*/
LIBSBML_EXTERN
void
SBMLErrorLog_clearLog(SBMLErrorLog_t *log);

END_C_DECLS
LIBSBML_CPP_NAMESPACE_END

#endif /* !SWIG */
#endif /* SBMLErrorLog_h */
6 changes: 6 additions & 0 deletions src/sbml/common/sbmlfwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ typedef CLASS_OR_STRUCT SBMLWriter SBMLWriter_t;
*/
typedef CLASS_OR_STRUCT SBMLError SBMLError_t;

/**
* @var typedef class SBMLErrorLog SBMLErrorLog_t
* @copydoc SBMLErrorLog
*/
typedef CLASS_OR_STRUCT SBMLErrorLog SBMLErrorLog_t;

/**
* @var typedef class ASTNode ASTNode_t
* @copydoc ASTNode
Expand Down
Loading

0 comments on commit f850dbd

Please sign in to comment.