From a0d770611b245ffdbe4fb0768375616b44b42c27 Mon Sep 17 00:00:00 2001 From: Max Franke Date: Mon, 1 Aug 2016 21:21:49 +0200 Subject: [PATCH] Bytes now get written into unsigned char This fixes #17 Signed-off-by: Max Franke --- .../standard_single_byte_transition_counter.cpp | 13 +++++-------- .../standard_single_byte_transition_counter.hpp | 6 +++--- src/io/filereader.cpp | 6 +++--- src/io/filereader.hpp | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/data/standard_single_byte_transition_counter.cpp b/src/data/standard_single_byte_transition_counter.cpp index c34876f..f35086c 100644 --- a/src/data/standard_single_byte_transition_counter.cpp +++ b/src/data/standard_single_byte_transition_counter.cpp @@ -20,31 +20,28 @@ data::StandardSingleByteTransitionCounter::run() { while (this->fileReader->operator bool()) // file reader has input still { - std::vector nextBlock = this->fileReader->getNext(1); + std::vector nextBlock = this->fileReader->getNext(1); this->handleBlock(nextBlock); } } } void -data::StandardSingleByteTransitionCounter::handleBlock(std::vector const& block) +data::StandardSingleByteTransitionCounter::handleBlock(std::vector const& block) { - for (char const& c : block) + for (unsigned char const& c : block) { this->nextChar(c); } } -void data::StandardSingleByteTransitionCounter::nextChar(char const& c) +void data::StandardSingleByteTransitionCounter::nextChar(unsigned char const& c) { if (this->started) { size_t x = static_cast(c); size_t y = static_cast(this->last); - if (x < 256 && y < 256) - { - this->histogram.addEntry(x,y); - } + this->histogram.addEntry(x,y); } else { diff --git a/src/data/standard_single_byte_transition_counter.hpp b/src/data/standard_single_byte_transition_counter.hpp index f5696ca..f2c66b6 100644 --- a/src/data/standard_single_byte_transition_counter.hpp +++ b/src/data/standard_single_byte_transition_counter.hpp @@ -9,12 +9,12 @@ namespace data Histogram const& getHistogram() const override; void run() override; private: - void handleBlock(std::vector const&); - void nextChar(char const&); + void handleBlock(std::vector const&); + void nextChar(unsigned char const&); Histogram histogram; std::shared_ptr fileReader; bool started = false; - char last = 0x00; + unsigned char last = 0x00; }; } diff --git a/src/io/filereader.cpp b/src/io/filereader.cpp index ca305a5..b191604 100644 --- a/src/io/filereader.cpp +++ b/src/io/filereader.cpp @@ -28,9 +28,9 @@ io::FileReader::operator bool () const return bool(*(this->input)); // evaluate badness of stream } -std::vector io::FileReader::getNext(size_t const& numberBytes) +std::vector io::FileReader::getNext(size_t const& numberBytes) { - std::vector v; + std::vector v; char c; for (size_t i = 0; i < numberBytes && this->input; ++i) @@ -41,7 +41,7 @@ std::vector io::FileReader::getNext(size_t const& numberBytes) } else { - v.push_back(c); + v.push_back(static_cast(c)); } } diff --git a/src/io/filereader.hpp b/src/io/filereader.hpp index 344e094..2eacbab 100644 --- a/src/io/filereader.hpp +++ b/src/io/filereader.hpp @@ -36,7 +36,7 @@ namespace io { * \param Number of bytes (n) * \return vector of bytes */ - std::vector getNext(size_t const&); + std::vector getNext(size_t const&); protected: FileReader(FileReader const&) = delete;