VectorConvert.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 #include <istream>
4 #include <ostream>
5 #include <vector>
6 #include <string>
7 #include <hrpUtil/EigenTypes.h>
8 
9 // Clang (and apparently ISO C++) doesn't like it when functions are not
10 // declared before use, *even when the use occurs in templates*.
11 
12 template<typename T>
13 std::istream& operator>>(std::istream& is, std::vector<T>& v);
14 std::istream& operator>>(std::istream& is, hrp::dvector& v);
15 std::istream& operator>>(std::istream& is, hrp::Vector3& v);
16 
17 #include <coil/stringutil.h>
18 
19 template<typename T>
20 std::istream& operator>>(std::istream& is, std::vector<T>& v)
21 {
22  std::string s;
23  std::vector<std::string> sv;
24  getline(is,s);
25  sv = coil::split(s ,",");
26  v.resize(sv.size());
27  for (int i(0), len(sv.size()); i < len; ++i)
28  {
29  T tv;
30  if (coil::stringTo(tv, sv[i].c_str()))
31  {
32  v[i] = tv;
33  }
34  }
35  return is;
36 }
37 
38 std::istream& operator>>(std::istream& is, hrp::dvector& v)
39 {
40  std::string s;
41  std::vector<std::string> sv;
42  getline(is,s);
43  sv = coil::split(s ,",");
44  v.resize(sv.size());
45  for (int i(0), len(sv.size()); i < len; ++i)
46  {
47  double tv;
48  if (coil::stringTo(tv, sv[i].c_str()))
49  {
50  v[i] = tv;
51  }
52  }
53  return is;
54 }
55 
56 std::istream& operator>>(std::istream& is, hrp::Vector3& v)
57 {
58  std::string s;
59  std::vector<std::string> sv;
60  getline(is,s);
61  sv = coil::split(s ,",");
62  for (int i(0); i < 3; ++i)
63  {
64  double tv;
65  if (coil::stringTo(tv, sv[i].c_str()))
66  {
67  v[i] = tv;
68  }
69  }
70  return is;
71 }
bool stringTo(To &val, const char *str)
std::istream & operator>>(std::istream &is, std::vector< T > &v)
Definition: VectorConvert.h:20
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
png_uint_32 i
Eigen::VectorXd dvector
Eigen::Vector3d Vector3


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:51