Browse Source

fixed valgrind errors

creating new shared_ptr instances from a raw pointer (i.e. shared_ptr<>(this) or alike) destroys the internal reference counting.
To make this work, one can use std::enable_shared_from_this(), which solves our problem here.
tempestpy_adaptions
gereon 12 years ago
parent
commit
4fd1d672ef
  1. 4
      src/models/AbstractModel.h
  2. 6
      src/parser/DeterministicModelParser.h

4
src/models/AbstractModel.h

@ -24,7 +24,7 @@ std::ostream& operator<<(std::ostream& os, ModelType const type);
* This is base class defines a common interface for all models to identify
* their type and obtain the special model.
*/
class AbstractModel {
class AbstractModel: public std::enable_shared_from_this<AbstractModel> {
public:
/*!
@ -44,7 +44,7 @@ class AbstractModel {
*/
template <typename Model>
std::shared_ptr<Model> as() {
return std::dynamic_pointer_cast<Model>(std::shared_ptr<AbstractModel>(this));
return std::dynamic_pointer_cast<Model>(shared_from_this());
}
/*!

6
src/parser/DeterministicModelParser.h

@ -28,12 +28,18 @@ class DeterministicModelParser: public storm::parser::Parser {
DeterministicModelParser(std::string const & transitionSystemFile, std::string const & labelingFile,
std::string const & stateRewardFile = "", std::string const & transitionRewardFile = "");
/*!
* @brief Get the parsed dtmc model.
*/
std::shared_ptr<storm::models::Dtmc<double>> getDtmc() {
if (this->dtmc == nullptr) {
this->dtmc = std::shared_ptr<storm::models::Dtmc<double>>(new storm::models::Dtmc<double>(this->transitionSystem, this->labeling, this->stateRewards, this->transitionRewards));
}
return this->dtmc;
}
/*!
* @brief Get the parsed ctmc model.
*/
std::shared_ptr<storm::models::Ctmc<double>> getCtmc() {
if (this->ctmc == nullptr) {
this->ctmc = std::shared_ptr<storm::models::Ctmc<double>>(new storm::models::Ctmc<double>(this->transitionSystem, this->labeling, this->stateRewards, this->transitionRewards));

Loading…
Cancel
Save