This repository has been archived on 2019-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
2012-09-09 20:50:15 +00:00
|
|
|
/*
|
|
|
|
* String.h
|
|
|
|
*
|
|
|
|
* Created on: 19.07.2012
|
|
|
|
* Author: Felix
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use this as a replacement for std::to_string as MingW does not support it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DG_STRING_H_
|
|
|
|
#define DG_STRING_H_
|
|
|
|
|
|
|
|
#include <sstream>
|
2012-10-11 21:24:22 +00:00
|
|
|
#include <string>
|
2012-09-09 20:50:15 +00:00
|
|
|
|
2012-10-11 21:24:22 +00:00
|
|
|
typedef std::string String;
|
2012-09-09 20:50:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts any value to a string.
|
|
|
|
*
|
|
|
|
* @param val Any variable.
|
|
|
|
* @return val converted to string.
|
|
|
|
*/
|
|
|
|
template <typename T>
|
2012-10-11 21:24:22 +00:00
|
|
|
String
|
2012-09-09 20:50:15 +00:00
|
|
|
str(T val) {
|
|
|
|
std::stringstream out;
|
|
|
|
out << val;
|
|
|
|
return out.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts floating point variable to string,
|
|
|
|
*
|
|
|
|
* @param val Any floating point variable.
|
|
|
|
* @param digits Number of decimal places to round to.
|
|
|
|
* @return val converted to string.
|
|
|
|
*/
|
|
|
|
template <typename T>
|
2012-10-11 21:24:22 +00:00
|
|
|
String
|
2012-09-09 20:50:15 +00:00
|
|
|
str(T val, int digits) {
|
|
|
|
std::stringstream out;
|
|
|
|
out.precision(digits);
|
|
|
|
out << val;
|
|
|
|
return out.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DG_STRING_H_ */
|