Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/libopencor/issue.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class LIBOPENCOR_EXPORT Issue

Impl *mPimpl; /**< The private implementation, @private. */

explicit Issue(Type pType, const std::string &pDescription); /**< Constructor, @private. */
explicit Issue(Type pType, const std::string &pDescription, const std::string &pContext); /**< Constructor, @private. */
};

} // namespace libOpenCOR
6 changes: 3 additions & 3 deletions src/file/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ void File::Impl::checkType(const FilePtr &pOwner, bool pResetType)
if (mCellmlFile != nullptr) {
mType = Type::CELLML_FILE;

addIssues(mCellmlFile);
addIssues(mCellmlFile, "CellML file");
} else {
mSedmlFile = SedmlFile::create(pOwner);

if (mSedmlFile != nullptr) {
mType = Type::SEDML_FILE;

addIssues(mSedmlFile);
addIssues(mSedmlFile, "SED-ML file");
} else {
mCombineArchive = CombineArchive::create(pOwner);

if (mCombineArchive != nullptr) {
mType = Type::COMBINE_ARCHIVE;

addIssues(mCombineArchive);
addIssues(mCombineArchive, "COMBINE archive");
} else {
addError("The file is not a CellML file, a SED-ML file, or a COMBINE archive.");
}
Expand Down
23 changes: 20 additions & 3 deletions src/logger/issue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ limitations under the License.

namespace libOpenCOR {

Issue::Impl::Impl(Type pType, const std::string &pDescription)
Issue::Impl::Impl(Type pType, const std::string &pDescription, const std::string &pContext)
: mType(pType)
, mDescription(pDescription)
, mContext(pContext)
{
}

Expand All @@ -36,11 +37,27 @@ std::string Issue::Impl::typeAsString() const

std::string Issue::Impl::description() const
{
// Check whether we have some context to add to the description.

if (!mContext.empty()) {
auto description {mDescription};

#ifndef CODE_COVERAGE_ENABLED
if (std::isupper(description[0]) != 0) {
#endif
description[0] = static_cast<char>(std::tolower(description[0]));
#ifndef CODE_COVERAGE_ENABLED
}
#endif

return mContext + ": " + description;
}

return mDescription;
}

Issue::Issue(Type pType, const std::string &pDescription)
: mPimpl(new Impl {pType, pDescription})
Issue::Issue(Type pType, const std::string &pDescription, const std::string &pContext)
: mPimpl(new Impl {pType, pDescription, pContext})
{
}

Expand Down
3 changes: 2 additions & 1 deletion src/logger/issue_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class Issue::Impl
public:
Type mType;
std::string mDescription;
std::string mContext;

explicit Impl(Type pType, const std::string &pDescription);
explicit Impl(Type pType, const std::string &pDescription, const std::string &pContext);

Type type() const;
std::string typeAsString() const;
Expand Down
14 changes: 8 additions & 6 deletions src/logger/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#include "issue_p.h"
#include "logger_p.h"

namespace libOpenCOR {
Expand Down Expand Up @@ -90,27 +91,28 @@ IssuePtr Logger::Impl::warning(size_t pIndex) const
return mWarnings[pIndex];
}

void Logger::Impl::addIssues(const LoggerPtr &pLogger)
void Logger::Impl::addIssues(const LoggerPtr &pLogger, const std::string &pContext)
{
for (const auto &issue : pLogger->issues()) {
addIssue(issue->type(), issue->description());
addIssue(issue->type(), issue->mPimpl->mDescription,
issue->mPimpl->mContext.empty() ? pContext : pContext + " | " + issue->mPimpl->mContext);
}
}

void Logger::Impl::addIssues(const libcellml::LoggerPtr &pLogger)
void Logger::Impl::addIssues(const libcellml::LoggerPtr &pLogger, const std::string &pContext)
{
for (size_t i {0}; i < pLogger->issueCount(); ++i) {
auto issue {pLogger->issue(i)};

addIssue((issue->level() == libcellml::Issue::Level::ERROR) ? Issue::Type::ERROR :
Issue::Type::WARNING,
issue->description());
issue->description(), pContext);
}
}

void Logger::Impl::addIssue(Issue::Type pType, const std::string &pDescription)
void Logger::Impl::addIssue(Issue::Type pType, const std::string &pDescription, const std::string &pContext)
{
auto issue {IssuePtr {new Issue {pType, pDescription}}};
auto issue {IssuePtr {new Issue {pType, pDescription, pContext}}};
mIssues.push_back(issue);

if (pType == Issue::Type::ERROR) {
Expand Down
6 changes: 3 additions & 3 deletions src/logger/logger_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ class Logger::Impl
IssuePtrs warnings() const;
IssuePtr warning(size_t pIndex) const;

void addIssues(const LoggerPtr &pLogger);
void addIssues(const libcellml::LoggerPtr &pLogger);
void addIssues(const LoggerPtr &pLogger, const std::string &pContext);
void addIssues(const libcellml::LoggerPtr &pLogger, const std::string &pContext);

void addIssue(Issue::Type pType, const std::string &pDescription);
void addIssue(Issue::Type pType, const std::string &pDescription, const std::string &pContext = "");

void addError(const std::string &pDescription);
void addWarning(const std::string &pDescription);
Expand Down
2 changes: 1 addition & 1 deletion src/sed/seddocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void SedDocument::Impl::initialiseFromSedmlFile(const SedDocumentPtr &pOwner, co

sedmlFile->populateDocument(pOwner);

addIssues(sedmlFile);
addIssues(sedmlFile, "SED-ML file");
}

void SedDocument::Impl::initialiseFromCombineArchive(const SedDocumentPtr &pOwner, const FilePtr &pFile)
Expand Down
6 changes: 3 additions & 3 deletions src/sed/sedinstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ SedInstance::Impl::Impl(const SedDocumentPtr &pDocument)
// Make sure that the task is valid.

if (!taskPimpl->isValid()) {
addIssues(task);
addIssues(task, "Task");

tasksValid = false;
}
Expand All @@ -63,7 +63,7 @@ SedInstance::Impl::Impl(const SedDocumentPtr &pDocument)
mTasks.push_back(taskInstance);

if (taskInstance->hasIssues()) {
addIssues(taskInstance);
addIssues(taskInstance, "Task instance");
}
}
}
Expand Down Expand Up @@ -93,7 +93,7 @@ double SedInstance::Impl::run()
res += task->pimpl()->run();

if (task->hasIssues()) {
addIssues(task);
addIssues(task, "Task");

// Reset the issues of the task so that they are not reported again should the instance be run again.

Expand Down
12 changes: 6 additions & 6 deletions src/sed/sedinstancetask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ SedInstanceTask::Impl::Impl(const SedAbstractTaskPtr &pTask)

#ifndef CODE_COVERAGE_ENABLED
if (mRuntime->hasErrors()) {
addIssues(mRuntime);
addIssues(mRuntime, "Runtime");

return;
}
Expand Down Expand Up @@ -141,7 +141,7 @@ void SedInstanceTask::Impl::applyChanges()

changeAttribute->pimpl()->apply(mOwner.lock(), mAnalyserModel);

addIssues(changeAttribute);
addIssues(changeAttribute, "Change attribute");
}
}

Expand Down Expand Up @@ -194,7 +194,7 @@ void SedInstanceTask::Impl::initialise()
// Make sure that the NLA solver, should it have been used, didn't report any issues.

if ((mNlaSolver != nullptr) && mNlaSolver->hasIssues()) {
addIssues(mNlaSolver);
addIssues(mNlaSolver, mNlaSolver->name());

return;
}
Expand All @@ -205,7 +205,7 @@ void SedInstanceTask::Impl::initialise()
if (!mOdeSolver->pimpl()->initialise(mVoi, mAnalyserModel->stateCount(), mStates, mRates,
mConstants, mComputedConstants, mAlgebraic,
mRuntime)) {
addIssues(mOdeSolver);
addIssues(mOdeSolver, mOdeSolver->name());

return;
}
Expand Down Expand Up @@ -264,7 +264,7 @@ double SedInstanceTask::Impl::run()

while (!fuzzyCompare(mVoi, voiEnd)) {
if (!mOdeSolver->pimpl()->solve(mVoi, std::min(voiStart + static_cast<double>(++voiCounter) * voiInterval, voiEnd))) {
addIssues(mOdeSolver);
addIssues(mOdeSolver, mOdeSolver->name());

return 0.0;
}
Expand All @@ -283,7 +283,7 @@ double SedInstanceTask::Impl::run()

#ifndef CODE_COVERAGE_ENABLED
if ((mNlaSolver != nullptr) && mNlaSolver->hasIssues()) {
addIssues(mNlaSolver);
addIssues(mNlaSolver, mNlaSolver->name());

return 0.0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sed/sedmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool SedModel::Impl::isValid()
break;
}

addIssues(mFile->pimpl()->mCellmlFile);
addIssues(mFile->pimpl()->mCellmlFile, "CellML");

return !hasErrors();
}
Expand Down
4 changes: 2 additions & 2 deletions src/sed/sedtask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ bool SedTask::Impl::isValid()
// Make sure that the model is valid.

if (!mModel->pimpl()->isValid()) {
addIssues(mModel);
addIssues(mModel, "Model");
}

// Make sure that the simulation is valid for the model.

if (!mSimulation->pimpl()->isValid(mModel)) {
addIssues(mSimulation);
addIssues(mSimulation, "Simulation");
}

return !hasIssues();
Expand Down
2 changes: 1 addition & 1 deletion src/solver/solverkinsol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ bool SolverKinsol::Impl::solve(ComputeObjectiveFunction pComputeObjectiveFunctio
#ifndef CODE_COVERAGE_ENABLED
if (userData.infOrNanFound) {
#endif
addError("The input vector contains some Inf and/or NaN values.");
addError("The NLA system could not be solved (it contains some Inf and/or NaN values).");
#ifndef CODE_COVERAGE_ENABLED
} else {
addError(mErrorMessage);
Expand Down
4 changes: 2 additions & 2 deletions src/support/cellml/cellmlfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CellmlFile::Impl::Impl(const FilePtr &pFile, const libcellml::ModelPtr &pModel,
if (importer->resolveImports(mModel, pathToString(stringToPath(pFile->path()).parent_path()))) {
mModel = importer->flattenModel(mModel);
} else {
addIssues(importer);
addIssues(importer, "Importer");
}
}

Expand All @@ -53,7 +53,7 @@ CellmlFile::Impl::Impl(const FilePtr &pFile, const libcellml::ModelPtr &pModel,
mAnalyserModel = mAnalyser->model();

if (mAnalyser->errorCount() != 0) {
addIssues(mAnalyser);
addIssues(mAnalyser, "Analyser");
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/support/cellml/cellmlfileruntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ CellmlFileRuntime::Impl::Impl(const CellmlFilePtr &pCellmlFile, const SolverNlaP
auto cellmlFileAnalyser {pCellmlFile->analyser()};

if (cellmlFileAnalyser->errorCount() != 0) {
addIssues(cellmlFileAnalyser);
addIssues(cellmlFileAnalyser, "Analyser");
} else {
// Get an NLA solver, if needed.

Expand Down Expand Up @@ -341,7 +341,7 @@ extern void nlaSolve(uintptr_t nlaSolverAddress, void (*objectiveFunction)(doubl
if (!mCompiler->compile(implementationCode, mWasmModule)) {
// The compilation failed, so add the issues it generated.

addIssues(mCompiler);
addIssues(mCompiler, "Compiler");

return;
}
Expand Down Expand Up @@ -376,7 +376,7 @@ extern void nlaSolve(uintptr_t nlaSolverAddress, void (*objectiveFunction)(doubl
if (!mCompiler->compile(generator->implementationCode(pCellmlFile->analyserModel()))) {
// The compilation failed, so add the issues it generated.

addIssues(mCompiler);
addIssues(mCompiler, "Compiler");

return;
}
Expand All @@ -393,7 +393,7 @@ extern void nlaSolve(uintptr_t nlaSolverAddress, void (*objectiveFunction)(doubl

# ifndef CODE_COVERAGE_ENABLED
if (!functionAdded) {
addIssues(mCompiler);
addIssues(mCompiler, "Compiler");

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/support/sedml/sedmlfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ void SedmlFile::Impl::populateDocument(const SedDocumentPtr &pDocument)
if (odeSolver != nullptr) {
odeSolver->pimpl()->populate(sedAlgorithm);

addIssues(odeSolver);
addIssues(odeSolver, odeSolver->name());

simulation->setOdeSolver(odeSolver);
}

if (nlaSolver != nullptr) {
nlaSolver->pimpl()->populate(sedAlgorithm);

addIssues(nlaSolver);
addIssues(nlaSolver, nlaSolver->name());

simulation->setNlaSolver(nlaSolver);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/api/sed/basictests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ TEST(BasicSedTest, combineArchiveWithUnknownDirectCellmlFile)
TEST(BasicSedTest, combineArchiveWithUnknownIndirectCellmlFile)
{
static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{
{libOpenCOR::Issue::Type::ERROR, "Task 'task1' requires a model of CellML type."},
{libOpenCOR::Issue::Type::ERROR, "Task: task 'task1' requires a model of CellML type."},
}};

auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/unknown_indirect_cellml_file.omex"))};
Expand Down
Loading
Loading