Skip to content
Snippets Groups Projects
Unverified Commit 6d7d044d authored by Oleg Alexandrov's avatar Oleg Alexandrov Committed by GitHub
Browse files

Check if the loaded model type is what is expected (#379)

* Check if the loaded model type is what is expected when loading from state

* Minor code touchup
parent 25a96b20
No related branches found
No related tags found
No related merge requests found
...@@ -121,36 +121,41 @@ csm::Version UsgsAstroPlugin::getModelVersion( ...@@ -121,36 +121,41 @@ csm::Version UsgsAstroPlugin::getModelVersion(
bool UsgsAstroPlugin::canModelBeConstructedFromState( bool UsgsAstroPlugin::canModelBeConstructedFromState(
const std::string &modelName, const std::string &modelState, const std::string &modelName, const std::string &modelState,
csm::WarningList *warnings) const { csm::WarningList *warnings) const {
std::string err_msg;
try { try {
csm::Model *model = constructModelFromState(modelState, warnings); // Use a shared_ptr to not have to manually deallocate the pointer
std::shared_ptr<csm::Model> model(constructModelFromState(modelState, warnings));
if (model) { if (model) {
delete model; // The created model name
std::string createdModelName = model->getModelName();
// If the model is of expected type, all is good
if (createdModelName == modelName)
return true; return true;
// Need to stay on to deal with the fact that the model is not of expected type.
err_msg = "Created a model of type " + createdModelName + " instead of the expected "
+ modelName;
} }
} catch (std::exception &e) { } catch (std::exception &e) {
std::string msg = "Could not create model ["; err_msg = e.what();
msg += modelName;
msg += "] with error [";
msg += e.what();
msg += "]";
MESSAGE_LOG(msg);
if (warnings) {
warnings->push_back(csm::Warning(
csm::Warning::UNKNOWN_WARNING, msg,
"UsgsAstroFrameSensorModel::canModelBeConstructedFromState()"));
}
return false;
} catch (...) { } catch (...) {
std::string msg = "Could not create model ["; err_msg = "Unknown error";
msg += modelName; }
msg += "] with an unknown error.";
MESSAGE_LOG(msg); std::string fullMsg = "Could not create model [";
fullMsg += modelName;
fullMsg += "] with error [";
fullMsg += err_msg;
fullMsg += "]";
MESSAGE_LOG(fullMsg);
if (warnings) { if (warnings) {
warnings->push_back(csm::Warning( warnings->push_back(csm::Warning
csm::Warning::UNKNOWN_WARNING, msg, (csm::Warning::UNKNOWN_WARNING, fullMsg,
"UsgsAstroFrameSensorModel::canModelBeConstructedFromState()")); "UsgsAstroFrameSensorModel::canModelBeConstructedFromState()"));
} }
}
return false; return false;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment