service interface stream enhancements #93

Merged
gaisser merged 14 commits from KSat/fsfw:mueller_ServiceStreamEnhancement into master 2020-07-21 12:18:20 +02:00
Showing only changes of commit 1cb241ca0c - Show all commits

View File

@ -1,6 +1,7 @@
#ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_ #ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_
#define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_ #define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
@ -58,21 +59,33 @@ private:
/** /**
* This helper function returns the zero padded string version of a number. * This helper function returns the zero padded string version of a number.
* The type is deduced automatically. * The type is deduced automatically.
* TODO: This uses dynamic memory allocation, so we should provide
* a custom streambuf class to use it (which takes maxSize as argument)
* Then we would propably
* @tparam T * @tparam T
* @param num * @param num
* @param width * @param width
* @return * @return
*/ */
template<typename T> template<typename T>
std::string zero_padded(const T& num, uint8_t width) { ReturnValue_t zeroPadded(std::string stringToFill, const T& num,
std::ostringstream string_to_pad; uint8_t width) {
string_to_pad << std::setw(width) << std::setfill('0') << num; auto numString = std::to_string(num);
std::string result = string_to_pad.str(); uint8_t i = 0;
if (result.length() > width) for(i = 0; i < width; i++) {
{ stringToFill[i] = '0';
result.erase(0, result.length() - width); }
} numString.copy(stringToFill.data() + i, numString.size());
return result; // std::streambuf streambuf;
// std::ostringstream string_to_pad;
// string_to_pad << std::setw(width) << std::setfill('0') << num;
// std::string result = string_to_pad.str();
// if (result.length() > width)
// {
// result.erase(0, result.length() - width);
// }
// return result;
//std::string dest = std::string( number_of_zeros, '0').append( original_string);
} }
}; };