Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove an instance of boost::any #453

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions src/storm/builder/StateAndChoiceInformationBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool StateAndChoiceInformationBuilder::isBuildChoiceOrigins() const {
return _buildChoiceOrigins;
}

void StateAndChoiceInformationBuilder::addChoiceOriginData(boost::any const& originData, uint_fast64_t choiceIndex) {
void StateAndChoiceInformationBuilder::addChoiceOriginData(std::any const& originData, uint_fast64_t choiceIndex) {
STORM_LOG_ASSERT(_buildChoiceOrigins, "Building ChoiceOrigins was not enabled.");
STORM_LOG_ASSERT(_dataOfChoiceOrigins.size() <= choiceIndex, "Unexpected choice index. Apparently, the choice indices are provided in an incorrect order.");
if (_dataOfChoiceOrigins.size() != choiceIndex) {
Expand All @@ -51,7 +51,7 @@ void StateAndChoiceInformationBuilder::addChoiceOriginData(boost::any const& ori
_dataOfChoiceOrigins.push_back(originData);
}

std::vector<boost::any> StateAndChoiceInformationBuilder::buildDataOfChoiceOrigins(uint_fast64_t totalNumberOfChoices) {
std::vector<std::any> StateAndChoiceInformationBuilder::buildDataOfChoiceOrigins(uint_fast64_t totalNumberOfChoices) {
STORM_LOG_ASSERT(_buildChoiceOrigins, "Building ChoiceOrigins was not enabled.");
_dataOfChoiceOrigins.resize(totalNumberOfChoices);
_dataOfChoiceOrigins.shrink_to_fit();
Expand Down
8 changes: 4 additions & 4 deletions src/storm/builder/StateAndChoiceInformationBuilder.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <boost/any.hpp>
#include <any>
#include <memory>
#include <string>
#include <unordered_map>
Expand Down Expand Up @@ -31,8 +31,8 @@ class StateAndChoiceInformationBuilder {

void setBuildChoiceOrigins(bool value);
bool isBuildChoiceOrigins() const;
void addChoiceOriginData(boost::any const& originData, uint_fast64_t choiceIndex);
std::vector<boost::any> buildDataOfChoiceOrigins(uint_fast64_t totalNumberOfChoices);
void addChoiceOriginData(std::any const& originData, uint_fast64_t choiceIndex);
std::vector<std::any> buildDataOfChoiceOrigins(uint_fast64_t totalNumberOfChoices);

void setBuildStatePlayerIndications(bool value);
bool isBuildStatePlayerIndications() const;
Expand All @@ -57,7 +57,7 @@ class StateAndChoiceInformationBuilder {
std::unordered_map<std::string, storm::storage::BitVector> _choiceLabels;

bool _buildChoiceOrigins;
std::vector<boost::any> _dataOfChoiceOrigins;
std::vector<std::any> _dataOfChoiceOrigins;

bool _buildStatePlayerIndications;
std::vector<storm::storage::PlayerIndex> _statePlayerIndications;
Expand Down
12 changes: 6 additions & 6 deletions src/storm/generator/Choice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ storm::storage::PlayerIndex const& Choice<ValueType, StateType>::getPlayerIndex(
}

template<typename ValueType, typename StateType>
void Choice<ValueType, StateType>::addOriginData(boost::any const& data) {
if (!this->originData || this->originData->empty()) {
void Choice<ValueType, StateType>::addOriginData(std::any const& data) {
if (!this->originData || !this->originData->has_value()) {
this->originData = data;
} else {
if (!data.empty()) {
if (data.has_value()) {
// Reaching this point means that the both the existing and the given data are non-empty

auto existingDataAsIndexSet = boost::any_cast<storm::storage::FlatSet<uint_fast64_t>>(&this->originData.get());
auto existingDataAsIndexSet = std::any_cast<storm::storage::FlatSet<uint_fast64_t>>(&this->originData.get());
if (existingDataAsIndexSet != nullptr) {
auto givenDataAsIndexSet = boost::any_cast<storm::storage::FlatSet<uint_fast64_t>>(&data);
auto givenDataAsIndexSet = std::any_cast<storm::storage::FlatSet<uint_fast64_t>>(&data);
STORM_LOG_THROW(givenDataAsIndexSet != nullptr, storm::exceptions::InvalidOperationException,
"Types of existing and given choice origin data do not match.");
existingDataAsIndexSet->insert(givenDataAsIndexSet->begin(), givenDataAsIndexSet->end());
Expand All @@ -140,7 +140,7 @@ bool Choice<ValueType, StateType>::hasOriginData() const {
}

template<typename ValueType, typename StateType>
boost::any const& Choice<ValueType, StateType>::getOriginData() const {
std::any const& Choice<ValueType, StateType>::getOriginData() const {
return originData.get();
}

Expand Down
8 changes: 4 additions & 4 deletions src/storm/generator/Choice.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef STORM_GENERATOR_CHOICE_H_
#define STORM_GENERATOR_CHOICE_H_

#include <any>
#include <cstdint>
#include <functional>
#include <set>

#include <boost/any.hpp>
#include <boost/optional.hpp>

#include "storm/storage/Distribution.h"
Expand Down Expand Up @@ -125,7 +125,7 @@ struct Choice {
/*!
* Adds the given data that specifies the origin of this choice w.r.t. the model specification
*/
void addOriginData(boost::any const& data);
void addOriginData(std::any const& data);

/*!
* Returns whether there is origin data defined for this choice
Expand All @@ -135,7 +135,7 @@ struct Choice {
/*!
* Returns the origin data associated with this choice.
*/
boost::any const& getOriginData() const;
std::any const& getOriginData() const;

/*!
* Retrieves the index of the action of this choice.
Expand Down Expand Up @@ -203,7 +203,7 @@ struct Choice {
std::vector<ValueType> rewards;

// The data that stores what part of the model specification induced this choice
boost::optional<boost::any> originData;
boost::optional<std::any> originData;

// The labels of this choice
boost::optional<std::set<std::string>> labels;
Expand Down
12 changes: 6 additions & 6 deletions src/storm/generator/JaniNextStateGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ void JaniNextStateGenerator<ValueType, StateType>::expandSynchronizingEdgeCombin

// Add the edge indices if requested.
if (this->getOptions().isBuildChoiceOriginsSet()) {
choice.addOriginData(boost::any(std::move(edgeIndices)));
choice.addOriginData(std::any(std::move(edgeIndices)));
}

// Add the rewards to the choice.
Expand Down Expand Up @@ -1070,7 +1070,7 @@ std::vector<Choice<ValueType>> JaniNextStateGenerator<ValueType, StateType>::get

if (this->getOptions().isBuildChoiceOriginsSet()) {
EdgeIndexSet edgeIndex{model.encodeAutomatonAndEdgeIndices(automatonIndex, indexAndEdge.first)};
result.back().addOriginData(boost::any(std::move(edgeIndex)));
result.back().addOriginData(std::any(std::move(edgeIndex)));
}
}
}
Expand Down Expand Up @@ -1350,7 +1350,7 @@ void JaniNextStateGenerator<ValueType, StateType>::createSynchronizationInformat

template<typename ValueType, typename StateType>
std::shared_ptr<storm::storage::sparse::ChoiceOrigins> JaniNextStateGenerator<ValueType, StateType>::generateChoiceOrigins(
std::vector<boost::any>& dataForChoiceOrigins) const {
std::vector<std::any>& dataForChoiceOrigins) const {
if (!this->getOptions().isBuildChoiceOriginsSet()) {
return nullptr;
}
Expand All @@ -1363,11 +1363,11 @@ std::shared_ptr<storm::storage::sparse::ChoiceOrigins> JaniNextStateGenerator<Va
STORM_LOG_ASSERT(storm::storage::sparse::ChoiceOrigins::getIdentifierForChoicesWithNoOrigin() == 0, "The no origin identifier is assumed to be zero");
edgeIndexSetToIdentifierMap.insert(std::make_pair(EdgeIndexSet(), 0));
uint_fast64_t currentIdentifier = 1;
for (boost::any& originData : dataForChoiceOrigins) {
STORM_LOG_ASSERT(originData.empty() || boost::any_cast<EdgeIndexSet>(&originData) != nullptr,
for (std::any& originData : dataForChoiceOrigins) {
STORM_LOG_ASSERT(!originData.has_value() || std::any_cast<EdgeIndexSet>(&originData) != nullptr,
"Origin data has unexpected type: " << originData.type().name() << ".");

EdgeIndexSet currentEdgeIndexSet = originData.empty() ? EdgeIndexSet() : boost::any_cast<EdgeIndexSet>(std::move(originData));
EdgeIndexSet currentEdgeIndexSet = !originData.has_value() ? EdgeIndexSet() : std::any_cast<EdgeIndexSet>(std::move(originData));
auto insertionRes = edgeIndexSetToIdentifierMap.emplace(std::move(currentEdgeIndexSet), currentIdentifier);
identifiers.push_back(insertionRes.first->second);
if (insertionRes.second) {
Expand Down
2 changes: 1 addition & 1 deletion src/storm/generator/JaniNextStateGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class JaniNextStateGenerator : public NextStateGenerator<ValueType, StateType> {
std::vector<StateType> const& initialStateIndices = {},
std::vector<StateType> const& deadlockStateIndices = {}) override;

virtual std::shared_ptr<storm::storage::sparse::ChoiceOrigins> generateChoiceOrigins(std::vector<boost::any>& dataForChoiceOrigins) const override;
virtual std::shared_ptr<storm::storage::sparse::ChoiceOrigins> generateChoiceOrigins(std::vector<std::any>& dataForChoiceOrigins) const override;

/*!
* Sets the values of all transient variables in the current state to the given evaluator.
Expand Down
2 changes: 1 addition & 1 deletion src/storm/generator/NextStateGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void NextStateGenerator<ValueType, StateType>::extendStateInformation(storm::jso

template<typename ValueType, typename StateType>
std::shared_ptr<storm::storage::sparse::ChoiceOrigins> NextStateGenerator<ValueType, StateType>::generateChoiceOrigins(
std::vector<boost::any>& dataForChoiceOrigins) const {
std::vector<std::any>& dataForChoiceOrigins) const {
STORM_LOG_ERROR_COND(!options.isBuildChoiceOriginsSet(), "Generating choice origins is not supported for the considered model format.");
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion src/storm/generator/NextStateGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class NextStateGenerator {

VariableInformation const& getVariableInformation() const;

virtual std::shared_ptr<storm::storage::sparse::ChoiceOrigins> generateChoiceOrigins(std::vector<boost::any>& dataForChoiceOrigins) const;
virtual std::shared_ptr<storm::storage::sparse::ChoiceOrigins> generateChoiceOrigins(std::vector<std::any>& dataForChoiceOrigins) const;

/*!
* Performs a remapping of all values stored by applying the given remapping.
Expand Down
12 changes: 6 additions & 6 deletions src/storm/generator/PrismNextStateGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ std::vector<Choice<ValueType>> PrismNextStateGenerator<ValueType, StateType>::ge
// Remember the choice origin only if we were asked to.
if (this->options.isBuildChoiceOriginsSet()) {
CommandSet commandIndex{command.getGlobalIndex()};
choice.addOriginData(boost::any(std::move(commandIndex)));
choice.addOriginData(std::any(std::move(commandIndex)));
}

// Iterate over all updates of the current command.
Expand Down Expand Up @@ -755,7 +755,7 @@ void PrismNextStateGenerator<ValueType, StateType>::addSynchronousChoices(std::v
for (uint_fast64_t i = 0; i < iteratorList.size(); ++i) {
commandIndices.insert(iteratorList[i]->get().getGlobalIndex());
}
choice.addOriginData(boost::any(std::move(commandIndices)));
choice.addOriginData(std::any(std::move(commandIndices)));
}

// Add the probabilities/rates to the newly created choice.
Expand Down Expand Up @@ -872,7 +872,7 @@ storm::builder::RewardModelInformation PrismNextStateGenerator<ValueType, StateT

template<typename ValueType, typename StateType>
std::shared_ptr<storm::storage::sparse::ChoiceOrigins> PrismNextStateGenerator<ValueType, StateType>::generateChoiceOrigins(
std::vector<boost::any>& dataForChoiceOrigins) const {
std::vector<std::any>& dataForChoiceOrigins) const {
if (!this->getOptions().isBuildChoiceOriginsSet()) {
return nullptr;
}
Expand All @@ -885,11 +885,11 @@ std::shared_ptr<storm::storage::sparse::ChoiceOrigins> PrismNextStateGenerator<V
STORM_LOG_ASSERT(storm::storage::sparse::ChoiceOrigins::getIdentifierForChoicesWithNoOrigin() == 0, "The no origin identifier is assumed to be zero");
commandSetToIdentifierMap.insert(std::make_pair(CommandSet(), 0));
uint_fast64_t currentIdentifier = 1;
for (boost::any& originData : dataForChoiceOrigins) {
STORM_LOG_ASSERT(originData.empty() || boost::any_cast<CommandSet>(&originData) != nullptr,
for (std::any& originData : dataForChoiceOrigins) {
STORM_LOG_ASSERT(!originData.has_value() || std::any_cast<CommandSet>(&originData) != nullptr,
"Origin data has unexpected type: " << originData.type().name() << ".");

CommandSet currentCommandSet = originData.empty() ? CommandSet() : boost::any_cast<CommandSet>(std::move(originData));
CommandSet currentCommandSet = !originData.has_value() ? CommandSet() : std::any_cast<CommandSet>(std::move(originData));
auto insertionRes = commandSetToIdentifierMap.insert(std::make_pair(std::move(currentCommandSet), currentIdentifier));
identifiers.push_back(insertionRes.first->second);
if (insertionRes.second) {
Expand Down
2 changes: 1 addition & 1 deletion src/storm/generator/PrismNextStateGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PrismNextStateGenerator : public NextStateGenerator<ValueType, StateType>
std::vector<StateType> const& initialStateIndices = {},
std::vector<StateType> const& deadlockStateIndices = {}) override;

virtual std::shared_ptr<storm::storage::sparse::ChoiceOrigins> generateChoiceOrigins(std::vector<boost::any>& dataForChoiceOrigins) const override;
virtual std::shared_ptr<storm::storage::sparse::ChoiceOrigins> generateChoiceOrigins(std::vector<std::any>& dataForChoiceOrigins) const override;

private:
void checkValid() const;
Expand Down
Loading