47 if ( RDB::REOF == rdb.
read( ) ) {
48 is.setstate( std::ios::eofbit | std::ios::failbit );
52 }
catch (
RDBErr& rdberr ) {
53 rdberr.set_message(
"operator>>(std::istream&,RDB&): " );
57 throw(
RDBErr(
"operator>>(std::istream&,RDB&): unexpected exception caught" ) );
88 }
catch (
RDBErr& rdberr ) {
89 rdberr.set_message(
"operator<<(std::ostream&,RDB&): " );
93 throw(
RDBErr(
"operator<<(std::ostream&,RDB&): unexpected exception caught" ) );
118 const std::string& name,
119 std::ios::openmode mode
121 : _filename(name), _mode(mode),
122 _isptr(NULL), _osptr(NULL),
123 _myisptr(true), _myosptr(true),
125 _ncomms(0), _ncols(0), _nrows(0),
126 _knowrows(false), _rownum(0),
128 _firstread(true), _lastread(false), _writehdr(true),
129 _comms(NULL), _cols(NULL),
130 _nrcol(
"_NR",
"N"), _mycols(NULL),
135 if ( name.empty( ) ) {
142 }
catch (
RDBErr& rdberr ) {
143 rdberr.set_message(
"RDB::RDB(std::string&,ios::openmode): " );
147 throw(
RDBErr(
"RDB::RDB(std::string&,ios::openmode): unexpected exception caught" ) );
165 ) : _filename(
"istream"),
166 _isptr(NULL), _osptr(NULL),
167 _myisptr(false), _myosptr(false),
169 _ncomms(0), _ncols(0), _nrows(0),
170 _knowrows(false), _rownum(0),
172 _firstread(true), _lastread(false), _writehdr(true),
173 _comms(NULL), _cols(NULL),
174 _nrcol(
"_NR",
"N"), _mycols(NULL),
182 }
catch (
RDBErr& rdberr ) {
183 rdberr.set_message(
"RDB::RDB(std::istream*): " );
187 throw(
RDBErr(
"RDB::RDB(std::istream*): unexpected exception caught" ) );
200 ) : _filename(
"ostream"),
201 _isptr(NULL), _osptr(NULL),
202 _myisptr(false), _myosptr(false),
204 _ncomms(0), _ncols(0), _nrows(0),
205 _knowrows(false), _rownum(0),
207 _firstread(true), _lastread(false), _writehdr(true),
208 _comms(NULL), _cols(NULL),
209 _nrcol(
"_NR",
"N"), _mycols(NULL),
217 }
catch (
RDBErr& rdberr ) {
218 rdberr.set_message(
"RDB::RDB(std::ostream&): " );
222 throw(
RDBErr(
"RDB::RDB(ostream&): unexpected exception caught" ) );
235 ) : _filename(rdb._filename), _mode(rdb._mode),
236 _isptr(NULL), _osptr(NULL),
237 _myisptr(true), _myosptr(true),
238 _rewindto(0), _ncomms(0), _ncols(0), _nrows(0),
239 _knowrows(false), _rownum(0),
240 _autoidx(false), _firstread(true), _lastread(false),
242 _comms(NULL), _cols(NULL), _nrcol(
"_NR",
"N"),
243 _mycols(NULL), _line(1024,
'\0') {
250 }
catch (
RDBErr& rdberr ) {
251 rdberr.set_message(
"RDB::RDB(RDB&): " );
255 throw(
RDBErr(
"RDB::RDB(RDB&): unexpected exception caught" ) );
282 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
316 const std::string& name,
317 std::ios::openmode mode
325 if ( std::ios::in &
_mode ) {
329 std::stringstream ss;
330 ss <<
"RDB::open(std::string&,std::ios_base::openmode): Error opening '" 332 if ( std::ios_base::app &
_mode )
333 ss <<
" std::ios_base::app";
334 if ( std::ios_base::binary &
_mode )
335 ss <<
" std::ios_base::binary";
336 if ( std::ios_base::in &
_mode )
337 ss <<
" ios_bae::in";
338 if ( std::ios_base::out &
_mode )
339 ss <<
" std::ios_base::out";
340 if ( std::ios_base::trunc &
_mode )
341 ss <<
" std::ios_base::trunc";
342 if ( std::ios_base::ate &
_mode )
343 ss <<
" std::ios_base::ate";
344 throw(
RDBErr( ss.str( ) ) );
351 }
catch (
RDBErr& rdberr ) {
352 rdberr.set_message(
"RDB::open(std::string&,ios::openmode): error with file '" +
_filename +
"': " );
356 throw(
RDBErr(
"RDB::open(std::string&,ios::openmode): unexpected exception caught with file '" +
_filename +
"'" ) );
361 if ( std::ios::out &
_mode ) {
365 std::stringstream ss;
366 ss <<
"RDB::open(std::string&,std::ios_base::openmode): Error opening '" 368 if ( std::ios_base::app &
_mode )
369 ss <<
" std::ios_base::app";
370 if ( std::ios_base::binary &
_mode )
371 ss <<
" std::ios_base::binary";
372 if ( std::ios_base::in &
_mode )
373 ss <<
" ios_bae::in";
374 if ( std::ios_base::out &
_mode )
375 ss <<
" std::ios_base::out";
376 if ( std::ios_base::trunc &
_mode )
377 ss <<
" std::ios_base::trunc";
378 if ( std::ios_base::ate &
_mode )
379 ss <<
" std::ios_base::ate";
380 throw(
RDBErr( ss.str( ) ) );
406 _mode = std::ios::in;
412 }
catch (
RDBErr& rdberr ) {
413 rdberr.set_message(
"RDB::open(std::istream&): " );
417 throw(
RDBErr(
"RDB::open(istream&): unexpected exception caught" ) );
438 _mode = std::ios::out;
459 if ( std::ios::in &
_mode ) {
463 std::stringstream ss;
464 ss <<
"RDB::open(RDB&): Error opening '" 466 if ( std::ios_base::app &
_mode )
467 ss <<
" std::ios_base::app";
468 if ( std::ios_base::binary &
_mode )
469 ss <<
" std::ios_base::binary";
470 if ( std::ios_base::in &
_mode )
471 ss <<
" ios_bae::in";
472 if ( std::ios_base::out &
_mode )
473 ss <<
" std::ios_base::out";
474 if ( std::ios_base::trunc &
_mode )
475 ss <<
" std::ios_base::trunc";
476 if ( std::ios_base::ate &
_mode )
477 ss <<
" std::ios_base::ate";
478 throw(
RDBErr( ss.str( ) ) );
485 }
catch (
RDBErr& rdberr ) {
486 rdberr.set_message(
"RDB::open(RDB&): error with file '" +
_filename +
"': " );
490 throw(
RDBErr(
"RDB::open(RDB&): unexpected exception caught with file '" +
_filename +
"'" ) );
495 if ( std::ios::out &
_mode ) {
499 std::stringstream ss;
500 ss <<
"RDB::open(RDB&): Error opening '" 502 if ( std::ios_base::app &
_mode )
503 ss <<
" std::ios_base::app";
504 if ( std::ios_base::binary &
_mode )
505 ss <<
" std::ios_base::binary";
506 if ( std::ios_base::in &
_mode )
507 ss <<
" ios_bae::in";
508 if ( std::ios_base::out &
_mode )
509 ss <<
" std::ios_base::out";
510 if ( std::ios_base::trunc &
_mode )
511 ss <<
" std::ios_base::trunc";
512 if ( std::ios_base::ate &
_mode )
513 ss <<
" std::ios_base::ate";
514 throw(
RDBErr( ss.str( ) ) );
536 for ( idx = 0; idx <
_ncomms; idx++ )
540 for ( idx = 0; idx <
_ncols - 1; idx++ )
544 for ( idx = 0; idx <
_ncols - 1; idx++ )
593 int newgroup = RDB::REOF;
614 std::vector<std::string> tokens;
615 suplib::tok( tokens,
_line,
"\t",
false );
617 if ( tokens.size( ) !=
_ncols ) {
618 std::stringstream ss;
619 ss <<
"RDB::read(void): error reading file '" <<
_filename <<
"': invalid row at " <<
_rownum <<
": number of token(" << tokens.size( ) <<
") != number of columns(" <<
_ncols <<
")";
620 throw(
RDBErr( ss.str( ) ) );
623 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
631 }
catch (
RDBErr& rdberr ) {
632 rdberr.set_message(
"RDB::read(void): error reading file '" +
_filename +
"': " );
636 throw(
RDBErr(
"RDB::read(void): unexpected exception caught with file '" +
_filename +
"'" ) );
645 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
652 std::vector<std::string> tokens;
653 suplib::tok( tokens,
_line,
"\t",
false );
655 if ( tokens.size( ) !=
_ncols ) {
656 std::stringstream ss;
657 ss <<
"RDB::read(void): error reading file '" <<
_filename <<
"': invalid row at " <<
_rownum+1 <<
": number of token(" << tokens.size( ) <<
") != number of columns(" <<
_ncols <<
")";
658 throw(
RDBErr( ss.str( ) ) );
661 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
669 }
catch (
RDBErr& rdberr ) {
670 rdberr.set_message(
"RDB::read(void): error reading file '" +
_filename +
"': " );
674 throw(
RDBErr(
"RDB::read(void): unexpected exception caught reading file '" +
_filename +
"'" ) );
684 newgroup = RDB::REOG;
686 newgroup = RDB::REOF;
718 for ( idx = 0; idx <
_ncomms; idx++ )
721 for ( idx = 0; idx <
_ncols - 1; idx++ )
725 for ( idx = 0; idx <
_ncols - 1; idx++ )
740 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
775 if ( std::ios::in &
_mode ) {
784 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
792 }
else if ( std::ios::out &
_mode ) {
801 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
860 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
878 const std::string& name,
884 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
893 if (
"_NR" != name ) {
894 throw(
RDBErr( std::string(
"RDB::setGroup(std::string): error in file '" +
_filename +
"': Column ") + name +
"(0) not found" ) );
917 if ( 0 <= idx && idx < (
int)
_ncols ) {
921 std::stringstream ss;
922 ss <<
"RDB::setGroup(std::string): error with file '" +
_filename +
"': Column " << idx <<
" of " <<
_ncols <<
" not found";
923 throw(
RDBErr( ss.str( ) ) );
938 const std::string& name
941 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
948 if (
"_NR" != name ) {
949 throw(
RDBErr( std::string(
"RDB::getGroup(std::string): error with file '" +
_filename +
"': Column ") + name +
"(0) not found" ) );
970 if ( 0 > idx && idx >=
_ncols ) {
971 std::stringstream ss;
972 ss <<
"RDB::getGroup(std::string): error with file '" +
_filename +
"': Column " << idx <<
" out of " <<
_ncols <<
" not found";
973 throw(
RDBErr( ss.str( ) ) );
992 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
1015 const std::string& comm,
1019 if ( 0 < idx && idx < (
int)
_ncomms ) {
1026 for (
size_t jdx = 0; jdx <
_ncomms; jdx++ ) {
1057 if ( 0 < idx && idx < (
int)
_ncomms ) {
1064 for (
size_t jdx = 0; jdx <
_ncomms; jdx++ ) {
1091 const std::string& name,
1095 for (
size_t jdx = 0; jdx <
_ncomms; jdx++ ) {
1096 if ( name ==
_comms[jdx].getKeyword( ) ) {
1128 for (
size_t idx = 0; idx <
_ncomms; idx++ ) {
1151 if ( 0 > idx && idx >=
_ncomms ) {
1152 std::stringstream ss;
1153 ss <<
"RDB::getComment(size_t): error with file '" +
_filename +
"': Comment " << idx <<
"out of "<<
_ncomms <<
" not found";
1154 throw(
RDBErr( ss.str( ) ) );
1173 const std::string& name,
1177 for (
size_t jdx = 0; jdx <
_ncomms; jdx++ ) {
1178 if ( name ==
_comms[jdx].getKeyword( ) ) {
1184 std::stringstream ss;
1185 ss <<
"RDB::getComment(std::string): error with file '" <<
_filename<<
"': Comment " << name <<
"("<< idx <<
") not found";
1186 throw(
RDBErr( ss.str( ) ) );
1208 const std::string& name,
1209 const std::string& def,
1213 if ( 0 <= idx && idx < (
int)
_ncols ) {
1226 bool* tmpmycols =
new bool[
_ncols+1];
1229 if ( def.npos != (pos = def.find_first_not_of(
"0123456789" )) &&
'N' == def[pos] ) {
1236 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
1237 tmp[jdx] =
_cols[jdx];
1238 tmpmycols[jdx] =
_mycols[jdx];
1248 tmpmycols[
_ncols++] =
true;
1278 if ( 0 <= idx && idx < (
int)
_ncols ) {
1290 bool* tmpmycols =
new bool[
_ncols+1];
1293 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
1294 tmp[jdx] =
_cols[jdx];
1295 tmpmycols[jdx] =
_mycols[jdx];
1305 tmpmycols[
_ncols++] =
false;
1332 const std::string& name,
1336 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
1374 bool* tmpmycols =
new bool[rdb.
_ncols];
1377 for ( idx = 0; idx <
_ncols; idx++ ) {
1378 tmp[idx] = rdb.
_cols[idx];
1379 tmpmycols[idx] =
false;
1394 for ( ; idx < rdb.
_ncols; idx++ ) {
1395 tmp[idx] = rdb.
_cols[idx];
1396 tmpmycols[idx] =
false;
1403 for ( idx = 0; idx < rdb.
_ncols; idx++ ) {
1409 for ( ; idx <
_ncols; idx++ ) {
1436 if ( 0 > idx && idx >=
_ncols ) {
1437 std::stringstream ss;
1438 ss <<
"RDB::getColumn(size_t): error with file '" <<
_filename <<
"': Column " << idx <<
" out of "<<
_ncols <<
" not found";
1439 throw(
RDBErr( ss.str( ) ) );
1458 const std::string& name,
1462 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
1469 if (
"_NR" != name ) {
1470 std::stringstream ss;
1471 ss <<
"RDB::getColumn(std::string): error with file '" <<
_filename <<
"': Column " << name <<
"("<< idx <<
") not found";
1472 throw(
RDBErr( ss.str( ) ) );
1490 std::stringstream ss;
1491 ss <<
"RDB::setName: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1492 throw(
RDBErr( ss.str( ) ) );
1511 std::stringstream ss;
1512 ss <<
"RDB::setDef: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1513 throw(
RDBErr( ss.str( ) ) );
1520 e.set_message(
"RDB::setDef: error with file '" +
_filename +
"': " );
1524 throw(
RDBErr(
"RDB::setDef: unexpected exception caught with file '" +
_filename +
"'" ) );
1539 std::stringstream ss;
1540 ss <<
"RDB::setWidth: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1541 throw(
RDBErr( ss.str( ) ) );
1548 e.set_message(
"RDB::setWidth: error with file '" +
_filename +
"': " );
1552 throw(
RDBErr(
"RDB::setWidth: unexpected exception caught with file '" +
_filename +
"'" ) );
1567 std::stringstream ss;
1568 ss <<
"RDB::setType: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1569 throw(
RDBErr( ss.str( ) ) );
1576 e.set_message(
"RDB::setType: error with file '" +
_filename +
"': " );
1580 throw(
RDBErr(
"RDB::setType: unexpected exception caught with file '" +
_filename +
"'" ) );
1595 std::stringstream ss;
1596 ss <<
"RDB::setJust: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1597 throw(
RDBErr( ss.str( ) ) );
1604 e.set_message(
"RDB::setJust: error with file '" +
_filename +
"': " );
1608 throw(
RDBErr(
"RDB::setJust: unexpected exception caught with file '" +
_filename +
"'" ) );
1623 std::stringstream ss;
1624 ss <<
"RDB::setDesc: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1625 throw(
RDBErr( ss.str( ) ) );
1632 e.set_message(
"RDB::setDesc: error with file '" +
_filename +
"': " );
1636 throw(
RDBErr(
"RDB::setDesc: unexpected exception caught with file '" +
_filename +
"'" ) );
1649 void RDB::mapData(
const size_t idx,
double data[],
const size_t nelems ) {
1651 std::stringstream ss;
1652 ss <<
"RDB::mapData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1653 throw(
RDBErr( ss.str( ) ) );
1660 e.set_message(
"RDB::mapData: error with file '" +
_filename +
"': " );
1664 throw(
RDBErr(
"RDB::mapData: unexpected exception caught with file '" +
_filename +
"'" ) );
1680 std::stringstream ss;
1681 ss <<
"RDB::mapData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1682 throw(
RDBErr( ss.str( ) ) );
1689 e.set_message(
"RDB::mapData: error with file '" +
_filename +
"': " );
1693 throw(
RDBErr(
"RDB::mapData: unexpected exception caught with file '" +
_filename +
"'" ) );
1706 void RDB::mapData(
const size_t idx, std::string data[],
const size_t nelems ) {
1709 std::stringstream ss;
1710 ss <<
"RDB::mapData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1711 throw(
RDBErr( ss.str( ) ) );
1718 e.set_message(
"RDB::mapData: error with file '" +
_filename +
"': " );
1722 throw(
RDBErr(
"RDB::mapData: unexpected exception caught with file '" +
_filename +
"'" ) );
1737 std::stringstream ss;
1738 ss <<
"RDB::setData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1739 throw(
RDBErr( ss.str( ) ) );
1746 e.set_message(
"RDB::setData: error with file '" +
_filename +
"': " );
1750 throw(
RDBErr(
"RDB::setData: unexpected exception caught with file '" +
_filename +
"'" ) );
1765 std::stringstream ss;
1766 ss <<
"RDB::setData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1767 throw(
RDBErr( ss.str( ) ) );
1774 e.set_message(
"RDB::setData: error with file '" +
_filename +
"': " );
1778 throw(
RDBErr(
"RDB::setData: unexpected exception caught with file '" +
_filename +
"'" ) );
1793 std::stringstream ss;
1794 ss <<
"RDB::setData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1795 throw(
RDBErr( ss.str( ) ) );
1802 e.set_message(
"RDB::setData: error with file '" +
_filename +
"': " );
1806 throw(
RDBErr(
"RDB::setData: unexpected exception caught with file '" +
_filename +
"'" ) );
1820 std::stringstream ss;
1821 ss <<
"RDB::getName: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1822 throw(
RDBErr( ss.str( ) ) );
1839 std::stringstream ss;
1840 ss <<
"RDB::getDef: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1841 throw(
RDBErr( ss.str( ) ) );
1858 std::stringstream ss;
1859 ss <<
"RDB::getWidth: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1860 throw(
RDBErr( ss.str( ) ) );
1877 std::stringstream ss;
1878 ss <<
"RDB::getType: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1879 throw(
RDBErr( ss.str( ) ) );
1896 std::stringstream ss;
1897 ss <<
"RDB::getJust: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1898 throw(
RDBErr( ss.str( ) ) );
1915 std::stringstream ss;
1916 ss <<
"RDB::getDesc: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1917 throw(
RDBErr( ss.str( ) ) );
1935 std::stringstream ss;
1936 ss <<
"RDB::getData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1937 throw(
RDBErr( ss.str( ) ) );
1944 e.set_message(
"RDB::getData: error with file '" +
_filename +
"': " );
1948 throw(
RDBErr(
"RDB::getData: unexpected exception caught with file '" +
_filename +
"'" ) );
1963 std::stringstream ss;
1964 ss <<
"RDB::getData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1965 throw(
RDBErr( ss.str( ) ) );
1972 e.set_message(
"RDB::getData: error with file '" +
_filename +
"': " );
1976 throw(
RDBErr(
"RDB::getData: unexpected exception caught with file '" +
_filename +
"'" ) );
1991 std::stringstream ss;
1992 ss <<
"RDB::getData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1993 throw(
RDBErr( ss.str( ) ) );
2000 e.set_message(
"RDB::getData: error with file '" +
_filename +
"': " );
2004 throw(
RDBErr(
"RDB::getData: unexpected exception caught with file '" +
_filename +
"': " ) );
2019 std::stringstream ss;
2020 ss <<
"RDB::getName: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2021 throw(
RDBErr( ss.str( ) ) );
2039 std::stringstream ss;
2040 ss <<
"RDB::getDef: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2041 throw(
RDBErr( ss.str( ) ) );
2059 std::stringstream ss;
2060 ss <<
"RDB::getWidth: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2061 throw(
RDBErr( ss.str( ) ) );
2079 std::stringstream ss;
2080 ss <<
"RDB::getType: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2081 throw(
RDBErr( ss.str( ) ) );
2099 std::stringstream ss;
2100 ss <<
"RDB::getJust: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2101 throw(
RDBErr( ss.str( ) ) );
2119 std::stringstream ss;
2120 ss <<
"RDB::getDesc: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2121 throw(
RDBErr( ss.str( ) ) );
2140 std::stringstream ss;
2141 ss <<
"RDB::getDataDouble: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2142 throw(
RDBErr( ss.str( ) ) );
2149 e.set_message(
"RDB::getDataDouble: error with file '" +
_filename +
"': " );
2153 throw(
RDBErr(
"RDB::getDataDouble: unexpected exception caught with file '" +
_filename +
"':" ) );
2169 std::stringstream ss;
2170 ss <<
"RDB::getDataLong: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2171 throw(
RDBErr( ss.str( ) ) );
2178 e.set_message(
"RDB::getDataLong: error with file '" +
_filename +
"': " );
2182 throw(
RDBErr(
"RDB::getDataLong: unexpected exception caught with file '" +
_filename +
"':" ) );
2198 std::stringstream ss;
2199 ss <<
"RDB::getDataString: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2200 throw(
RDBErr( ss.str( ) ) );
2207 e.set_message(
"RDB::getDataString: error with file '" +
_filename +
"': " );
2211 throw(
RDBErr(
"RDB::getDataString: unexpected exception caught with file '" +
_filename +
"':" ) );
2225 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2233 if (
"_NR" != name ) {
2234 throw (
RDBErr( std::string(
"RDB::setName(std::string&,std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2251 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2257 e.set_message(
"RDB::setDef: error with file '" +
_filename +
"': " );
2261 throw(
RDBErr(
"RDB::setDef: unexpected exception caught with file '" +
_filename +
"':" ) );
2269 if (
"_NR" != name ) {
2270 throw (
RDBErr( std::string(
"RDB::setDef(std::string&,std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2286 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2292 e.set_message(
"RDB::setWidth: error with file '" +
_filename +
"': " );
2296 throw(
RDBErr(
"RDB::setWidth: unexpected exception caught with file '" +
_filename +
"':" ) );
2304 if (
"_NR" != name ) {
2305 throw (
RDBErr( std::string(
"RDB::setWidth(std::string&,long): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2321 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2327 e.set_message(
"RDB::setType: error with file '" +
_filename +
"': " );
2331 throw(
RDBErr(
"RDB::setType: error with file '" +
_filename +
"': unexpected exception caught" ) );
2339 if (
"_NR" != name ) {
2340 throw (
RDBErr( std::string(
"RDB::setType(std::string&,RDBColumn::Type): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2356 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2362 e.set_message(
"RDB::setJust: error with file '" +
_filename +
"': " );
2366 throw(
RDBErr(
"RDB::setJust: error with file '" +
_filename +
"': unexpected exception caught" ) );
2374 if (
"_NR" != name ) {
2375 throw (
RDBErr( std::string(
"RDB::setJust(std::string&,RDBColumn::Just): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2391 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2397 e.set_message(
"RDB::setDesc: error with file '" +
_filename +
"': " );
2401 throw(
RDBErr(
"RDB::setDesc: error with file '" +
_filename +
"': unexpected exception caught" ) );
2409 if (
"_NR" != name ) {
2410 throw (
RDBErr( std::string(
"RDB::setDesc(std::string&,std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2425 void RDB::mapData(
const std::string& name,
double data[],
const size_t nelems ) {
2427 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2433 e.set_message(
"RDB::mapData: error with file '" +
_filename +
"': " );
2437 throw(
RDBErr(
"RDB::mapData: error with file '" +
_filename +
"': unexpected exception caught" ) );
2445 if (
"_NR" != name ) {
2446 throw (
RDBErr( std::string(
"RDB::mapData(std::string&,double[],size_t): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2448 throw(
RDBErr(
"RDB::mapData('_NR',double[],size_t): error with file '" +
_filename +
"': mapping double[] to '_NR' column not allowed" ) );
2461 void RDB::mapData(
const std::string& name,
long data[],
const size_t nelems ) {
2463 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2469 e.set_message(
"RDB::mapData: error with file '" +
_filename +
"': " );
2473 throw(
RDBErr(
"RDB::mapData: unexpected exception caught with file '" +
_filename +
"':" ) );
2482 if (
"_NR" != name ) {
2483 throw (
RDBErr( std::string(
"RDB::mapData(std::string&,long[],size_t): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2498 void RDB::mapData(
const std::string& name, std::string data[],
const size_t nelems ) {
2500 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2506 e.set_message(
"RDB::mapData: error with file '" +
_filename +
"': " );
2510 throw(
RDBErr(
"RDB::mapData: unexpected exception caught with file '" +
_filename +
"':" ) );
2518 if (
"_NR" != name ) {
2519 throw (
RDBErr( std::string(
"RDB::mapData(std::string&,std::string[],size_t): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2521 throw(
RDBErr(
"RDB::mapData('_NR',std::string[],size_t): error with file '" +
_filename +
"': mapping std::string[] to '_NR' column not allowed" ) );
2535 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2541 e.set_message(
"RDB::setData: error with file '" +
_filename +
"': " );
2545 throw(
RDBErr(
"RDB::setData: unexpected exception caught with file '" +
_filename +
"':" ) );
2551 if (
"_NR" != name ) {
2552 throw (
RDBErr( std::string(
"RDB::setData(std::string&,double): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2568 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2574 e.set_message(
"RDB::setData: error with file '" +
_filename +
"': " );
2578 throw(
RDBErr(
"RDB::setData: unexpected exception caught with file '" +
_filename +
"':" ) );
2584 if (
"_NR" != name ) {
2585 throw (
RDBErr( std::string(
"RDB::setData(std::string&,long): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2601 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2607 e.set_message(
"RDB::setData: error with file '" +
_filename +
"': " );
2611 throw(
RDBErr(
"RDB::setData: unexpected exception caught with file '" +
_filename +
"':" ) );
2618 if (
"_NR" != name ) {
2619 throw (
RDBErr( std::string(
"RDB::setData(std::string&,std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2632 void RDB::getName(
const std::string& name, std::string& namefound )
const {
2634 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2642 if (
"_NR" != name ) {
2643 throw (
RDBErr( std::string(
"RDB::getName(std::string&,std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2658 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2666 if (
"_NR" != name ) {
2667 throw (
RDBErr( std::string(
"RDB::getDef(std::string&,std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2682 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2690 if (
"_NR" != name ) {
2691 throw (
RDBErr( std::string(
"RDB::getWidth(std::string&,long): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2706 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2714 if (
"_NR" != name ) {
2715 throw (
RDBErr( std::string(
"RDB::getType(std::string&,RDBColumn::Type): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2730 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2738 if (
"_NR" != name ) {
2739 throw (
RDBErr( std::string(
"RDB::getJust(std::string&,RDBColumn::Just): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2754 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2762 if (
"_NR" != name ) {
2763 throw (
RDBErr( std::string(
"RDB::getDesc(std::string&,std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2779 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2785 e.set_message(
"RDB::getData: error with file '" +
_filename +
"': " );
2789 throw(
RDBErr(
"RDB::getData: unexpected exception caught with file '" +
_filename +
"':" ) );
2796 if (
"_NR" != name ) {
2797 throw (
RDBErr( std::string(
"RDB::getData(std::string&,double): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2813 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2819 e.set_message(
"RDB::getData: error with file '" +
_filename +
"': " );
2823 throw(
RDBErr(
"RDB::getData: unexpected exception caught with file '" +
_filename +
"':" ) );
2830 if (
"_NR" != name ) {
2831 throw (
RDBErr( std::string(
"RDB::getData(std::string&,long&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2847 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2853 e.set_message(
"RDB::getData: error with file '" +
_filename +
"': " );
2857 throw(
RDBErr(
"RDB::getData: unexpected exception caught with file '" +
_filename +
"':" ) );
2864 if (
"_NR" != name ) {
2865 throw (
RDBErr( std::string(
"RDB::getData(std::string&,std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2881 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2888 if (
"_NR" != name ) {
2889 throw (
RDBErr( std::string(
"RDB::getName(std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2905 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2912 if (
"_NR" != name ) {
2913 throw (
RDBErr( std::string(
"RDB::getDef(std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2929 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2936 if (
"_NR" != name ) {
2937 throw (
RDBErr( std::string(
"RDB::getWidth(std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2953 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2960 if (
"_NR" != name ) {
2961 throw (
RDBErr( std::string(
"RDB::getType(std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2977 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2984 if (
"_NR" != name ) {
2985 throw (
RDBErr( std::string(
"RDB::getJust(std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
3001 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
3008 if (
"_NR" != name ) {
3009 throw (
RDBErr( std::string(
"RDB::getDesc(std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
3026 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
3032 e.set_message(
"RDB::getDataDouble: error with file '" +
_filename +
"': " );
3036 throw(
RDBErr(
"RDB::getDataDouble: unexpected exception caught with file '" +
_filename +
"':" ) );
3041 if (
"_NR" != name ) {
3042 throw (
RDBErr( std::string(
"RDB::getDataDouble(std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
3059 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
3065 e.set_message(
"RDB::getDataLong: error with file '" +
_filename +
"': " );
3069 throw(
RDBErr(
"RDB::getDataLong: unexpected exception caught with file '" +
_filename +
"':" ) );
3074 if (
"_NR" != name ) {
3075 throw (
RDBErr( std::string(
"RDB::getDataLong(std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
3092 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
3098 e.set_message(
"RDB::getDataString: error with file '" +
_filename +
"': " );
3102 throw(
RDBErr(
"RDB::getDataString: unexpected exception caught with file '" +
_filename +
"':" ) );
3107 if (
"_NR" != name ) {
3108 throw (
RDBErr( std::string(
"RDB::getDataString(std::string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
3161 position =
_isptr->tellg( );
3169 _isptr->seekg( position );
3188 std::string line0, line1;
3189 getline( *
_isptr, line0,
'\n' );
3191 while ( suplib::iscomment( line0 ) ) {
3197 std::stringstream ss;
3198 ss <<
"RDB::parseHeader(void): error at comment " <<
_ncomms +
_nrows <<
": ";
3199 e.set_message( ss.str( ) );
3203 std::stringstream ss;
3204 ss <<
"RDB::parseHeader(void): unexpected exception caught at comment " <<
_ncomms +
_nrows ;
3205 throw(
RDBErr( ss.str( ) ) );
3210 getline( *
_isptr, line0,
'\n' );
3213 getline( *
_isptr, line1,
'\n' );
3214 std::vector<std::string> nametokens;
3215 std::vector<std::string> deftokens;
3216 suplib::tok( nametokens, line0,
"\t",
false );
3217 suplib::tok( deftokens, line1,
"\t",
false );
3219 if ( nametokens.size( ) != deftokens.size( ) ) {
3220 std::stringstream ss;
3221 ss <<
"RDB::parseHeader(void): Number of names(" << nametokens.size( ) <<
") " << (nametokens.size() > deftokens.size() ?
"greater" :
"less") <<
" than number of definitions(" << deftokens.size( ) <<
")";
3222 throw(
RDBErr( ss.str( ) ) );
3225 _ncols = nametokens.size( );
3228 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
3244 for ( idx = 0; idx <
_ncols; idx++ ) {
3246 if ( deftokens[idx].npos != (typepos = deftokens[idx].find_first_not_of(
"0123456789" )) &&
'N' == deftokens[idx][typepos] ) {
3255 }
catch (
RDBErr& rdberr ) {
3256 rdberr.set_message(
"RDB::parseHeader(void): column definition error: " );
3260 throw(
RDBErr(
"RDB::parse::Header(void): unexpected exception caught" ) );
3282 std::vector<std::string>
3284 const std::string& line
3287 std::vector<std::string> tokens;
3288 if ( ! line.empty( ) ) {
3289 size_t st0 = 0, st1 = 0;
3292 st1 = line.find(
'\t', st0 );
3293 if ( line.size( ) < st1 ) {
3298 tokens.push_back( line.substr( st0, st1 - st0 ) );
3301 }
while ( line.size( ) > st1 );
3321 size_t end =
_line.find(
'\t' );
3325 end =
_line.find(
'\t', begin );
3335 }
while (
_line.npos != end );
3337 }
catch (
RDBErr& rdberr ) {
3338 std::stringstream ss;
3339 ss <<
"RDB::parseLine(void): error at row " <<
_rownum <<
": ";
3340 rdberr.set_message( ss.str( ) );
3344 std::stringstream ss;
3345 ss <<
"RDB::parseLine(void): unexpected exception caught at row " <<
_rownum;
3346 throw(
RDBErr( ss.str( ) ) );
size_t _ncols
Number of columns.
std::string getDef(void)
Returns the definition.
void getData(const size_t idx, double &data)
Return the data of the RDBColumn at idx, converting if necessary.
size_t nColumns(void) const
Return number of columns in RDB object.
virtual void rewind(void)=0
Rewinds index to the RDBColumn's data elements.
void setName(const std::string &name)
Sets the name.
std::ios::openmode _mode
Open mode of the associated stream.
void setComment(const std::string &comm, const int idx=-1)
Add RDBComment in header of RDB object.
Just
Acceptable column justifications.
std::string _line
Line from RDB table.
void setDef(const std::string &def)
Sets the definition.
size_t _nrows
Number of rows.
bool _knowrows
Indicates if associated file must be scanned to determine number of rows.
bool rewind(void)
Rewind the stream to the beginning of the first row of data.
bool _myosptr
Indicates if RDB object is responsible for deallocating the ostream.
RDBComment & getComment(const size_t idx)
Return RDBComment at given index.
bool _myisptr
Indicates if RDB object is responsible for deallocating the istream.
bool _firstread
Indicates if this is the first call to RDB::read.
void setWidth(const long width)
Sets the width.
void setJust(const RDBColumn::Just just)
Sets the justification.
virtual std::string getDataString(void)=0
Returns the value of the current data element, converting if necessary.
virtual void mapData(Tmplt0 data[], const size_t nelems)
Maps data to user-supplied memory.
void getDesc(const size_t idx, std::string &desc) const
Return the description of the RDBColumn at idx.
std::string getName(void) const
Returns the name.
bool _writehdr
Indicates if the header has been output.
void close(void)
Closes the stream attached to RDB object.
std::istream * _isptr
Istream attached to data file.
void setType(const RDBColumn::Type type)
Sets the type.
RDBLongColumn _nrcol
Hidden column, containing row number.
void getName(const size_t idx, std::string &name) const
Return the name of the RDBColumn at idx.
std::string getDesc(void) const
Returns the description.
The parent class for all RDB related exceptions.
int read(void)
Read a line of data from the istream.
void parseHeader(void)
Parse header, i.e. comments and column names and definitions.
~RDB(void)
Deletes resources allocated by the RDB object.
RDBColumn ** _cols
Array of RDBColumns.
virtual bool setData(const Tmplt0 &data)
Sets the data value, converting as necessary.
bool write(void)
Write a line of data to the ostream.
void setWidth(const size_t idx, const long width)
Modify the width of the RDBColumn at idx.
std::ostream * _osptr
Ostream attached to data file.
void setType(const size_t idx, const RDBColumn::Type type)
Modify the type of the RDBColumn at idx.
void setDesc(const size_t idx, const std::string &desc)
Modify the description of the RDBColumn at idx.
virtual void setGroup(bool group)
Turn on/off group tracking for this column object.
bool getGroup(void) const
Returns group status, RBOG if at beginning of a group, REOG if at ned of a group, or REOL if in the m...
void setData(const size_t idx, const double data)
Sets the data value of RDBColumn, converting as necessary.
void setGroup(const std::string &name, bool group=true)
Turn on/off group status for the named column.
RDBColumn * getColumn(const size_t idx)
Return pointer to RDBColumn at given index.
size_t nRows(void)
Return number of rows in RDB object.
bool autoIdx(void) const
Indicates if auto-indexing is activated.
RDBComment * _comms
Array of RDBComments.
RDB(const std::string &name="", std::ios::openmode mode=std::ios::in)
Attaches RDB object to a file.
RDBColumn::Type getType(void) const
Returns the type.
bool newGroup(void)
Checks if any column indicates a new group.
size_t _rewindto
Position of beginning of first row of data.
Provides interface for manipulating RDB tables.
virtual void mapData(double data[], const size_t nelems=1)
Maps data to user-supplied memory, if possible.
void setDesc(const std::string &desc)
Sets the description.
size_t _ncomms
Number of comments.
void getType(const size_t idx, RDBColumn::Type &type) const
Return the type of the RDBColumn at idx.
virtual long getDataLong(void)
Returns the value of the current data element, converting if necessary.
Type
Acceptable column types.
virtual double getDataDouble(void)=0
Returns the value of the current data element, converting if necessary.
virtual bool setData(const double &data)=0
Sets the data value, converting as necessary.
void getWidth(const size_t idx, long &width) const
Return the width of the RDBColumn at idx.
void mapData(const size_t idx, double data[], const size_t nelems=1)
Map RDBColumn data to user-supplied memory.
long getDataLong(const size_t idx)
Return the data of the RDBColumn at idx, converting if necessary.
void getDef(const size_t idx, std::string &def)
Return the definition of the RDBColumn at idx.
virtual double getDataDouble(void)
Returns the value of the current data element, converting if necessary.
virtual void setGroup(bool group)
size_t nComments(void) const
Return number of comments in RDB object.
long getWidth(void) const
Returns the width.
void advanceIdx(void)
Increments the indices in the RDBColumn data elements.
void open(const std::string &name, std::ios::openmode mode=std::ios::in)
Attaches RDB object to a file.
void setColumn(const std::string &name, const std::string &def, const int idx=-1)
Add an RDBColumn in RDB object.
std::vector< std::string > parseLine(const std::string &line) const
Parse fields in a row.
void setName(const size_t idx, const std::string &name)
Modify the name of the RDBColumn at idx.
void setDef(const size_t idx, const std::string &def)
Modify the definition of the RDBColumn at idx.
virtual std::string getDataString(void)
Returns the value of the current data element, converting if necessary.
std::string getDataString(const size_t idx)
Return the data of the RDBColumn at idx, converting if necessary.
bool _autoidx
Indicates if RDBColumn data elements should be advanced.
virtual void advanceIdx(void)=0
Increments index to the RDBColumn's data elements.
virtual void advanceIdx(void)
Increments index to the RDBColumn's data elements.
std::string _filename
Name of RDB file.
virtual int newGroup(void)=0
Returns the group status of this column object.
bool _lastread
Indicates if this is the last call to RDB::read.
RDBColumn::Just getJust(void) const
Returns the justification.
double getDataDouble(const size_t idx)
Return the data of the RDBColumn at idx, converting if necessary.
virtual long getDataLong(void)=0
Returns the value of the current data element, converting if necessary.
bool getGroup(const std::string &name)
Returns group status, true if its a new group, for the named column.
long _rownum
Current table row number.
Parameterizes RDBColumn interface for many data types.
Provides interface for general column related methods.
bool * _mycols
Indicates if RDB object is responsible for deallocating given RDBColumn.
void getJust(const size_t idx, RDBColumn::Just &just) const
Return the just of the RDBColumn at idx.
void setJust(const size_t idx, const RDBColumn::Just just)
Modify the justification of the RDBColumn at idx.