#ifndef __CSV_READER_H__ #define __CSV_READER_H__ #include #include #include #include /** * Flight Recoderで記録されたCVSファイルを読み込む * */ class CSV_Reader { protected: typedef std::istream istream; typedef std::ostream ostream; typedef std::string string; public: typedef std::vector item_t; protected: item_t next_item; istream &_in; public: CSV_Reader(istream &in) : _in(in), next_item() {} ~CSV_Reader() {} bool seek(const char delim = ','){ if(!_in.good()){ return false; } next_item.clear(); char buf[4096]; _in.getline(buf, sizeof(buf)); if(_in.fail()){ return false; } string str(buf); string::size_type pos; while((pos = str.find_first_of(delim)) != str.npos){ next_item.push_back(str.substr(0, pos)); str = str.substr(pos + 1); } next_item.push_back(str); return true; } item_t &next(){ return next_item; } void inspect(ostream &out) const { for(item_t::const_iterator it(next_item.begin()); it != next_item.end(); ++it){ out << *it << ","; } out << std::endl; } }; #endif /* __CSV_READER_H__ */