VectorConvert.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 #include <istream>
00004 #include <ostream>
00005 #include <vector>
00006 #include <string>
00007 #include <hrpUtil/EigenTypes.h>
00008 
00009 // Clang (and apparently ISO C++) doesn't like it when functions are not
00010 // declared before use, *even when the use occurs in templates*.
00011 
00012 template<typename T>
00013 std::istream& operator>>(std::istream& is, std::vector<T>& v);
00014 std::istream& operator>>(std::istream& is, hrp::dvector& v);
00015 std::istream& operator>>(std::istream& is, hrp::Vector3& v);
00016 
00017 #include <coil/stringutil.h>
00018 
00019 template<typename T>
00020 std::istream& operator>>(std::istream& is, std::vector<T>& v)
00021 {
00022   std::string s;
00023   std::vector<std::string> sv;
00024   getline(is,s);
00025   sv = coil::split(s ,",");
00026   v.resize(sv.size());
00027   for (int i(0), len(sv.size()); i < len; ++i)
00028     {
00029       T tv;
00030       if (coil::stringTo(tv, sv[i].c_str()))
00031         {
00032           v[i] = tv;
00033         }
00034     }
00035   return is;
00036 }
00037 
00038 std::istream& operator>>(std::istream& is, hrp::dvector& v)
00039 {
00040   std::string s;
00041   std::vector<std::string> sv;
00042   getline(is,s);
00043   sv = coil::split(s ,",");
00044   v.resize(sv.size());
00045   for (int i(0), len(sv.size()); i < len; ++i)
00046     {
00047       double tv;
00048       if (coil::stringTo(tv, sv[i].c_str()))
00049         {
00050           v[i] = tv;
00051         }
00052     }
00053   return is;
00054 }
00055 
00056 std::istream& operator>>(std::istream& is, hrp::Vector3& v)
00057 {
00058   std::string s;
00059   std::vector<std::string> sv;
00060   getline(is,s);
00061   sv = coil::split(s ,",");
00062   for (int i(0); i < 3; ++i)
00063     {
00064       double tv;
00065       if (coil::stringTo(tv, sv[i].c_str()))
00066         {
00067           v[i] = tv;
00068         }
00069     }
00070   return is;
00071 }


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed Sep 6 2017 02:35:56