Skip to content

Commit

Permalink
Bytes now get written into unsigned char
Browse files Browse the repository at this point in the history
This fixes #17

Signed-off-by: Max Franke <max@mumintroll.org>
  • Loading branch information
mfranke93 committed Aug 1, 2016
1 parent 0fedef8 commit a0d7706
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
13 changes: 5 additions & 8 deletions src/data/standard_single_byte_transition_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,28 @@ data::StandardSingleByteTransitionCounter::run()
{
while (this->fileReader->operator bool()) // file reader has input still
{
std::vector<char> nextBlock = this->fileReader->getNext(1);
std::vector<unsigned char> nextBlock = this->fileReader->getNext(1);
this->handleBlock(nextBlock);
}
}
}

void
data::StandardSingleByteTransitionCounter::handleBlock(std::vector<char> const& block)
data::StandardSingleByteTransitionCounter::handleBlock(std::vector<unsigned char> 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<size_t>(c);
size_t y = static_cast<size_t>(this->last);
if (x < 256 && y < 256)
{
this->histogram.addEntry(x,y);
}
this->histogram.addEntry(x,y);
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/data/standard_single_byte_transition_counter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace data
Histogram const& getHistogram() const override;
void run() override;
private:
void handleBlock(std::vector<char> const&);
void nextChar(char const&);
void handleBlock(std::vector<unsigned char> const&);
void nextChar(unsigned char const&);

Histogram histogram;
std::shared_ptr<io::FileReader> fileReader;
bool started = false;
char last = 0x00;
unsigned char last = 0x00;
};
}
6 changes: 3 additions & 3 deletions src/io/filereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ io::FileReader::operator bool () const
return bool(*(this->input)); // evaluate badness of stream
}

std::vector<char> io::FileReader::getNext(size_t const& numberBytes)
std::vector<unsigned char> io::FileReader::getNext(size_t const& numberBytes)
{
std::vector<char> v;
std::vector<unsigned char> v;
char c;

for (size_t i = 0; i < numberBytes && this->input; ++i)
Expand All @@ -41,7 +41,7 @@ std::vector<char> io::FileReader::getNext(size_t const& numberBytes)
}
else
{
v.push_back(c);
v.push_back(static_cast<unsigned char>(c));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/io/filereader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace io {
* \param Number of bytes (n)
* \return vector of bytes
*/
std::vector<char> getNext(size_t const&);
std::vector<unsigned char> getNext(size_t const&);

protected:
FileReader(FileReader const&) = delete;
Expand Down

0 comments on commit a0d7706

Please sign in to comment.