48 if ( RDB::REOF == rdb.
read( ) ) {
49 is.setstate( ios::eofbit | ios::failbit );
53 }
catch (
RDBErr& rdberr ) {
54 rdberr.set_message(
"operator>>(istream&,RDB&): " );
58 throw(
RDBErr(
"operator>>(istream&,RDB&): unexpected exception caught" ) );
89 }
catch (
RDBErr& rdberr ) {
90 rdberr.set_message(
"operator<<(ostream&,RDB&): " );
94 throw(
RDBErr(
"operator<<(ostream&,RDB&): unexpected exception caught" ) );
122 : _filename(name), _mode(mode),
123 _isptr(NULL), _osptr(NULL),
124 _myisptr(true), _myosptr(true),
126 _ncomms(0), _ncols(0), _nrows(0),
127 _knowrows(false), _rownum(0),
129 _firstread(true), _lastread(false), _writehdr(true),
130 _comms(NULL), _cols(NULL),
131 _nrcol(
"_NR",
"N"), _mycols(NULL),
136 if ( name.empty( ) ) {
143 }
catch (
RDBErr& rdberr ) {
144 rdberr.set_message(
"RDB::RDB(string&,ios::openmode): " );
148 throw(
RDBErr(
"RDB::RDB(string&,ios::openmode): unexpected exception caught" ) );
166 ) : _filename(
"istream"),
167 _isptr(NULL), _osptr(NULL),
168 _myisptr(false), _myosptr(false),
170 _ncomms(0), _ncols(0), _nrows(0),
171 _knowrows(false), _rownum(0),
173 _firstread(true), _lastread(false), _writehdr(true),
174 _comms(NULL), _cols(NULL),
175 _nrcol(
"_NR",
"N"), _mycols(NULL),
183 }
catch (
RDBErr& rdberr ) {
184 rdberr.set_message(
"RDB::RDB(istream*): " );
188 throw(
RDBErr(
"RDB::RDB(istream*): unexpected exception caught" ) );
201 ) : _filename(
"ostream"),
202 _isptr(NULL), _osptr(NULL),
203 _myisptr(false), _myosptr(false),
205 _ncomms(0), _ncols(0), _nrows(0),
206 _knowrows(false), _rownum(0),
208 _firstread(true), _lastread(false), _writehdr(true),
209 _comms(NULL), _cols(NULL),
210 _nrcol(
"_NR",
"N"), _mycols(NULL),
218 }
catch (
RDBErr& rdberr ) {
219 rdberr.set_message(
"RDB::RDB(ostream&): " );
223 throw(
RDBErr(
"RDB::RDB(ostream&): unexpected exception caught" ) );
236 ) : _filename(rdb._filename), _mode(rdb._mode),
237 _isptr(NULL), _osptr(NULL),
238 _myisptr(true), _myosptr(true),
239 _rewindto(0), _ncomms(0), _ncols(0), _nrows(0),
240 _knowrows(false), _rownum(0),
241 _autoidx(false), _firstread(true), _lastread(false),
243 _comms(NULL), _cols(NULL), _nrcol(
"_NR",
"N"),
244 _mycols(NULL), _line(1024,
'\0') {
251 }
catch (
RDBErr& rdberr ) {
252 rdberr.set_message(
"RDB::RDB(RDB&): " );
256 throw(
RDBErr(
"RDB::RDB(RDB&): unexpected exception caught" ) );
283 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
326 if ( ios::in &
_mode ) {
331 ss <<
"RDB::open(string&,ios_base::openmode): Error opening '" 333 if ( ios_base::app &
_mode )
334 ss <<
" ios_base::app";
335 if ( ios_base::binary &
_mode )
336 ss <<
" ios_base::binary";
337 if ( ios_base::in &
_mode )
338 ss <<
" ios_bae::in";
339 if ( ios_base::out &
_mode )
340 ss <<
" ios_base::out";
341 if ( ios_base::trunc &
_mode )
342 ss <<
" ios_base::trunc";
343 if ( ios_base::ate &
_mode )
344 ss <<
" ios_base::ate";
345 throw(
RDBErr( ss.str( ) ) );
352 }
catch (
RDBErr& rdberr ) {
353 rdberr.set_message(
"RDB::open(string&,ios::openmode): error with file '" +
_filename +
"': " );
357 throw(
RDBErr(
"RDB::open(string&,ios::openmode): unexpected exception caught with file '" +
_filename +
"'" ) );
362 if ( ios::out &
_mode ) {
367 ss <<
"RDB::open(string&,ios_base::openmode): Error opening '" 369 if ( ios_base::app &
_mode )
370 ss <<
" ios_base::app";
371 if ( ios_base::binary &
_mode )
372 ss <<
" ios_base::binary";
373 if ( ios_base::in &
_mode )
374 ss <<
" ios_bae::in";
375 if ( ios_base::out &
_mode )
376 ss <<
" ios_base::out";
377 if ( ios_base::trunc &
_mode )
378 ss <<
" ios_base::trunc";
379 if ( ios_base::ate &
_mode )
380 ss <<
" ios_base::ate";
381 throw(
RDBErr( ss.str( ) ) );
413 }
catch (
RDBErr& rdberr ) {
414 rdberr.set_message(
"RDB::open(istream&): " );
418 throw(
RDBErr(
"RDB::open(istream&): unexpected exception caught" ) );
460 if ( ios::in &
_mode ) {
465 ss <<
"RDB::open(RDB&): Error opening '" 467 if ( ios_base::app &
_mode )
468 ss <<
" ios_base::app";
469 if ( ios_base::binary &
_mode )
470 ss <<
" ios_base::binary";
471 if ( ios_base::in &
_mode )
472 ss <<
" ios_bae::in";
473 if ( ios_base::out &
_mode )
474 ss <<
" ios_base::out";
475 if ( ios_base::trunc &
_mode )
476 ss <<
" ios_base::trunc";
477 if ( ios_base::ate &
_mode )
478 ss <<
" ios_base::ate";
479 throw(
RDBErr( ss.str( ) ) );
486 }
catch (
RDBErr& rdberr ) {
487 rdberr.set_message(
"RDB::open(RDB&): error with file '" +
_filename +
"': " );
491 throw(
RDBErr(
"RDB::open(RDB&): unexpected exception caught with file '" +
_filename +
"'" ) );
496 if ( ios::out &
_mode ) {
501 ss <<
"RDB::open(RDB&): Error opening '" 503 if ( ios_base::app &
_mode )
504 ss <<
" ios_base::app";
505 if ( ios_base::binary &
_mode )
506 ss <<
" ios_base::binary";
507 if ( ios_base::in &
_mode )
508 ss <<
" ios_bae::in";
509 if ( ios_base::out &
_mode )
510 ss <<
" ios_base::out";
511 if ( ios_base::trunc &
_mode )
512 ss <<
" ios_base::trunc";
513 if ( ios_base::ate &
_mode )
514 ss <<
" ios_base::ate";
515 throw(
RDBErr( ss.str( ) ) );
537 for ( idx = 0; idx <
_ncomms; idx++ )
541 for ( idx = 0; idx <
_ncols - 1; idx++ )
545 for ( idx = 0; idx <
_ncols - 1; idx++ )
594 int newgroup = RDB::REOF;
615 vector<string> tokens;
616 suplib::tok( tokens,
_line,
"\t",
false );
618 if ( tokens.size( ) !=
_ncols ) {
620 ss <<
"RDB::read(void): error reading file '" <<
_filename <<
"': invalid row at " <<
_rownum <<
": number of token(" << tokens.size( ) <<
") != number of columns(" <<
_ncols <<
")";
621 throw(
RDBErr( ss.str( ) ) );
624 for (
int idx = 0; idx <
_ncols; idx++ ) {
632 }
catch (
RDBErr& rdberr ) {
633 rdberr.set_message(
"RDB::read(void): error reading file '" +
_filename +
"': " );
637 throw(
RDBErr(
"RDB::read(void): unexpected exception caught with file '" +
_filename +
"'" ) );
646 for (
int idx = 0; idx <
_ncols; idx++ ) {
653 vector<string> tokens;
654 suplib::tok( tokens,
_line,
"\t",
false );
656 if ( tokens.size( ) !=
_ncols ) {
658 ss <<
"RDB::read(void): error reading file '" <<
_filename <<
"': invalid row at " <<
_rownum+1 <<
": number of token(" << tokens.size( ) <<
") != number of columns(" <<
_ncols <<
")";
659 throw(
RDBErr( ss.str( ) ) );
662 for (
int idx = 0; idx <
_ncols; idx++ ) {
670 }
catch (
RDBErr& rdberr ) {
671 rdberr.set_message(
"RDB::read(void): error reading file '" +
_filename +
"': " );
675 throw(
RDBErr(
"RDB::read(void): unexpected exception caught reading file '" +
_filename +
"'" ) );
685 newgroup = RDB::REOG;
687 newgroup = RDB::REOF;
719 for ( idx = 0; idx <
_ncomms; idx++ )
722 for ( idx = 0; idx <
_ncols - 1; idx++ )
726 for ( idx = 0; idx <
_ncols - 1; idx++ )
741 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
776 if ( ios::in &
_mode ) {
785 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
793 }
else if ( ios::out &
_mode ) {
802 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
861 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
885 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
894 if (
"_NR" != name ) {
895 throw(
RDBErr(
string(
"RDB::setGroup(string): error in file '" +
_filename +
"': Column ") + name +
"(0) not found" ) );
918 if ( 0 <= idx && idx < (
int)
_ncols ) {
923 ss <<
"RDB::setGroup(string): error with file '" +
_filename +
"': Column " << idx <<
" of " <<
_ncols <<
" not found";
924 throw(
RDBErr( ss.str( ) ) );
942 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
949 if (
"_NR" != name ) {
950 throw(
RDBErr(
string(
"RDB::getGroup(string): error with file '" +
_filename +
"': Column ") + name +
"(0) not found" ) );
971 if ( 0 > idx && idx >=
_ncols ) {
973 ss <<
"RDB::getGroup(string): error with file '" +
_filename +
"': Column " << idx <<
" out of " <<
_ncols <<
" not found";
974 throw(
RDBErr( ss.str( ) ) );
993 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
1020 if ( 0 < idx && idx < (
int)
_ncomms ) {
1027 for (
size_t jdx = 0; jdx <
_ncomms; jdx++ ) {
1058 if ( 0 < idx && idx < (
int)
_ncomms ) {
1065 for (
size_t jdx = 0; jdx <
_ncomms; jdx++ ) {
1096 for (
size_t jdx = 0; jdx <
_ncomms; jdx++ ) {
1097 if ( name ==
_comms[jdx].getKeyword( ) ) {
1129 for (
size_t idx = 0; idx <
_ncomms; idx++ ) {
1152 if ( 0 > idx && idx >=
_ncomms ) {
1154 ss <<
"RDB::getComment(size_t): error with file '" +
_filename +
"': Comment " << idx <<
"out of "<<
_ncomms <<
" not found";
1155 throw(
RDBErr( ss.str( ) ) );
1178 for (
size_t jdx = 0; jdx <
_ncomms; jdx++ ) {
1179 if ( name ==
_comms[jdx].getKeyword( ) ) {
1186 ss <<
"RDB::getComment(string): error with file '" <<
_filename<<
"': Comment " << name <<
"("<< idx <<
") not found";
1187 throw(
RDBErr( ss.str( ) ) );
1214 if ( 0 <= idx && idx < (
int)
_ncols ) {
1227 bool* tmpmycols =
new bool[
_ncols+1];
1230 if ( def.npos != (pos = def.find_first_not_of(
"0123456789" )) &&
'N' == def[pos] ) {
1237 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
1238 tmp[jdx] =
_cols[jdx];
1239 tmpmycols[jdx] =
_mycols[jdx];
1249 tmpmycols[
_ncols++] =
true;
1279 if ( 0 <= idx && idx < (
int)
_ncols ) {
1291 bool* tmpmycols =
new bool[
_ncols+1];
1294 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
1295 tmp[jdx] =
_cols[jdx];
1296 tmpmycols[jdx] =
_mycols[jdx];
1306 tmpmycols[
_ncols++] =
false;
1337 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
1375 bool* tmpmycols =
new bool[rdb.
_ncols];
1378 for ( idx = 0; idx <
_ncols; idx++ ) {
1379 tmp[idx] = rdb.
_cols[idx];
1380 tmpmycols[idx] =
false;
1395 for ( ; idx < rdb.
_ncols; idx++ ) {
1396 tmp[idx] = rdb.
_cols[idx];
1397 tmpmycols[idx] =
false;
1404 for ( idx = 0; idx < rdb.
_ncols; idx++ ) {
1410 for ( ; idx <
_ncols; idx++ ) {
1437 if ( 0 > idx && idx >=
_ncols ) {
1439 ss <<
"RDB::getColumn(size_t): error with file '" <<
_filename <<
"': Column " << idx <<
" out of "<<
_ncols <<
" not found";
1440 throw(
RDBErr( ss.str( ) ) );
1463 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
1470 if (
"_NR" != name ) {
1472 ss <<
"RDB::getColumn(string): error with file '" <<
_filename <<
"': Column " << name <<
"("<< idx <<
") not found";
1473 throw(
RDBErr( ss.str( ) ) );
1490 if ( idx >= (
int)
_ncols ) {
1492 ss <<
"RDB::setName: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1493 throw(
RDBErr( ss.str( ) ) );
1511 if ( idx > (
int)
_ncols ) {
1513 ss <<
"RDB::setDef: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1514 throw(
RDBErr( ss.str( ) ) );
1521 e.set_message(
"RDB::setDef: error with file '" +
_filename +
"': " );
1525 throw(
RDBErr(
"RDB::setDef: unexpected exception caught with file '" +
_filename +
"'" ) );
1539 if ( idx > (
int)
_ncols ) {
1541 ss <<
"RDB::setWidth: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1542 throw(
RDBErr( ss.str( ) ) );
1549 e.set_message(
"RDB::setWidth: error with file '" +
_filename +
"': " );
1553 throw(
RDBErr(
"RDB::setWidth: unexpected exception caught with file '" +
_filename +
"'" ) );
1567 if ( idx > (
int)
_ncols ) {
1569 ss <<
"RDB::setType: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1570 throw(
RDBErr( ss.str( ) ) );
1577 e.set_message(
"RDB::setType: error with file '" +
_filename +
"': " );
1581 throw(
RDBErr(
"RDB::setType: unexpected exception caught with file '" +
_filename +
"'" ) );
1595 if ( idx > (
int)
_ncols ) {
1597 ss <<
"RDB::setJust: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1598 throw(
RDBErr( ss.str( ) ) );
1605 e.set_message(
"RDB::setJust: error with file '" +
_filename +
"': " );
1609 throw(
RDBErr(
"RDB::setJust: unexpected exception caught with file '" +
_filename +
"'" ) );
1623 if ( idx > (
int)
_ncols ) {
1625 ss <<
"RDB::setDesc: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1626 throw(
RDBErr( ss.str( ) ) );
1633 e.set_message(
"RDB::setDesc: error with file '" +
_filename +
"': " );
1637 throw(
RDBErr(
"RDB::setDesc: unexpected exception caught with file '" +
_filename +
"'" ) );
1650 void RDB::mapData(
const size_t idx,
double data[],
const size_t nelems ) {
1651 if ( idx > (
int)
_ncols ) {
1653 ss <<
"RDB::mapData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1654 throw(
RDBErr( ss.str( ) ) );
1661 e.set_message(
"RDB::mapData: error with file '" +
_filename +
"': " );
1665 throw(
RDBErr(
"RDB::mapData: unexpected exception caught with file '" +
_filename +
"'" ) );
1680 if ( idx > (
int)
_ncols ) {
1682 ss <<
"RDB::mapData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1683 throw(
RDBErr( ss.str( ) ) );
1690 e.set_message(
"RDB::mapData: error with file '" +
_filename +
"': " );
1694 throw(
RDBErr(
"RDB::mapData: unexpected exception caught with file '" +
_filename +
"'" ) );
1707 void RDB::mapData(
const size_t idx,
string data[],
const size_t nelems ) {
1709 if ( idx > (
int)
_ncols ) {
1711 ss <<
"RDB::mapData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1712 throw(
RDBErr( ss.str( ) ) );
1719 e.set_message(
"RDB::mapData: error with file '" +
_filename +
"': " );
1723 throw(
RDBErr(
"RDB::mapData: unexpected exception caught with file '" +
_filename +
"'" ) );
1737 if ( idx > (
int)
_ncols ) {
1739 ss <<
"RDB::setData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1740 throw(
RDBErr( ss.str( ) ) );
1747 e.set_message(
"RDB::setData: error with file '" +
_filename +
"': " );
1751 throw(
RDBErr(
"RDB::setData: unexpected exception caught with file '" +
_filename +
"'" ) );
1765 if ( idx > (
int)
_ncols ) {
1767 ss <<
"RDB::setData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1768 throw(
RDBErr( ss.str( ) ) );
1775 e.set_message(
"RDB::setData: error with file '" +
_filename +
"': " );
1779 throw(
RDBErr(
"RDB::setData: unexpected exception caught with file '" +
_filename +
"'" ) );
1793 if ( idx > (
int)
_ncols ) {
1795 ss <<
"RDB::setData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1796 throw(
RDBErr( ss.str( ) ) );
1803 e.set_message(
"RDB::setData: error with file '" +
_filename +
"': " );
1807 throw(
RDBErr(
"RDB::setData: unexpected exception caught with file '" +
_filename +
"'" ) );
1820 if ( idx > (
int)
_ncols ) {
1822 ss <<
"RDB::getName: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1823 throw(
RDBErr( ss.str( ) ) );
1839 if ( idx > (
int)
_ncols ) {
1841 ss <<
"RDB::getDef: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1842 throw(
RDBErr( ss.str( ) ) );
1858 if ( idx > (
int)
_ncols ) {
1860 ss <<
"RDB::getWidth: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1861 throw(
RDBErr( ss.str( ) ) );
1877 if ( idx > (
int)
_ncols ) {
1879 ss <<
"RDB::getType: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1880 throw(
RDBErr( ss.str( ) ) );
1896 if ( idx > (
int)
_ncols ) {
1898 ss <<
"RDB::getJust: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1899 throw(
RDBErr( ss.str( ) ) );
1915 if ( idx > (
int)
_ncols ) {
1917 ss <<
"RDB::getDesc: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1918 throw(
RDBErr( ss.str( ) ) );
1935 if ( idx > (
int)
_ncols ) {
1937 ss <<
"RDB::getData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1938 throw(
RDBErr( ss.str( ) ) );
1945 e.set_message(
"RDB::getData: error with file '" +
_filename +
"': " );
1949 throw(
RDBErr(
"RDB::getData: unexpected exception caught with file '" +
_filename +
"'" ) );
1963 if ( idx > (
int)
_ncols ) {
1965 ss <<
"RDB::getData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1966 throw(
RDBErr( ss.str( ) ) );
1973 e.set_message(
"RDB::getData: error with file '" +
_filename +
"': " );
1977 throw(
RDBErr(
"RDB::getData: unexpected exception caught with file '" +
_filename +
"'" ) );
1991 if ( idx > (
int)
_ncols ) {
1993 ss <<
"RDB::getData: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
1994 throw(
RDBErr( ss.str( ) ) );
2001 e.set_message(
"RDB::getData: error with file '" +
_filename +
"': " );
2005 throw(
RDBErr(
"RDB::getData: unexpected exception caught with file '" +
_filename +
"': " ) );
2019 if ( idx > (
int)
_ncols ) {
2021 ss <<
"RDB::getName: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2022 throw(
RDBErr( ss.str( ) ) );
2039 if ( idx > (
int)
_ncols ) {
2041 ss <<
"RDB::getDef: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2042 throw(
RDBErr( ss.str( ) ) );
2059 if ( idx > (
int)
_ncols ) {
2061 ss <<
"RDB::getWidth: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2062 throw(
RDBErr( ss.str( ) ) );
2079 if ( idx > (
int)
_ncols ) {
2081 ss <<
"RDB::getType: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2082 throw(
RDBErr( ss.str( ) ) );
2099 if ( idx > (
int)
_ncols ) {
2101 ss <<
"RDB::getJust: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2102 throw(
RDBErr( ss.str( ) ) );
2119 if ( idx > (
int)
_ncols ) {
2121 ss <<
"RDB::getDesc: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2122 throw(
RDBErr( ss.str( ) ) );
2140 if ( idx > (
int)
_ncols ) {
2142 ss <<
"RDB::getDataDouble: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2143 throw(
RDBErr( ss.str( ) ) );
2150 e.set_message(
"RDB::getDataDouble: error with file '" +
_filename +
"': " );
2154 throw(
RDBErr(
"RDB::getDataDouble: unexpected exception caught with file '" +
_filename +
"':" ) );
2169 if ( idx > (
int)
_ncols ) {
2171 ss <<
"RDB::getDataLong: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2172 throw(
RDBErr( ss.str( ) ) );
2179 e.set_message(
"RDB::getDataLong: error with file '" +
_filename +
"': " );
2183 throw(
RDBErr(
"RDB::getDataLong: unexpected exception caught with file '" +
_filename +
"':" ) );
2198 if ( idx > (
int)
_ncols ) {
2200 ss <<
"RDB::getDataString: error with file '" <<
_filename <<
"': index out of range [0," << idx <<
")";
2201 throw(
RDBErr( ss.str( ) ) );
2208 e.set_message(
"RDB::getDataString: error with file '" +
_filename +
"': " );
2212 throw(
RDBErr(
"RDB::getDataString: unexpected exception caught with file '" +
_filename +
"':" ) );
2226 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2234 if (
"_NR" != name ) {
2235 throw (
RDBErr(
string(
"RDB::setName(string&,string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2252 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2258 e.set_message(
"RDB::setDef: error with file '" +
_filename +
"': " );
2262 throw(
RDBErr(
"RDB::setDef: unexpected exception caught with file '" +
_filename +
"':" ) );
2270 if (
"_NR" != name ) {
2271 throw (
RDBErr(
string(
"RDB::setDef(string&,string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2287 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2293 e.set_message(
"RDB::setWidth: error with file '" +
_filename +
"': " );
2297 throw(
RDBErr(
"RDB::setWidth: unexpected exception caught with file '" +
_filename +
"':" ) );
2305 if (
"_NR" != name ) {
2306 throw (
RDBErr(
string(
"RDB::setWidth(string&,long): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2322 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2328 e.set_message(
"RDB::setType: error with file '" +
_filename +
"': " );
2332 throw(
RDBErr(
"RDB::setType: error with file '" +
_filename +
"': unexpected exception caught" ) );
2340 if (
"_NR" != name ) {
2341 throw (
RDBErr(
string(
"RDB::setType(string&,RDBColumn::Type): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2357 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2363 e.set_message(
"RDB::setJust: error with file '" +
_filename +
"': " );
2367 throw(
RDBErr(
"RDB::setJust: error with file '" +
_filename +
"': unexpected exception caught" ) );
2375 if (
"_NR" != name ) {
2376 throw (
RDBErr(
string(
"RDB::setJust(string&,RDBColumn::Just): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2392 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2398 e.set_message(
"RDB::setDesc: error with file '" +
_filename +
"': " );
2402 throw(
RDBErr(
"RDB::setDesc: error with file '" +
_filename +
"': unexpected exception caught" ) );
2410 if (
"_NR" != name ) {
2411 throw (
RDBErr(
string(
"RDB::setDesc(string&,string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2426 void RDB::mapData(
const string& name,
double data[],
const size_t nelems ) {
2428 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2434 e.set_message(
"RDB::mapData: error with file '" +
_filename +
"': " );
2438 throw(
RDBErr(
"RDB::mapData: error with file '" +
_filename +
"': unexpected exception caught" ) );
2446 if (
"_NR" != name ) {
2447 throw (
RDBErr(
string(
"RDB::mapData(string&,double[],size_t): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2449 throw(
RDBErr(
"RDB::mapData('_NR',double[],size_t): error with file '" +
_filename +
"': mapping double[] to '_NR' column not allowed" ) );
2462 void RDB::mapData(
const string& name,
long data[],
const size_t nelems ) {
2464 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2470 e.set_message(
"RDB::mapData: error with file '" +
_filename +
"': " );
2474 throw(
RDBErr(
"RDB::mapData: unexpected exception caught with file '" +
_filename +
"':" ) );
2483 if (
"_NR" != name ) {
2484 throw (
RDBErr(
string(
"RDB::mapData(string&,long[],size_t): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2499 void RDB::mapData(
const string& name,
string data[],
const size_t nelems ) {
2501 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2507 e.set_message(
"RDB::mapData: error with file '" +
_filename +
"': " );
2511 throw(
RDBErr(
"RDB::mapData: unexpected exception caught with file '" +
_filename +
"':" ) );
2519 if (
"_NR" != name ) {
2520 throw (
RDBErr(
string(
"RDB::mapData(string&,string[],size_t): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2522 throw(
RDBErr(
"RDB::mapData('_NR',string[],size_t): error with file '" +
_filename +
"': mapping string[] to '_NR' column not allowed" ) );
2536 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2542 e.set_message(
"RDB::setData: error with file '" +
_filename +
"': " );
2546 throw(
RDBErr(
"RDB::setData: unexpected exception caught with file '" +
_filename +
"':" ) );
2552 if (
"_NR" != name ) {
2553 throw (
RDBErr(
string(
"RDB::setData(string&,double): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2569 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2575 e.set_message(
"RDB::setData: error with file '" +
_filename +
"': " );
2579 throw(
RDBErr(
"RDB::setData: unexpected exception caught with file '" +
_filename +
"':" ) );
2585 if (
"_NR" != name ) {
2586 throw (
RDBErr(
string(
"RDB::setData(string&,long): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2602 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2608 e.set_message(
"RDB::setData: error with file '" +
_filename +
"': " );
2612 throw(
RDBErr(
"RDB::setData: unexpected exception caught with file '" +
_filename +
"':" ) );
2619 if (
"_NR" != name ) {
2620 throw (
RDBErr(
string(
"RDB::setData(string&,string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2635 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2643 if (
"_NR" != name ) {
2644 throw (
RDBErr(
string(
"RDB::getName(string&,string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2659 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2667 if (
"_NR" != name ) {
2668 throw (
RDBErr(
string(
"RDB::getDef(string&,string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2683 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2691 if (
"_NR" != name ) {
2692 throw (
RDBErr(
string(
"RDB::getWidth(string&,long): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2707 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2715 if (
"_NR" != name ) {
2716 throw (
RDBErr(
string(
"RDB::getType(string&,RDBColumn::Type): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2731 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2739 if (
"_NR" != name ) {
2740 throw (
RDBErr(
string(
"RDB::getJust(string&,RDBColumn::Just): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2755 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2763 if (
"_NR" != name ) {
2764 throw (
RDBErr(
string(
"RDB::getDesc(string&,string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2780 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2786 e.set_message(
"RDB::getData: error with file '" +
_filename +
"': " );
2790 throw(
RDBErr(
"RDB::getData: unexpected exception caught with file '" +
_filename +
"':" ) );
2797 if (
"_NR" != name ) {
2798 throw (
RDBErr(
string(
"RDB::getData(string&,double): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2814 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2820 e.set_message(
"RDB::getData: error with file '" +
_filename +
"': " );
2824 throw(
RDBErr(
"RDB::getData: unexpected exception caught with file '" +
_filename +
"':" ) );
2831 if (
"_NR" != name ) {
2832 throw (
RDBErr(
string(
"RDB::getData(string&,long&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2848 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2854 e.set_message(
"RDB::getData: error with file '" +
_filename +
"': " );
2858 throw(
RDBErr(
"RDB::getData: unexpected exception caught with file '" +
_filename +
"':" ) );
2865 if (
"_NR" != name ) {
2866 throw (
RDBErr(
string(
"RDB::getData(string&,string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2882 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2889 if (
"_NR" != name ) {
2890 throw (
RDBErr(
string(
"RDB::getName(string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2906 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2913 if (
"_NR" != name ) {
2914 throw (
RDBErr(
string(
"RDB::getDef(string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2930 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2937 if (
"_NR" != name ) {
2938 throw (
RDBErr(
string(
"RDB::getWidth(string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2954 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2961 if (
"_NR" != name ) {
2962 throw (
RDBErr(
string(
"RDB::getType(string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
2978 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
2985 if (
"_NR" != name ) {
2986 throw (
RDBErr(
string(
"RDB::getJust(string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
3002 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
3009 if (
"_NR" != name ) {
3010 throw (
RDBErr(
string(
"RDB::getDesc(string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
3027 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
3033 e.set_message(
"RDB::getDataDouble: error with file '" +
_filename +
"': " );
3037 throw(
RDBErr(
"RDB::getDataDouble: unexpected exception caught with file '" +
_filename +
"':" ) );
3042 if (
"_NR" != name ) {
3043 throw (
RDBErr(
string(
"RDB::getDataDouble(string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
3060 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
3066 e.set_message(
"RDB::getDataLong: error with file '" +
_filename +
"': " );
3070 throw(
RDBErr(
"RDB::getDataLong: unexpected exception caught with file '" +
_filename +
"':" ) );
3075 if (
"_NR" != name ) {
3076 throw (
RDBErr(
string(
"RDB::getDataLong(string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
3093 for (
size_t jdx = 0; jdx <
_ncols; jdx++ ) {
3099 e.set_message(
"RDB::getDataString: error with file '" +
_filename +
"': " );
3103 throw(
RDBErr(
"RDB::getDataString: unexpected exception caught with file '" +
_filename +
"':" ) );
3108 if (
"_NR" != name ) {
3109 throw (
RDBErr(
string(
"RDB::getDataString(string&): error with file '" +
_filename +
"': Column ") + name +
" not found" ) );
3162 position =
_isptr->tellg( );
3170 _isptr->seekg( position );
3189 string line0, line1;
3190 getline( *
_isptr, line0,
'\n' );
3192 while ( suplib::iscomment( line0 ) ) {
3199 ss <<
"RDB::parseHeader(void): error at comment " <<
_ncomms +
_nrows <<
": ";
3200 e.set_message( ss.str( ) );
3205 ss <<
"RDB::parseHeader(void): unexpected exception caught at comment " <<
_ncomms +
_nrows ;
3206 throw(
RDBErr( ss.str( ) ) );
3211 getline( *
_isptr, line0,
'\n' );
3214 getline( *
_isptr, line1,
'\n' );
3215 vector<string> nametokens;
3216 vector<string> deftokens;
3217 suplib::tok( nametokens, line0,
"\t",
false );
3218 suplib::tok( deftokens, line1,
"\t",
false );
3220 if ( nametokens.size( ) != deftokens.size( ) ) {
3222 ss <<
"RDB::parseHeader(void): Number of names(" << nametokens.size( ) <<
") " << (nametokens.size() > deftokens.size() ?
"greater" :
"less") <<
" than number of definitions(" << deftokens.size( ) <<
")";
3223 throw(
RDBErr( ss.str( ) ) );
3226 _ncols = nametokens.size( );
3229 for (
size_t idx = 0; idx <
_ncols; idx++ ) {
3245 for ( idx = 0; idx <
_ncols; idx++ ) {
3247 if ( deftokens[idx].npos != (typepos = deftokens[idx].find_first_not_of(
"0123456789" )) &&
'N' == deftokens[idx][typepos] ) {
3256 }
catch (
RDBErr& rdberr ) {
3257 rdberr.set_message(
"RDB::parseHeader(void): column definition error: " );
3261 throw(
RDBErr(
"RDB::parse::Header(void): unexpected exception caught" ) );
3288 vector<string> tokens;
3289 if ( ! line.empty( ) ) {
3290 size_t st0 = 0, st1 = 0;
3293 st1 = line.find(
'\t', st0 );
3294 if ( line.size( ) < st1 ) {
3299 tokens.push_back( line.substr( st0, st1 - st0 ) );
3302 }
while ( line.size( ) > st1 );
3322 size_t end =
_line.find(
'\t' );
3326 end =
_line.find(
'\t', begin );
3336 }
while (
_line.npos != end );
3338 }
catch (
RDBErr& rdberr ) {
3340 ss <<
"RDB::parseLine(void): error at row " <<
_rownum <<
": ";
3341 rdberr.set_message( ss.str( ) );
3346 ss <<
"RDB::parseLine(void): unexpected exception caught at row " <<
_rownum;
3347 throw(
RDBErr( ss.str( ) ) );
void setComment(const string &comm, const int idx=-1)
Add RDBComment in header of RDB object.
size_t _ncols
Number of columns.
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.
string getName(void) const
Returns the name.
virtual void rewind(void)=0
Rewinds index to the RDBColumn's data elements.
virtual string getDataString(void)
Returns the value of the current data element, converting if necessary.
vector< string > parseLine(const string &line) const
Parse fields in a row.
string _filename
Name of RDB file.
Just
Acceptable column justifications.
size_t _nrows
Number of rows.
void setName(const string &name)
Sets the name.
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.
void setGroup(const string &name, bool group=true)
Turn on/off group status for the named column.
RDBComment & getComment(const size_t idx)
Return RDBComment at given index.
bool _myisptr
Indicates if RDB object is responsible for deallocating the istream.
void setDesc(const size_t idx, const string &desc)
Modify the description of the RDBColumn at idx.
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 void mapData(Tmplt0 data[], const size_t nelems)
Maps data to user-supplied memory.
string getDataString(const size_t idx)
Return the data of the RDBColumn at idx, converting if necessary.
bool _writehdr
Indicates if the header has been output.
void close(void)
Closes the stream attached to RDB object.
void setType(const RDBColumn::Type type)
Sets the type.
void setDef(const string &def)
Sets the definition.
void setDef(const size_t idx, const string &def)
Modify the definition of the RDBColumn at idx.
RDBLongColumn _nrcol
Hidden column, containing row number.
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.
void getDef(const size_t idx, string &def)
Return the definition of the RDBColumn at idx.
~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.
void open(const string &name, ios::openmode mode=ios::in)
Attaches RDB object to a file.
void setType(const size_t idx, const RDBColumn::Type type)
Modify the type 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.
RDBColumn * getColumn(const size_t idx)
Return pointer to RDBColumn at given index.
size_t nRows(void)
Return number of rows in RDB object.
ostream * _osptr
Ostream attached to data file.
bool autoIdx(void) const
Indicates if auto-indexing is activated.
string getDesc(void) const
Returns the description.
RDBComment * _comms
Array of RDBComments.
istream * _isptr
Istream attached to data 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.
RDB(const string &name="", ios::openmode mode=ios::in)
Attaches RDB object to a file.
virtual void mapData(double data[], const size_t nelems=1)
Maps data to user-supplied memory, if possible.
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.
void setDesc(const string &desc)
Sets the description.
long getDataLong(const size_t idx)
Return the data of the RDBColumn at idx, converting if necessary.
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.
string _line
Line from RDB table.
void setColumn(const string &name, const string &def, const int idx=-1)
Add an RDBColumn in RDB object.
void getDesc(const size_t idx, string &desc) const
Return the description of the RDBColumn at idx.
ios::openmode _mode
Open mode of the associated stream.
string getDef(void)
Returns the definition.
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.
void setName(const size_t idx, const string &name)
Modify the name of the RDBColumn at idx.
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.
long _rownum
Current table row number.
virtual string getDataString(void)=0
Returns the value of the current data element, converting if necessary.
Parameterizes RDBColumn interface for many data types.
bool getGroup(const string &name)
Returns group status, true if its a new group, for the named column.
void getName(const size_t idx, string &name) const
Return the name of the RDBColumn at idx.
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.