ARPDAS_QNX6 1.0
|
00001 #ifndef CSV_FILE_H_INCLUDED 00002 #define CSV_FILE_H_INCLUDED 00003 #include <vector> 00004 #include <stdio.h> 00005 00006 class csv_col { 00007 public: 00008 csv_col(const char *colname, const char *fmt = NULL); 00009 ~csv_col(); 00010 const char *output(); 00011 const char *header(); 00012 void set(double dval); 00013 void set(const char *tval); 00014 void reset(); 00015 protected: 00016 void dsval_resize(int newsize); 00017 const char *cname; 00018 char *dsval; 00019 int dsval_size; 00020 const char *format; 00021 bool warned; 00022 }; 00023 00024 class csv_file { 00025 public: 00026 csv_file(const char *name, unsigned int n_cols, 00027 const char *nan_text = NULL, int json = 0); 00028 ~csv_file(); 00029 void init(); 00030 void init_col(unsigned int col_num, const char *colname, 00031 const char *fmt = NULL); 00032 void set_time(double T); 00033 void set_col(unsigned int col_num, double dval); 00034 void set_col(unsigned int col_num, const char *sval); 00035 static void terminate_on_write_err(int sig); 00036 static const char *nan; 00037 private: 00038 void flush_headers(); 00039 void flush_row(); 00040 std::vector<csv_col*> cols; 00041 double cur_time; 00042 bool time_set; 00043 bool json; 00044 const char *filename; 00045 FILE *fp; 00046 }; 00047 00048 #endif