changed display write method
This commit is contained in:
@@ -31,17 +31,28 @@ template<int DigitCount>
|
|||||||
void Display<DigitCount>::write_score(int score)
|
void Display<DigitCount>::write_score(int score)
|
||||||
{
|
{
|
||||||
auto score_string = std::to_string(score);
|
auto score_string = std::to_string(score);
|
||||||
auto score_length = score_string.length();
|
if (score_string.length() > DigitCount)
|
||||||
if (score_length > DigitCount)
|
|
||||||
{
|
{
|
||||||
CLOG(DEBUG, OUTPUT_LOGGER) << "Score too long for display";
|
CLOG(DEBUG, OUTPUT_LOGGER) << "Score too long for display";
|
||||||
this->content = score_string.substr(score_length-DigitCount,score_length);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string spaces;
|
auto score_c_string = this->fit_string(score_string).c_str();
|
||||||
std::generate_n(spaces.begin(), DigitCount-score_length, []{return " ";});
|
|
||||||
this->content = spaces + score_string;
|
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();
|
||||||
|
for (int i = 0; i < DigitCount; i++)
|
||||||
|
{
|
||||||
|
score_string = " " + score_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
score_length = score_string.length();
|
||||||
|
|
||||||
|
return score_string.substr(score_length-DigitCount, score_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int DigitCount>
|
template<int DigitCount>
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
int address;
|
int address;
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
|
std::string fit_string(std::string& score_string);
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace output */
|
} /* namespace output */
|
||||||
|
|||||||
Reference in New Issue
Block a user