graph.cc: coding style fixes

This commit is contained in:
Pawel "l0ner" Soltys 2015-01-17 23:48:54 +01:00
parent 1cc6b0c9ef
commit f2b75f7531
2 changed files with 32 additions and 22 deletions

@ -3,34 +3,42 @@
#include "graph.h" #include "graph.h"
char * getGraphByPercentage(unsigned value, unsigned len) { std::string get_graph_by_percentage(unsigned value, unsigned len)
unsigned step = 0; {
char * bars = new char[len + 1]; unsigned step = 0;
std::string bars;
unsigned barCount = (static_cast<float>(value) / 99.9 * len); unsigned bar_count = (static_cast<float>(value) / 99.9 * len);
for(step; step < barCount; step++) for(step; step < bar_count; step++)
bars[step] = '|'; {
for(step; step < len; step++) bars.append("|");
bars[step] = ' '; }
bars[len]='\0'; for(step; step < len; step++)
{
bars.append(" ");
}
return bars; return bars;
} }
char * getGraphByValue(unsigned value, unsigned max, unsigned len) { std::string get_graph_by_value(unsigned value, unsigned max, unsigned len)
unsigned step = 0; {
char * bars = new char[len + 1]; unsigned step = 0;
std::string bars;
unsigned barCount = (static_cast<float>(value / (max - 0.1)) * len); unsigned bar_count = (static_cast<float>(value / (max - 0.1)) * len);
for(step; step < barCount; step++) for(step; step < bar_count; step++)
bars[step] = '|'; {
for(step; step < len; step++) bars.append("|");
bars[step] = ' '; }
bars[len]='\0'; for(step; step < len; step++)
{
bars.append(" ");
}
return bars; return bars;
} }

@ -1,7 +1,9 @@
#ifndef GRAPH_H_ #ifndef GRAPH_H_
#define GRAPH_H_ #define GRAPH_H_
char * getGraphByPercentage(unsigned, unsigned len = 10); #include <string>
char * getGraphByValue(unsigned, unsigned, unsigned len = 10);
std::string get_graph_by_percentage(unsigned, unsigned len = 10);
std::string get_graph_by_value(unsigned, unsigned, unsigned len = 10);
#endif #endif