cgv
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 
13 namespace cgv {
14  namespace utils {
15 
17 template <typename T>
18 std::string to_string(const T& v, unsigned int w = -1, unsigned int p = -1)
19 {
20  std::stringstream ss;
21  if (w != (unsigned int)-1)
22  ss << std::setw(w);
23  if (p != (unsigned int)-1)
24  ss << std::setprecision(p);
25  ss << v;
26  return ss.str();
27 }
28 
30 template <typename T>
31 std::string to_string(const T& v, unsigned int w, char fill_char)
32 {
33  std::stringstream ss;
34  ss << std::setw(w) << std::setfill(fill_char) << v;
35  return ss.str();
36 }
37 
39 template <> CGV_API std::string to_string(const std::string& v, unsigned int w, unsigned int p);
40 
42 template <typename T>
43 bool from_string(T& v, const std::string& s)
44 {
45  std::stringstream ss(s);
46  ss >> v;
47  return !ss.fail();
48 }
49 
51 template <> CGV_API bool from_string(std::string& v, const std::string& s);
52 
53  }
54 }
55 
56 #include <cgv/config/lib_end.h>
cgv::utils::from_string
bool from_string(std::string &v, const std::string &s)
specialization to extract string value from string
Definition: convert_string.cxx:13
cgv::utils::to_string
std::string to_string(const std::string &v, unsigned int w, unsigned int p)
specialization of conversion from string to strings
Definition: convert_string.cxx:7
cgv
the cgv namespace
Definition: vr_calib.cxx:9