12 #include <boost/fusion/include/mpl.hpp>
13 #include <boost/fusion/include/for_each.hpp>
15 #include "util/common.hpp"
16 #include <boost/mpl/range_c.hpp>
17 #include <boost/mpl/for_each.hpp>
18 #include "csv_multiarray.hpp"
21 #define CSV_WRITER 0x30000
32 template<
typename Tobj>
36 std::stringstream & str;
49 csv_prp(std::stringstream & str, Tobj & obj)
59 typedef decltype(obj.template get<T::value>()) col_type;
62 typedef typename boost::remove_reference<col_type>::type col_rtype;
77 template<
typename Tobj,
bool attr>
80 std::stringstream & str;
82 csv_col(std::stringstream & str)
92 typedef typename boost::mpl::at<typename Tobj::type,boost::mpl::int_<T::value>>::type col_type;
111 template<
typename Tobj>
114 std::stringstream & str;
116 csv_col(std::stringstream & str)
126 typedef typename boost::fusion::result_of::at_c<typename Tobj::type,T::value>::type col_type;
129 typedef typename boost::remove_reference<col_type>::type col_rtype;
131 std::stringstream str2;
132 str2 <<
"column_" << T::value;
148 template <
typename v_pos,
typename v_prp,
unsigned int impl = VECTOR>
156 std::stringstream str;
159 for (
size_t i = 0 ; i < v_pos::value_type::dims ; i++)
162 str <<
"x[" << i <<
"]";
164 str <<
"," <<
"x[" << i <<
"]";
172 boost::mpl::for_each< boost::mpl::range_c<int,0,v_prp::value_type::max_prop> >(col);
188 std::stringstream str;
191 if (vp.size() != vpr.size())
193 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" position vector and property vector must have the same size \n";
194 return std::string(
"");
198 for (
size_t i = offset ; i < vp.size() ; i++)
200 for (
size_t j = 0 ; j < v_pos::value_type::dims ; j++)
203 str << vp.template get<0>(i)[j];
205 str <<
"," << vp.template get<0>(i)[j];
209 auto obj = vpr.get(i);
214 boost::mpl::for_each< boost::mpl::range_c<int,0,v_prp::value_type::max_prop> >(c_prp);
235 bool write(std::string file, v_pos & v , v_prp & prp,
size_t offset=0)
238 std::string csv_header;
240 std::string point_data;
249 std::ofstream ofs(file);
252 if (ofs.is_open() ==
false)
253 {std::cerr <<
"Error cannot create the CSV file: " + file;}
255 ofs << csv_header << point_data;
void operator()(T &t)
It call the functor for each member.
bool write(std::string file, v_pos &v, v_prp &prp, size_t offset=0)
It write a CSV file.
This class is an helper to produce csv data from multi-array.
void operator()(T &t)
It call the functor for each member.
This class is an helper to produce csv headers from multi-array.
csv_prp(std::stringstream &str, Tobj &obj)
Constructor.
void operator()(T &t)
It call the functor for each member.
this class is a functor for "for_each" algorithm
std::string get_csv_colums()
Get the colums name (also the positional name)
this class is a functor for "for_each" algorithm
std::string get_csv_data(v_pos &vp, v_prp &vpr, size_t offset)
Get the csv data section.