48 std::ostringstream oss;
49 oss.setf(std::ios::fixed, std::ios::floatfield);
50 oss << std::setprecision(accuracy);
57 inline std::string
toHex(
const T i, std::streamsize numDigits = 0) {
59 std::stringstream stream;
60 stream <<
"0x" << std::setfill(
'0') << std::setw(numDigits == 0 ?
sizeof(T) * 2 : numDigits) << std::hex << i;
65 inline std::string
toString(
const Named* obj, std::streamsize accuracy) {
168 std::ostringstream oss;
169 for (std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); ++it) {
184 return dist.
toStr(accuracy);
187 template <
typename V>
189 return toString<V>(v.begin(), v.end(), accuracy);
192 template <
typename V>
193 inline std::string
toString(
const typename std::vector<V*>::const_iterator& b,
const typename std::vector<V*>::const_iterator& e, std::streamsize accuracy =
gPrecision) {
195 std::ostringstream oss;
196 for (
typename std::vector<V*>::const_iterator it = b; it != e; ++it) {
205 template <
typename V>
207 return toString<V>(v.begin(), v.end(), accuracy);
210 template <
typename V>
211 inline std::string
toString(
const typename std::list<V*>::const_iterator& b,
const typename std::list<V*>::const_iterator& e, std::streamsize accuracy =
gPrecision) {
213 std::ostringstream oss;
214 for (
typename std::list<V*>::const_iterator it = b; it != e; ++it) {
245 template <
typename T,
typename T_BETWEEN>
246 inline std::string
joinToString(
const std::vector<T>& v,
const T_BETWEEN& between, std::streamsize accuracy =
gPrecision) {
247 std::ostringstream oss;
248 bool connect =
false;
249 for (
typename std::vector<T>::const_iterator it = v.begin(); it != v.end(); ++it) {
261 template <
typename T,
typename T_BETWEEN>
263 std::vector<T> sorted(v);
264 std::sort(sorted.begin(), sorted.end());
269 template <
typename T,
typename T_BETWEEN>
271 std::vector<std::string> ids;
279 template <
typename T,
typename C,
typename T_BETWEEN>
281 std::vector<std::string> ids;
289 template <
typename V>
292 std::vector<std::string> ids;
293 for (
typename std::set<V*>::const_iterator it = v.begin(); it != v.end(); ++it) {
294 ids.push_back((*it)->getID());
301 inline std::string
toString(
const std::vector<int>& v, std::streamsize accuracy) {
307 inline std::string
toString(
const std::vector<long long int>& v, std::streamsize accuracy) {
313 inline std::string
toString(
const std::vector<double>& v, std::streamsize accuracy) {
318 template <
typename T,
typename T_BETWEEN>
320 std::ostringstream oss;
321 bool connect =
false;
322 for (
typename std::set<T>::const_iterator it = s.begin(); it != s.end(); ++it) {
335 inline std::string
toString(
const std::vector<std::string>& v, std::streamsize) {
341 inline std::string
toString(
const std::set<std::string>& v, std::streamsize) {
346 template <
typename KEY,
typename VAL,
typename T_BETWEEN,
typename T_BETWEEN_KEYVAL>
347 inline std::string
joinToString(
const std::map<KEY, VAL>& s,
const T_BETWEEN& between,
const T_BETWEEN_KEYVAL& between_keyval, std::streamsize accuracy =
gPrecision) {
348 std::ostringstream oss;
349 bool connect =
false;
350 for (
typename std::map<KEY, VAL>::const_iterator it = s.begin(); it != s.end(); ++it) {
356 oss <<
toString(it->first, accuracy) << between_keyval <<
toString(it->second, accuracy);
363 inline std::string
toString(
const std::map<std::string, std::string>& v, std::streamsize) {