@@ -91,10 +91,9 @@ class ReportTypePrinter : public boost::static_visitor<> {
9191};
9292
9393CSVFileReport::CSVFileReport (const string& filename, const char sep, const bool commentCharacter, char quoteChar,
94- const string& nullString, bool lowerHeader,
95- QuantLib::Size rolloverSize)
94+ const string& nullString, bool lowerHeader, QuantLib::Size rolloverSize)
9695 : filename_(filename), sep_(sep), commentCharacter_(commentCharacter), quoteChar_(quoteChar),
97- nullString_ (nullString), lowerHeader_(lowerHeader), rolloverSize_(rolloverSize), i_(0 ), fp_(NULL ) {
96+ nullString_ (nullString), lowerHeader_(lowerHeader), rolloverSize_(rolloverSize), i_(0 ), fp_(NULL ) {
9897 baseFilename_ = filename_;
9998 open ();
10099}
@@ -121,7 +120,8 @@ void CSVFileReport::rollover() {
121120 version_++;
122121 boost::filesystem::path p (baseFilename_);
123122 boost::filesystem::path newFilepath =
124- p.parent_path () / boost::filesystem::path (p.stem ().string () + " _" + to_string (version_) + p.extension ().string ());
123+ p.parent_path () /
124+ boost::filesystem::path (p.stem ().string () + " _" + to_string (version_) + p.extension ().string ());
125125 filename_ = newFilepath.string ();
126126 open ();
127127}
@@ -135,6 +135,7 @@ void CSVFileReport::flush() {
135135Report& CSVFileReport::addColumn (const string& name, const ReportType& rt, Size precision) {
136136 checkIsOpen (" addColumn(" + name + " )" );
137137 columnTypes_.push_back (rt);
138+ headers_.push_back (name);
138139 printers_.push_back (ReportTypePrinter (fp_, precision, quoteChar_, nullString_));
139140 if (i_ == 0 && commentCharacter_)
140141 fprintf (fp_, " #" );
@@ -162,18 +163,22 @@ Report& CSVFileReport::next() {
162163 }
163164
164165 checkIsOpen (" next()" );
165- QL_REQUIRE (i_ == columnTypes_.size (), " Cannot go to next line, only " << i_ << " entries filled" );
166+ QL_REQUIRE (i_ == columnTypes_.size (), " Cannot go to next line, only "
167+ << i_
168+ << " entries filled, report headers are: " << boost::join (headers_, " ," ));
166169 fprintf (fp_, " \n " );
167170 i_ = 0 ;
168171 return *this ;
169172}
170173
171174Report& CSVFileReport::add (const ReportType& rt) {
172175 checkIsOpen (" add()" );
173- QL_REQUIRE (i_ < columnTypes_.size (), " No column to add [" << rt << " ] to." );
174- QL_REQUIRE (rt.which () == columnTypes_[i_].which (), " Cannot add value " << rt << " of type " << rt.which ()
175- << " to column " << i_ << " of type "
176- << columnTypes_[i_].which ());
176+ QL_REQUIRE (i_ < columnTypes_.size (),
177+ " No column to add [" << rt << " ] to, report headers are: " << boost::join (headers_, " ," ));
178+ QL_REQUIRE (rt.which () == columnTypes_[i_].which (), " Cannot add value "
179+ << rt << " of type " << rt.which () << " to column " << i_
180+ << " of type " << columnTypes_[i_].which ()
181+ << " , report headers are: " << boost::join (headers_, " ," ));
177182
178183 if (i_ != 0 )
179184 fprintf (fp_, " %c" , sep_);
@@ -197,13 +202,14 @@ void CSVFileReport::end() {
197202 }
198203
199204 QL_REQUIRE (i_ == columnTypes_.size () || i_ == 0 , " csv report is finalized with incomplete row, got data for "
200- << i_ << " columns out of " << columnTypes_.size ());
205+ << i_ << " columns out of " << columnTypes_.size ()
206+ << " , report headers are: " << boost::join (headers_, " ," ));
201207 finalized_ = true ;
202208}
203209
204210void CSVFileReport::checkIsOpen (const std::string& op) const {
205- QL_REQUIRE (!finalized_,
206- " CSV file report ' " << filename_ << " ' is already finalized, can not process operation " << op );
211+ QL_REQUIRE (!finalized_, " CSV file report ' " << filename_ << " ' is already finalized, can not process operation "
212+ << op << " , report headers are: " << boost::join (headers_, " , " ) );
207213}
208214
209215} // namespace data
0 commit comments