From bf5de84ab9ce04aa040eb0208cb5938017b0acea Mon Sep 17 00:00:00 2001 From: PBerger Date: Thu, 13 Jun 2013 19:59:13 +0200 Subject: [PATCH] Refactored the parsing and lineFeeding handling. Former-commit-id: 5f46c55c22190b8f3361e29b14e18d0e0faf122f --- .../AtomicPropositionLabelingParser.cpp | 31 ++--------------- src/parser/Parser.cpp | 33 +++++++++++++++++++ src/parser/Parser.h | 5 +++ src/storage/BitVector.h | 2 +- 4 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/parser/AtomicPropositionLabelingParser.cpp b/src/parser/AtomicPropositionLabelingParser.cpp index 863e1198e..65228ec7b 100644 --- a/src/parser/AtomicPropositionLabelingParser.cpp +++ b/src/parser/AtomicPropositionLabelingParser.cpp @@ -61,34 +61,7 @@ storm::models::AtomicPropositionsLabeling AtomicPropositionLabelingParser(uint_f * First run: obtain number of propositions. */ char separator[5];// = " \r\n\t"; - switch (lineEndings) { - case SupportedLineEndingsEnum::SlashN: - separator[0] = ' '; - separator[1] = '\n'; - separator[2] = '\t'; - separator[3] = '\0'; - separator[4] = '\0'; - break; - case SupportedLineEndingsEnum::SlashR: - separator[0] = ' '; - separator[1] = '\r'; - separator[2] = '\t'; - separator[3] = '\0'; - separator[4] = '\0'; - break; - case SupportedLineEndingsEnum::SlashRN: - separator[0] = ' '; - separator[1] = '\r'; - separator[2] = '\n'; - separator[3] = '\t'; - separator[4] = '\0'; - break; - default: - case SupportedLineEndingsEnum::Unsupported: - // This Line will never be reached as the Parser would have thrown already. - throw; - break; - } + storm::parser::getMatchingSeparatorString(separator, sizeof(separator), lineEndings); bool foundDecl = false, foundEnd = false; uint_fast32_t proposition_count = 0; @@ -214,7 +187,7 @@ storm::models::AtomicPropositionsLabeling AtomicPropositionLabelingParser(uint_f buf += cnt; } } - buf = trimWhitespaces(buf); + buf = storm::parser::trimWhitespaces(buf); } } return labeling; diff --git a/src/parser/Parser.cpp b/src/parser/Parser.cpp index da2c7bb93..ae12cea9f 100644 --- a/src/parser/Parser.cpp +++ b/src/parser/Parser.cpp @@ -161,6 +161,39 @@ void storm::parser::scanForModelHint(char* targetBuffer, uint_fast64_t targetBuf } } +/*! + * @brief Returns the matching Separator-String in the format of "BLANK\t\NEWLINESYMBOL(S)\0 + */ +void storm::parser::getMatchingSeparatorString(char* targetBuffer, uint_fast64_t targetBufferSize, storm::parser::SupportedLineEndingsEnum lineEndings) { + if (targetBufferSize < 5) { + LOG4CPLUS_ERROR(logger, "storm::parser::getMatchingSeparatorString: The passed Target Buffer is too small."); + throw; + } + switch (lineEndings) { + case SupportedLineEndingsEnum::SlashN: { + char source[] = " \n\t"; + strncpy(targetBuffer, targetBufferSize, source, sizeof(source)); + break; + } + case SupportedLineEndingsEnum::SlashR: { + char source[] = " \r\t"; + strncpy(targetBuffer, targetBufferSize, source, sizeof(source)); + break; + } + case SupportedLineEndingsEnum::SlashRN: { + char source[] = " \r\n\t"; + strncpy(targetBuffer, targetBufferSize, source, sizeof(source)); + break; + } + default: + case SupportedLineEndingsEnum::Unsupported: + // This Line will never be reached as the Parser would have thrown already. + LOG4CPLUS_ERROR(logger, "storm::parser::getMatchingSeparatorString: The passed lineEndings were Unsupported. Check your input file."); + throw; + break; + } +} + /*! * Will stat the given file, open it and map it to memory. * If anything of this fails, an appropriate exception is raised diff --git a/src/parser/Parser.h b/src/parser/Parser.h index 29c6073de..f934ec50a 100644 --- a/src/parser/Parser.h +++ b/src/parser/Parser.h @@ -163,6 +163,11 @@ namespace parser { */ void scanForModelHint(char* targetBuffer, uint_fast64_t targetBufferSize, char const* buffer, storm::parser::SupportedLineEndingsEnum lineEndings); + /*! + * @brief Returns the matching Separator-String in the format of "BLANK\t\NEWLINESYMBOL(S)\0 + */ + void getMatchingSeparatorString(char* targetBuffer, uint_fast64_t targetBufferSize, storm::parser::SupportedLineEndingsEnum lineEndings); + } // namespace parser } // namespace storm diff --git a/src/storage/BitVector.h b/src/storage/BitVector.h index e3750f9cb..2e9a016f5 100644 --- a/src/storage/BitVector.h +++ b/src/storage/BitVector.h @@ -143,7 +143,7 @@ public: * Copy Constructor. Performs a deep copy of the given bit vector. * @param bv A reference to the bit vector to be copied. */ - BitVector(BitVector const& bv) : bucketCount(bv.bucketCount), bitCount(bv.bitCount), endIterator(*this, bitCount, bitCount, false), truncateMask((1ll << (bitCount & mod64mask)) - 1ll) { + BitVector(const BitVector & bv) : bucketCount(bv.bucketCount), bitCount(bv.bitCount), endIterator(*this, bitCount, bitCount, false), truncateMask((1ll << (bitCount & mod64mask)) - 1ll) { LOG4CPLUS_DEBUG(logger, "Invoking copy constructor."); bucketArray = new uint64_t[bucketCount]; std::copy(bv.bucketArray, bv.bucketArray + this->bucketCount, this->bucketArray);