cgv
Loading...
Searching...
No Matches
convert_string.h
Go to the documentation of this file.
1#pragma once
2
7#include <string>
8#include <sstream>
9#include <iomanip>
10
11#include "lib_begin.h"
12
13namespace cgv {
14 namespace utils {
15
17template <typename T>
18std::string to_string(const T& v, unsigned int w = -1, unsigned int p = -1, bool fixed=false)
19{
20 std::stringstream ss;
21 if (fixed)
22 ss << std::fixed;
23 if (w != (unsigned int)-1)
24 ss << std::setw(w);
25 if (p != (unsigned int)-1)
26 ss << std::setprecision(p);
27 ss << v;
28 return ss.str();
29}
30
32template <typename T>
33std::string to_string(const T& v, unsigned int w, char fill_char)
34{
35 std::stringstream ss;
36 ss << std::setw(w) << std::setfill(fill_char) << v;
37 return ss.str();
38}
39
41template <> CGV_API std::string to_string(const std::string& v, unsigned int w, unsigned int p, bool);
42
44template <typename T>
45bool from_string(T& v, const std::string& s)
46{
47 std::stringstream ss(s);
48 ss >> v;
49 return !ss.fail();
50}
51
53template <> CGV_API bool from_string(std::string& v, const std::string& s);
54
55 }
56}
57
58#include <cgv/config/lib_end.h>
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
bool from_string(std::string &v, const std::string &s)
specialization to extract string value from string
the cgv namespace
Definition print.h:11