20 #include <boost/lexical_cast.hpp>
22 using namespace boost;
23 using namespace Input;
26 CSVTokenizer::CSVTokenizer(
const FilePath &fp, std::string field_separator)
27 : Tokenizer(fp, Tokenizer::Separator(
"\\", field_separator,
"\""))
32 CSVTokenizer::CSVTokenizer( std::istream &in, std::string field_separator)
33 : Tokenizer(in, Tokenizer::Separator(
"\\", field_separator,
"\""))
37 unsigned int CSVTokenizer::get_n_lines()
39 unsigned int n_lines = 0;
40 this->set_position( Tokenizer::Position() );
41 while ( !this->eof() ) {
42 this->next_line(
false);
45 if (this->line().size()==0) n_lines--;
50 void CSVTokenizer::skip_header(
unsigned int n_head_lines)
52 this->set_position( Tokenizer::Position() );
53 for (
unsigned int i=0; i<n_head_lines; i++) {
54 this->next_line(
false);
59 int CSVTokenizer::get_int_val()
62 return lexical_cast<int>( *(*
this) );
63 }
catch (bad_lexical_cast &) {
64 THROW( ReaderInternalBase::ExcWrongCsvFormat() << ReaderInternalBase::EI_TokenizerMsg(this->position_msg()) );
69 double CSVTokenizer::get_double_val()
72 return lexical_cast<double>( *(*
this) );
73 }
catch (bad_lexical_cast &) {
74 THROW( ReaderInternalBase::ExcWrongCsvFormat() << ReaderInternalBase::EI_Specification(
"Wrong double value")
75 << ReaderInternalBase::EI_TokenizerMsg(this->position_msg()) );
80 std::string CSVTokenizer::get_string_val()
84 }
catch (bad_lexical_cast &) {
85 THROW( ReaderInternalBase::ExcWrongCsvFormat() << ReaderInternalBase::EI_TokenizerMsg(this->position_msg()) );