From 61f31fb91974d4bf474276fd2a4ff90989f0e3f9 Mon Sep 17 00:00:00 2001 From: Sebastian Junges Date: Thu, 3 May 2018 00:00:10 +0200 Subject: [PATCH] improved handling of capacities by switching to boost::optional --- src/storm-gspn/parser/GreatSpnEditorProjectParser.cpp | 2 +- src/storm-gspn/parser/PnmlParser.cpp | 5 ++--- src/storm-gspn/storage/gspn/GspnBuilder.cpp | 2 +- src/storm-gspn/storage/gspn/GspnBuilder.h | 2 +- src/storm-gspn/storage/gspn/Place.cpp | 2 +- src/storm-gspn/storage/gspn/Place.h | 4 ++-- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/storm-gspn/parser/GreatSpnEditorProjectParser.cpp b/src/storm-gspn/parser/GreatSpnEditorProjectParser.cpp index 2ab73ac91..ae17ca59b 100644 --- a/src/storm-gspn/parser/GreatSpnEditorProjectParser.cpp +++ b/src/storm-gspn/parser/GreatSpnEditorProjectParser.cpp @@ -212,7 +212,7 @@ namespace storm { STORM_PRINT_AND_LOG("unknown child (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); } } - builder.addPlace(-1, initialTokens, placeName); + builder.addPlace(boost::none, initialTokens, placeName); } bool ignoreTransitionAttribute(std::string const& name) { diff --git a/src/storm-gspn/parser/PnmlParser.cpp b/src/storm-gspn/parser/PnmlParser.cpp index 71757defc..189e34266 100644 --- a/src/storm-gspn/parser/PnmlParser.cpp +++ b/src/storm-gspn/parser/PnmlParser.cpp @@ -104,7 +104,7 @@ namespace storm { std::string placeName; // the first entry is false if the corresponding information was not found in the pnml file std::pair numberOfInitialTokens(false, defaultNumberOfInitialTokens); - std::pair capacity(false, defaultCapacity); + std::pair> capacity(false, boost::none); // traverse attributes for (uint_fast64_t i = 0; i < node->getAttributes()->getLength(); ++i) { @@ -150,10 +150,9 @@ namespace storm { } if (!capacity.first) { // no information about the capacity is found - // use default capacity STORM_PRINT_AND_LOG("unknown capacity (place=" + placeName + ")\n"); } - builder.addPlace(capacity.first ? capacity.second : -1, numberOfInitialTokens.first ? numberOfInitialTokens.second : 0, placeName); + builder.addPlace(capacity.second, numberOfInitialTokens.first ? numberOfInitialTokens.second : 0, placeName); } void PnmlParser::traverseTransition(xercesc::DOMNode const* const node) { diff --git a/src/storm-gspn/storage/gspn/GspnBuilder.cpp b/src/storm-gspn/storage/gspn/GspnBuilder.cpp index 5303a89c6..e273768ea 100644 --- a/src/storm-gspn/storage/gspn/GspnBuilder.cpp +++ b/src/storm-gspn/storage/gspn/GspnBuilder.cpp @@ -13,7 +13,7 @@ namespace storm { gspnName = name; } - uint_fast64_t GspnBuilder::addPlace(int_fast64_t const& capacity, uint_fast64_t const& initialTokens, std::string const& name) { + uint_fast64_t GspnBuilder::addPlace(boost::optional capacity, uint_fast64_t const& initialTokens, std::string const& name) { auto newId = places.size(); auto place = storm::gspn::Place(newId); place.setCapacity(capacity); diff --git a/src/storm-gspn/storage/gspn/GspnBuilder.h b/src/storm-gspn/storage/gspn/GspnBuilder.h index 79fb2e712..a9a99699f 100644 --- a/src/storm-gspn/storage/gspn/GspnBuilder.h +++ b/src/storm-gspn/storage/gspn/GspnBuilder.h @@ -25,7 +25,7 @@ namespace storm { * A capacity of -1 indicates an unbounded place. * @param initialTokens The number of inital tokens in the place. */ - uint_fast64_t addPlace(int_fast64_t const& capacity = 1, uint_fast64_t const& initialTokens = 0, std::string const& name = ""); + uint_fast64_t addPlace(boost::optional capacity = 1, uint_fast64_t const& initialTokens = 0, std::string const& name = ""); void setPlaceLayoutInfo(uint64_t placeId, LayoutInfo const& layoutInfo); diff --git a/src/storm-gspn/storage/gspn/Place.cpp b/src/storm-gspn/storage/gspn/Place.cpp index a78b7c585..d60ace5f6 100644 --- a/src/storm-gspn/storage/gspn/Place.cpp +++ b/src/storm-gspn/storage/gspn/Place.cpp @@ -29,7 +29,7 @@ namespace storm { return this->numberOfInitialTokens; } - void Place::setCapacity(uint64_t cap) { + void Place::setCapacity(boost::optional cap) { this->capacity = cap; } diff --git a/src/storm-gspn/storage/gspn/Place.h b/src/storm-gspn/storage/gspn/Place.h index e995f6a93..55c9da6fb 100644 --- a/src/storm-gspn/storage/gspn/Place.h +++ b/src/storm-gspn/storage/gspn/Place.h @@ -54,9 +54,9 @@ namespace storm { * Sets the capacity of tokens of this place. * * @param capacity The capacity of this place. A non-negative number represents the capacity. - * The value -1 indicates that the capacity is not set. + * boost::none indicates that the flag is not set. */ - void setCapacity(uint64_t capacity); + void setCapacity(boost::optional capacity); /*! * Returns the capacity of tokens of this place.