changed everything to impl
This commit is contained in:
75
FlippR-Driver/src/output/items/impl/Display.hpp
Normal file
75
FlippR-Driver/src/output/items/impl/Display.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// Created by rhetenor on 10.10.18.
|
||||
//
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace items
|
||||
{
|
||||
namespace impl
|
||||
{
|
||||
|
||||
template<int DigitCount>
|
||||
Display<DigitCount>::Display(int address, int id) :
|
||||
address(address),
|
||||
id(id)
|
||||
{
|
||||
}
|
||||
|
||||
template<int DigitCount>
|
||||
int Display<DigitCount>::getID()
|
||||
{
|
||||
return this->id;
|
||||
}
|
||||
|
||||
template<int DigitCount>
|
||||
void Display<DigitCount>::write_score(int score)
|
||||
{
|
||||
auto score_string = std::to_string(score);
|
||||
|
||||
auto score_c_string = this->fit_string(score_string).c_str();
|
||||
|
||||
std::copy(std::begin(score_c_string), std::end(score_c_string), std::begin(this->content));
|
||||
}
|
||||
|
||||
template<int DigitCount>
|
||||
std::string Display<DigitCount>::fit_string(std::string& score_string)
|
||||
{
|
||||
auto score_length = score_string.length();
|
||||
|
||||
if (score_length > DigitCount)
|
||||
{
|
||||
CLOG(DEBUG, OUTPUT_LOGGER) << "Score too long for display";
|
||||
std::string full_display;
|
||||
// TODO mach mal schöner hier wird 9999 angezeigt wenn die zahl zu groß is
|
||||
return full_display.insert(0, DigitCount, '9');
|
||||
}
|
||||
|
||||
score_string.insert(0, DigitCount-score_length, '\0');
|
||||
return score_string;
|
||||
}
|
||||
|
||||
template<int DigitCount>
|
||||
void Display<DigitCount>::write_content( std::array<char, DigitCount> content)
|
||||
{
|
||||
this->content = content;
|
||||
}
|
||||
|
||||
<int DigitCount>
|
||||
std::vector<char> Display<DigitCount>::get_content()
|
||||
{
|
||||
// todo: expensive?
|
||||
return std::vector<char>(content, content + DigitCount);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user