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 "util/for_each_ref_host.hpp"
18#include "csv_multiarray.hpp"
19#include "util/util.hpp"
20#include "is_csv_writable.hpp"
22#define CSV_WRITER 0x30000
33template<
typename Tobj>
37 std::stringstream &
str;
60 typedef typename boost::mpl::at<typename Tobj::type,T>::type col_type;
63 typedef typename boost::remove_reference<col_type>::type col_rtype;
64 typedef typename std::remove_all_extents<col_rtype>::type base_col_rtype;
79template<
typename Tobj,
bool attr>
83 std::stringstream &
str;
100 typedef typename boost::mpl::at<typename Tobj::type,boost::mpl::int_<T::value>>::type col_type;
119template<
typename Tobj>
140 typedef typename boost::fusion::result_of::at_c<typename Tobj::type,T::value>::type col_type;
143 typedef typename boost::remove_reference<col_type>::type col_rtype;
145 std::stringstream str2;
146 str2 <<
"column_" << T::value;
162template <
typename v_pos,
typename v_prp,
unsigned int impl = 1>
170 std::stringstream str;
173 for (
size_t i = 0 ; i < v_pos::value_type::dims ; i++)
176 str <<
"x[" << i <<
"]";
178 str <<
"," <<
"x[" << i <<
"]";
186 boost::mpl::for_each_ref_host< boost::mpl::range_c<int,0,v_prp::value_type::max_prop> >(col);
202 std::stringstream str;
205 if (vp.size() != vpr.size())
207 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" position vector and property vector must have the same size \n";
208 return std::string(
"");
212 for (
size_t i = offset ; i < vp.size() ; i++)
214 for (
size_t j = 0 ; j < v_pos::value_type::dims ; j++)
217 str << vp.template get<0>(i)[j];
219 str <<
"," << vp.template get<0>(i)[j];
223 auto obj = vpr.get(i);
225 csv_prp<
decltype(obj)> c_prp(str,obj);
228 boost::mpl::for_each_ref_host< boost::mpl::range_c<int,0,v_prp::value_type::max_prop> >(c_prp);
248 bool write(std::string file, v_pos & v , v_prp & prp,
size_t offset=0)
251 std::string csv_header;
253 std::string point_data;
262 std::ofstream ofs(file);
265 if (ofs.is_open() ==
false)
266 {std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" cannot create the CSV file: " << file << std::endl;}
268 ofs << csv_header << point_data;
std::string get_csv_data(v_pos &vp, v_prp &vpr, size_t offset)
Get the csv data section.
std::string get_csv_colums()
Get the colums name (also the positional name)
bool write(std::string file, v_pos &v, v_prp &prp, size_t offset=0)
It write a CSV file.
std::stringstream & str
String containing the colums list as string.
void operator()(T &t)
It call the functor for each member.
csv_col(std::stringstream &str)
Constructor.
This class is an helper to produce csv headers from multi-array.
this class is a functor for "for_each" algorithm
csv_col(std::stringstream &str)
Constructor.
std::stringstream & str
String containing the colums list as string.
void operator()(T &t)
It call the functor for each member.
this class is a functor for "for_each" algorithm
csv_prp(std::stringstream &str, Tobj &obj)
Constructor.
void operator()(T &t)
It call the functor for each member.
std::stringstream & str
String containing the csv line constructed from an object.
Tobj & obj
Object to write.
This class is an helper to produce csv data from multi-array.