rdbxx  1.0.7_02
RDB.cc
1 // --8<--8<--8<--8<--
2 //
3 // Copyright (C) 2006 Smithsonian Astrophysical Observatory
4 //
5 // This file is part of RDB
6 //
7 // RDB is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // RDB is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the
19 // Free Software Foundation, Inc.
20 // 51 Franklin Street, Fifth Floor
21 // Boston, MA 02110-1301, USA
22 //
23 // -->8-->8-->8-->8--
24 
25 #include "RDB.h"
26 
37 istream&
38 operator>>(
39  istream& is,
40  RDB& rdb
41  ) {
42 
43  try {
44  if ( &is != rdb._isptr ) {
45  rdb.open( &is );
46 
47  } else {
48  if ( RDB::REOF == rdb.read( ) ) {
49  is.setstate( ios::eofbit | ios::failbit );
50 
51  }
52  }
53  } catch ( RDBErr& rdberr ) {
54  rdberr.set_message( "operator>>(istream&,RDB&): " );
55  throw( rdberr );
56 
57  } catch ( ... ) {
58  throw( RDBErr( "operator>>(istream&,RDB&): unexpected exception caught" ) );
59 
60  }
61 
62  return is;
63 
64 }
65 
75 ostream&
76 operator<<(
77  ostream& os,
78  RDB& rdb
79  ) {
80 
81  try {
82  if ( &os != rdb._osptr ) {
83  rdb.open( &os );
84 
85  } else {
86  rdb.write( );
87 
88  }
89  } catch ( RDBErr& rdberr ) {
90  rdberr.set_message( "operator<<(ostream&,RDB&): " );
91  throw( rdberr );
92 
93  } catch ( ... ) {
94  throw( RDBErr( "operator<<(ostream&,RDB&): unexpected exception caught" ) );
95 
96  }
97 
98  return os;
99 
100 }
101 
119  const string& name,
120  ios::openmode mode
121  )
122  : _filename(name), _mode(mode),
123  _isptr(NULL), _osptr(NULL),
124  _myisptr(true), _myosptr(true),
125  _rewindto(0),
126  _ncomms(0), _ncols(0), _nrows(0),
127  _knowrows(false), _rownum(0),
128  _autoidx(false),
129  _firstread(true), _lastread(false), _writehdr(true),
130  _comms(NULL), _cols(NULL),
131  _nrcol("_NR","N"), _mycols(NULL),
132  _line(1024,'\0') {
133 
134  _nrcol.mapData( &_rownum, 1 );
135 
136  if ( name.empty( ) ) {
137  close( );
138 
139  } else {
140  try {
141  open( name, mode );
142 
143  } catch ( RDBErr& rdberr ) {
144  rdberr.set_message( "RDB::RDB(string&,ios::openmode): " );
145  throw( rdberr );
146 
147  } catch ( ... ) {
148  throw( RDBErr( "RDB::RDB(string&,ios::openmode): unexpected exception caught" ) );
149 
150  }
151  }
152 }
153 
165  istream* isptr
166  ) : _filename("istream"),
167  _isptr(NULL), _osptr(NULL),
168  _myisptr(false), _myosptr(false),
169  _rewindto(0),
170  _ncomms(0), _ncols(0), _nrows(0),
171  _knowrows(false), _rownum(0),
172  _autoidx(false),
173  _firstread(true), _lastread(false), _writehdr(true),
174  _comms(NULL), _cols(NULL),
175  _nrcol("_NR","N"), _mycols(NULL),
176  _line(1024,'\0') {
177 
178  _nrcol.mapData( &_rownum, 1 );
179 
180  try {
181  open( isptr );
182 
183  } catch ( RDBErr& rdberr ) {
184  rdberr.set_message( "RDB::RDB(istream*): " );
185  throw( rdberr );
186 
187  } catch ( ... ) {
188  throw( RDBErr( "RDB::RDB(istream*): unexpected exception caught" ) );
189 
190  }
191 }
192 
200  ostream* osptr
201  ) : _filename("ostream"),
202  _isptr(NULL), _osptr(NULL),
203  _myisptr(false), _myosptr(false),
204  _rewindto(0),
205  _ncomms(0), _ncols(0), _nrows(0),
206  _knowrows(false), _rownum(0),
207  _autoidx(false),
208  _firstread(true), _lastread(false), _writehdr(true),
209  _comms(NULL), _cols(NULL),
210  _nrcol("_NR","N"), _mycols(NULL),
211  _line(1024,'\0') {
212 
213  _nrcol.mapData( &_rownum, 1 );
214 
215  try {
216  open( osptr );
217 
218  } catch ( RDBErr& rdberr ) {
219  rdberr.set_message( "RDB::RDB(ostream&): " );
220  throw( rdberr );
221 
222  } catch ( ... ) {
223  throw( RDBErr( "RDB::RDB(ostream&): unexpected exception caught" ) );
224 
225  }
226 }
227 
235  const RDB& rdb
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),
242  _writehdr(true),
243  _comms(NULL), _cols(NULL), _nrcol("_NR","N"),
244  _mycols(NULL), _line(1024,'\0') {
245 
246  _nrcol.mapData( &_rownum, 1 );
247 
248  try {
249  open( rdb );
250 
251  } catch ( RDBErr& rdberr ) {
252  rdberr.set_message( "RDB::RDB(RDB&): " );
253  throw( rdberr );
254 
255  } catch ( ... ) {
256  throw( RDBErr( "RDB::RDB(RDB&): unexpected exception caught" ) );
257 
258  }
259 }
260 
272  void
273  ) {
274 
275  close( );
276 
277  if ( _comms ) {
278  delete [] _comms;
279 
280  }
281 
282  if ( _cols ) {
283  for ( size_t idx = 0; idx < _ncols; idx++ ) {
284  if ( _mycols[idx] ) {
285  delete _cols[idx];
286  }
287  }
288  delete [] _cols;
289  delete [] _mycols;
290  }
291 
292  _isptr = NULL;
293  _osptr = NULL;
294  _comms = NULL;
295  _cols = NULL;
296  _mycols = NULL;
297 
298 }
299 
315 void
317  const string& name,
318  ios::openmode mode
319  ) {
320 
321  close( );
322 
323  _filename = name;
324  _mode = mode;
325 
326  if ( ios::in & _mode ) {
327  _isptr = new ifstream( _filename.c_str( ), _mode );
328  _myisptr = true;
329  if ( ! _isptr || ! *_isptr ) {
330  stringstream ss;
331  ss << "RDB::open(string&,ios_base::openmode): Error opening '"
332  << _filename << "' with mode";
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( ) ) );
346 
347  }
348 
349  try {
350  parseHeader( );
351 
352  } catch ( RDBErr& rdberr ) {
353  rdberr.set_message( "RDB::open(string&,ios::openmode): error with file '" + _filename + "': " );
354  throw( rdberr );
355 
356  } catch ( ... ) {
357  throw( RDBErr( "RDB::open(string&,ios::openmode): unexpected exception caught with file '" + _filename + "'" ) );
358 
359  }
360  }
361 
362  if ( ios::out & _mode ) {
363  _osptr = new ofstream( _filename.c_str( ), _mode );
364  _myosptr = true;
365  if ( ! _osptr || ! *_osptr ) {
366  stringstream ss;
367  ss << "RDB::open(string&,ios_base::openmode): Error opening '"
368  << _filename << "' with mode";
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( ) ) );
382 
383  }
384  }
385 }
386 
399 void
401  istream* isptr
402  ) {
403 
404  close( );
405 
406  _filename = "istream";
407  _mode = ios::in;
408  _isptr = isptr;
409 
410  try {
411  parseHeader( );
412 
413  } catch ( RDBErr& rdberr ) {
414  rdberr.set_message( "RDB::open(istream&): " );
415  throw( rdberr );
416 
417  } catch ( ... ) {
418  throw( RDBErr( "RDB::open(istream&): unexpected exception caught" ) );
419 
420  }
421 }
422 
431 void
433  ostream* osptr
434  ) {
435 
436  close( );
437 
438  _filename = "ostream";
439  _mode = ios::out;
440  _osptr = osptr;
441 
442 }
443 
450 void
452  const RDB& rdb
453  ) {
454 
455  close( );
456 
457  _filename = rdb._filename;
458  _mode = rdb._mode;
459 
460  if ( ios::in & _mode ) {
461  _isptr = new ifstream( _filename.c_str( ), _mode );
462  _myisptr = true;
463  if ( ! _isptr ) {
464  stringstream ss;
465  ss << "RDB::open(RDB&): Error opening '"
466  << _filename << "' with mode";
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( ) ) );
480 
481  }
482 
483  try {
484  parseHeader( );
485 
486  } catch ( RDBErr& rdberr ) {
487  rdberr.set_message( "RDB::open(RDB&): error with file '" + _filename + "': " );
488  throw( rdberr );
489 
490  } catch ( ... ) {
491  throw( RDBErr( "RDB::open(RDB&): unexpected exception caught with file '" + _filename + "'" ) );
492 
493  }
494  }
495 
496  if ( ios::out & _mode ) {
497  _osptr = new ofstream( _filename.c_str( ), _mode );
498  _myosptr = true;
499  if ( ! _osptr ) {
500  stringstream ss;
501  ss << "RDB::open(RDB&): Error opening '"
502  << _filename << "' with mode";
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( ) ) );
516 
517  }
518  }
519 }
520 
525 void
527  void
528  ) {
529 
530  if ( _myisptr && _isptr ) {
531  delete _isptr;
532 
533  }
534 
535  if ( _osptr && _writehdr ) {
536  size_t idx;
537  for ( idx = 0; idx < _ncomms; idx++ )
538  *_osptr << _comms[idx] << endl;
539 
540  if ( _ncols ) {
541  for ( idx = 0; idx < _ncols - 1; idx++ )
542  *_osptr << _cols[idx]->getName( ) << "\t";
543  *_osptr << _cols[idx]->getName( ) << endl;
544 
545  for ( idx = 0; idx < _ncols - 1; idx++ )
546  *_osptr << _cols[idx]->getDef( ) << "\t";
547  *_osptr << _cols[idx]->getDef( ) << endl;
548 
549  _rewindto = _osptr->tellp( );
550  _rownum = 0;
551  _writehdr = false;
552 
553  }
554  }
555 
556  if ( _myosptr && _osptr ) {
557  delete _osptr;
558 
559  }
560 
561  _filename.erase( );
562  _isptr = NULL;
563  _myisptr = false;
564  _osptr = NULL;
565  _myosptr = false;
566  _autoidx = false;
567  _nrows = 0;
568  _knowrows = false;
569  _rownum = 0;
570 
571 }
572 
588 int
590  void
591  ) {
592 
593  if ( ios::in & _mode && _isptr && *_isptr ) {
594  int newgroup = RDB::REOF;
595  char c = _isptr->peek( );
596  if ( '\n' == c ) {
597  _isptr->get( );
598  c = _isptr->peek( );
599 
600  }
601 
602  if ( EOF == c ) {
603  if ( _lastread )
604  return RDB::REOF;
605  else
606  _lastread = true;
607  }
608 
609  _rownum++;
610 
611  if ( ! _lastread ) {
612  try {
613  getline( *_isptr, _line, '\n' );
614  _isptr->clear( );
615  vector<string> tokens;
616  suplib::tok( tokens, _line, "\t", false );
617 
618  if ( tokens.size( ) != _ncols ) {
619  stringstream ss;
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( ) ) );
622  }
623 
624  for ( int idx = 0; idx < _ncols; idx++ ) {
625  _cols[idx]->setData( tokens[idx] );
626  if ( _autoidx ) {
627  _cols[idx]->advanceIdx( );
628  }
629  newgroup = newgroup | _cols[idx]->newGroup( );
630 
631  }
632  } catch ( RDBErr& rdberr ) {
633  rdberr.set_message( "RDB::read(void): error reading file '" + _filename + "': " );
634  throw( rdberr );
635 
636  } catch ( ... ) {
637  throw( RDBErr( "RDB::read(void): unexpected exception caught with file '" + _filename + "'" ) );
638 
639  }
640 
641  if ( _firstread && (RDB::REOL ^ newgroup) ) {
642  try {
643  getline( *_isptr, _line, '\n' );
644  if ( _isptr->eof( ) ) {
645  newgroup |= REOG;
646  for ( int idx = 0; idx < _ncols; idx++ ) {
647  if ( _autoidx ) {
648  _cols[idx]->advanceIdx( );
649  }
650  }
651  } else {
652  _isptr->clear( );
653  vector<string> tokens;
654  suplib::tok( tokens, _line, "\t", false );
655 
656  if ( tokens.size( ) != _ncols ) {
657  stringstream ss;
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( ) ) );
660  }
661 
662  for ( int idx = 0; idx < _ncols; idx++ ) {
663  _cols[idx]->setData( tokens[idx] );
664  if ( _autoidx ) {
665  _cols[idx]->advanceIdx( );
666  }
667  // newgroup = _cols[idx]->newGroup( );
668  }
669  }
670  } catch ( RDBErr& rdberr ) {
671  rdberr.set_message( "RDB::read(void): error reading file '" + _filename + "': " );
672  throw( rdberr );
673 
674  } catch ( ... ) {
675  throw( RDBErr( "RDB::read(void): unexpected exception caught reading file '" + _filename + "'" ) );
676 
677  }
678 
679  _firstread = false;
680 
681  }
682  } else {
683  if ( _autoidx ) {
684  advanceIdx( );
685  newgroup = RDB::REOG;
686  } else {
687  newgroup = RDB::REOF;
688  }
689  }
690  return newgroup;
691 
692  } else {
693  return RDB::REOF;
694 
695  }
696 }
697 
711 bool
713  void
714  ) {
715 
716  if ( ios::out & _mode && _osptr ) {
717  if ( _writehdr ) {
718  size_t idx;
719  for ( idx = 0; idx < _ncomms; idx++ )
720  *_osptr << _comms[idx] << endl;
721 
722  for ( idx = 0; idx < _ncols - 1; idx++ )
723  *_osptr << _cols[idx]->getName( ) << "\t";
724  *_osptr << _cols[idx]->getName( ) << endl;
725 
726  for ( idx = 0; idx < _ncols - 1; idx++ )
727  *_osptr << _cols[idx]->getDef( ) << "\t";
728  *_osptr << _cols[idx]->getDef( ) << endl;
729 
730  _rewindto = _osptr->tellp( );
731  _rownum = 0;
732  _writehdr = false;
733 
734  }
735 
736  if ( _autoidx ) {
737  advanceIdx( );
738 
739  }
740 
741  for ( size_t idx = 0; idx < _ncols; idx++ ) {
742  *_osptr << *_cols[idx] << (( idx < _ncols - 1 ) ? ( '\t' ) : ( '\n' ));
743 
744  }
745 
746  _rownum++;
747 
748  return true;
749 
750  } else {
751  return false;
752 
753  }
754 }
755 
771 bool
773  void
774  ) {
775 
776  if ( ios::in & _mode ) {
777  _isptr->clear( );
778  _isptr->seekg( _rewindto );
779  _rownum = 0;
780 
781  if ( _rewindto != (size_t)_isptr->tellg( ) ) {
782  return false;
783 
784  } else {
785  for ( size_t idx = 0; idx < _ncols; idx++ ) {
786  _cols[idx]->rewind( );
787 
788  }
789 
790  return true;
791 
792  }
793  } else if ( ios::out & _mode ) {
794  _osptr->clear( );
795  _osptr->seekp( _rewindto );
796  _rownum = 0;
797 
798  if ( _rewindto != (size_t)_osptr->tellp( ) ) {
799  return false;
800 
801  } else {
802  for ( size_t idx = 0; idx < _ncols; idx++ ) {
803  _cols[idx]->rewind( );
804 
805  }
806 
807  return true;
808 
809  }
810  }
811 
812  return false;
813 
814 }
815 
829 void
831  const bool on
832  ) {
833 
834  _autoidx = on;
835 
836 }
837 
842 bool
844  void
845  ) const {
846 
847  return _autoidx;
848 
849 }
850 
856 void
858  void
859  ) {
860 
861  for ( size_t idx = 0; idx < _ncols; idx++ ) {
862  _cols[idx]->advanceIdx( );
863 
864  }
865  _nrcol.advanceIdx( );
866 
867 }
868 
877 void
879  const string& name,
880  bool group
881  ) {
882 
883  _autoidx = true;
884 
885  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
886  if ( name == _cols[jdx]->getName( ) ) {
887  _cols[jdx]->setGroup( group );
888  return;
889 
890  }
891  }
892 
893 
894  if ( "_NR" != name ) {
895  throw( RDBErr( string("RDB::setGroup(string): error in file '" + _filename + "': Column ") + name + "(0) not found" ) );
896 
897  }
898 
899  _nrcol.setGroup( group );
900 }
901 
910 void
912  const int idx,
913  bool group
914  ) {
915 
916  _autoidx = true;
917 
918  if ( 0 <= idx && idx < (int)_ncols ) {
919  _cols[idx]->setGroup( group );
920 
921  } else {
922  stringstream ss;
923  ss << "RDB::setGroup(string): error with file '" + _filename + "': Column " << idx << " of " << _ncols << " not found";
924  throw( RDBErr( ss.str( ) ) );
925 
926  }
927 }
928 
937 bool
939  const string& name
940  ) {
941 
942  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
943  if ( name == _cols[jdx]->getName( ) ) {
944  return _cols[jdx]->getGroup( );
945 
946  }
947  }
948 
949  if ( "_NR" != name ) {
950  throw( RDBErr( string("RDB::getGroup(string): error with file '" + _filename + "': Column ") + name + "(0) not found" ) );
951 
952  }
953 
954  return _nrcol.getGroup( );
955 
956 }
957 
966 bool
968  const int idx
969  ) {
970 
971  if ( 0 > idx && idx >= _ncols ) {
972  stringstream ss;
973  ss << "RDB::getGroup(string): error with file '" + _filename + "': Column " << idx << " out of " << _ncols << " not found";
974  throw( RDBErr( ss.str( ) ) );
975 
976  }
977 
978  return _cols[idx]->getGroup( );
979 }
980 
988 bool
990  void
991  ) {
992 
993  for ( size_t idx = 0; idx < _ncols; idx++ ) {
994  if ( REOL ^ _cols[idx]->newGroup( ) ) {
995  return true;
996 
997  }
998  }
999 
1000  return false;
1001 
1002 }
1003 
1014 void
1016  const string& comm,
1017  const int idx
1018  ) {
1019 
1020  if ( 0 < idx && idx < (int) _ncomms ) {
1021  _comms[idx] = comm;
1022 
1023  } else {
1024  RDBComment* tmp = new RDBComment[_ncomms+1];
1025 
1026  if ( _comms ) {
1027  for ( size_t jdx = 0; jdx < _ncomms; jdx++ ) {
1028  tmp[jdx] = _comms[jdx];
1029 
1030  }
1031  delete [] _comms;
1032 
1033  }
1034 
1035  tmp[_ncomms++] = comm;
1036 
1037  _comms = tmp;
1038 
1039  }
1040 }
1041 
1052 void
1054  RDBComment& comm,
1055  const int idx
1056  ) {
1057 
1058  if ( 0 < idx && idx < (int) _ncomms ) {
1059  _comms[idx] = comm;
1060 
1061  } else {
1062  RDBComment* tmp = new RDBComment[_ncomms+1];
1063 
1064  if ( _comms ) {
1065  for ( size_t jdx = 0; jdx < _ncomms; jdx++ ) {
1066  tmp[jdx] = _comms[jdx];
1067 
1068  }
1069  delete [] _comms;
1070 
1071  }
1072 
1073  tmp[_ncomms++] = comm;
1074 
1075  _comms = tmp;
1076 
1077  }
1078 }
1079 
1089 void
1091  RDBComment& comm,
1092  const string& name,
1093  const size_t idx
1094  ) {
1095 
1096  for ( size_t jdx = 0; jdx < _ncomms; jdx++ ) {
1097  if ( name == _comms[jdx].getKeyword( ) ) {
1098  _comms[jdx] = comm;
1099  return;
1100 
1101  }
1102  }
1103 
1104  setComment( comm, -1 );
1105 
1106 }
1107 
1115 void
1117  const RDB& rdb
1118  ) {
1119 
1120  if ( rdb._ncomms > _ncomms ) {
1121  if ( _ncomms )
1122  delete [] _comms;
1123  _comms = new RDBComment[rdb._ncomms];
1124 
1125  }
1126 
1127  _ncomms = rdb._ncomms;
1128 
1129  for ( size_t idx = 0; idx < _ncomms; idx++ ) {
1130  _comms[idx] = rdb._comms[idx];
1131 
1132  }
1133 }
1134 
1147 RDBComment&
1149  const size_t idx
1150  ) {
1151 
1152  if ( 0 > idx && idx >= _ncomms ) {
1153  stringstream ss;
1154  ss << "RDB::getComment(size_t): error with file '" + _filename + "': Comment " << idx << "out of "<< _ncomms << " not found";
1155  throw( RDBErr( ss.str( ) ) );
1156 
1157  }
1158 
1159  return _comms[idx];
1160 
1161 }
1162 
1172 RDBComment&
1174  const string& name,
1175  const size_t idx
1176  ) {
1177 
1178  for ( size_t jdx = 0; jdx < _ncomms; jdx++ ) {
1179  if ( name == _comms[jdx].getKeyword( ) ) {
1180  return _comms[jdx];
1181 
1182  }
1183  }
1184 
1185  stringstream ss;
1186  ss << "RDB::getComment(string): error with file '" << _filename<< "': Comment " << name << "("<< idx << ") not found";
1187  throw( RDBErr( ss.str( ) ) );
1188 
1189 }
1190 
1207 void
1209  const string& name,
1210  const string& def,
1211  const int idx
1212  ) {
1213 
1214  if ( 0 <= idx && idx < (int)_ncols ) {
1215 
1216  if ( _mycols[idx] ) {
1217  delete _cols[idx];
1218 
1219  }
1220 
1221  _cols[idx]->setName( name );
1222  _cols[idx]->setDef( def );
1223  _mycols[idx] = true;
1224 
1225  } else {
1226  RDBColumn** tmp = new RDBColumn*[_ncols+2];
1227  bool* tmpmycols = new bool[_ncols+1];
1228  RDBColumn* col;
1229  int pos;
1230  if ( def.npos != (pos = def.find_first_not_of( "0123456789" )) && 'N' == def[pos] ) {
1231  col = new RDBDoubleColumn( name, def );
1232  } else {
1233  col = new RDBStringColumn( name, def );
1234  }
1235 
1236  if ( _cols ) {
1237  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
1238  tmp[jdx] = _cols[jdx];
1239  tmpmycols[jdx] = _mycols[jdx];
1240 
1241  }
1242 
1243  delete [] _cols;
1244  delete [] _mycols;
1245 
1246  }
1247 
1248  tmp[_ncols] = col;
1249  tmpmycols[_ncols++] = true;
1250 
1251  _cols = tmp;
1252  _mycols = tmpmycols;
1253 
1254  }
1255 }
1256 
1273 void
1275  RDBColumn* col,
1276  const int idx
1277  ) {
1278 
1279  if ( 0 <= idx && idx < (int)_ncols ) {
1280 
1281  if ( _mycols[idx] ) {
1282  delete _cols[idx];
1283 
1284  }
1285 
1286  _cols[idx] = col;
1287  _mycols[idx] = false;
1288 
1289  } else {
1290  RDBColumn** tmp = new RDBColumn*[_ncols+2];
1291  bool* tmpmycols = new bool[_ncols+1];
1292 
1293  if ( _cols ) {
1294  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
1295  tmp[jdx] = _cols[jdx];
1296  tmpmycols[jdx] = _mycols[jdx];
1297 
1298  }
1299 
1300  delete [] _cols;
1301  delete [] _mycols;
1302 
1303  }
1304 
1305  tmp[_ncols] = col;
1306  tmpmycols[_ncols++] = false;
1307 
1308  _cols = tmp;
1309  _mycols = tmpmycols;
1310 
1311  }
1312 }
1313 
1330 void
1332  RDBColumn* col,
1333  const string& name,
1334  const size_t idx
1335  ) {
1336 
1337  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
1338  if ( name == _cols[jdx]->getName( ) ) {
1339  if ( _mycols[jdx] ) {
1340  delete _cols[jdx];
1341 
1342  }
1343 
1344  _cols[jdx] = col;
1345  _mycols[jdx] = false;
1346  return;
1347 
1348  }
1349  }
1350 
1351  col->setName( name );
1352  setColumn( col, -1 );
1353 
1354 }
1355 
1367 void
1369  const RDB& rdb
1370  ) {
1371 
1372  size_t idx = 0;
1373  if ( rdb._ncols > _ncols ) {
1374  RDBColumn** tmp = new RDBColumn*[rdb._ncols+1];
1375  bool* tmpmycols = new bool[rdb._ncols];
1376 
1377  if ( _cols ) {
1378  for ( idx = 0; idx < _ncols; idx++ ) {
1379  tmp[idx] = rdb._cols[idx];
1380  tmpmycols[idx] = false;
1381 
1382  if ( _mycols[idx] ) {
1383  delete _cols[idx];
1384 
1385  }
1386  }
1387 
1388  if ( _ncols ) {
1389  delete [] _cols;
1390  delete [] _mycols;
1391 
1392  }
1393  }
1394 
1395  for ( ; idx < rdb._ncols; idx++ ) {
1396  tmp[idx] = rdb._cols[idx];
1397  tmpmycols[idx] = false;
1398 
1399  }
1400  _cols = tmp;
1401  _mycols = tmpmycols;
1402 
1403  } else {
1404  for ( idx = 0; idx < rdb._ncols; idx++ ) {
1405  _cols[idx] = rdb._cols[idx];
1406  _mycols[idx] = false;
1407 
1408  }
1409 
1410  for ( ; idx < _ncols; idx++ ) {
1411  delete _cols[idx];
1412 
1413  }
1414  }
1415 
1416  _ncols = rdb._ncols;
1417 
1418 }
1419 
1432 RDBColumn*
1434  const size_t idx
1435  ) {
1436 
1437  if ( 0 > idx && idx >= _ncols ) {
1438  stringstream ss;
1439  ss << "RDB::getColumn(size_t): error with file '" << _filename << "': Column " << idx << " out of "<< _ncols << " not found";
1440  throw( RDBErr( ss.str( ) ) );
1441 
1442  }
1443 
1444  return _cols[idx];
1445 
1446 }
1447 
1457 RDBColumn*
1459  const string& name,
1460  const size_t idx
1461  ) {
1462 
1463  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
1464  if ( name == _cols[jdx]->getName( ) ) {
1465  return _cols[jdx];
1466 
1467  }
1468  }
1469 
1470  if ( "_NR" != name ) {
1471  stringstream ss;
1472  ss << "RDB::getColumn(string): error with file '" << _filename << "': Column " << name << "("<< idx << ") not found";
1473  throw( RDBErr( ss.str( ) ) );
1474 
1475  }
1476 
1477  return &_nrcol;
1478 
1479 }
1480 
1488 void RDB::setName( const size_t idx, const string& name ) {
1489 
1490  if ( idx >= (int)_ncols ) {
1491  stringstream ss;
1492  ss << "RDB::setName: error with file '" << _filename << "': index out of range [0," << idx << ")";
1493  throw( RDBErr( ss.str( ) ) );
1494 
1495  }
1496 
1497  _cols[idx]->setName( name );
1498 
1499 }
1500 
1509 void RDB::setDef( const size_t idx, const string& def ) {
1510 
1511  if ( idx > (int)_ncols ) {
1512  stringstream ss;
1513  ss << "RDB::setDef: error with file '" << _filename << "': index out of range [0," << idx << ")";
1514  throw( RDBErr( ss.str( ) ) );
1515  }
1516 
1517  try {
1518  _cols[idx]->setDef( def );
1519 
1520  } catch ( RDBErr& e ) {
1521  e.set_message( "RDB::setDef: error with file '" + _filename + "': " );
1522  throw( e );
1523 
1524  } catch ( ... ) {
1525  throw( RDBErr( "RDB::setDef: unexpected exception caught with file '" + _filename +"'" ) );
1526  }
1527 }
1528 
1537 void RDB::setWidth( const size_t idx, const long width ) {
1538 
1539  if ( idx > (int)_ncols ) {
1540  stringstream ss;
1541  ss << "RDB::setWidth: error with file '" << _filename << "': index out of range [0," << idx << ")";
1542  throw( RDBErr( ss.str( ) ) );
1543  }
1544 
1545  try {
1546  _cols[idx]->setWidth( width );
1547 
1548  } catch ( RDBErr& e ) {
1549  e.set_message( "RDB::setWidth: error with file '" + _filename + "': " );
1550  throw( e );
1551 
1552  } catch ( ... ) {
1553  throw( RDBErr( "RDB::setWidth: unexpected exception caught with file '" + _filename + "'" ) );
1554  }
1555 }
1556 
1565 void RDB::setType( const size_t idx, const RDBColumn::Type type ) {
1566 
1567  if ( idx > (int)_ncols ) {
1568  stringstream ss;
1569  ss << "RDB::setType: error with file '" << _filename << "': index out of range [0," << idx << ")";
1570  throw( RDBErr( ss.str( ) ) );
1571  }
1572 
1573  try {
1574  _cols[idx]->setType( type );
1575 
1576  } catch ( RDBErr& e ) {
1577  e.set_message( "RDB::setType: error with file '" + _filename + "': " );
1578  throw( e );
1579 
1580  } catch ( ... ) {
1581  throw( RDBErr( "RDB::setType: unexpected exception caught with file '" + _filename + "'" ) );
1582  }
1583 }
1584 
1593 void RDB::setJust( const size_t idx, const RDBColumn::Just just ) {
1594 
1595  if ( idx > (int)_ncols ) {
1596  stringstream ss;
1597  ss << "RDB::setJust: error with file '" << _filename << "': index out of range [0," << idx << ")";
1598  throw( RDBErr( ss.str( ) ) );
1599  }
1600 
1601  try {
1602  _cols[idx]->setJust( just );
1603 
1604  } catch ( RDBErr& e ) {
1605  e.set_message( "RDB::setJust: error with file '" + _filename + "': " );
1606  throw( e );
1607 
1608  } catch ( ... ) {
1609  throw( RDBErr( "RDB::setJust: unexpected exception caught with file '" + _filename + "'" ) );
1610  }
1611 }
1612 
1621 void RDB::setDesc( const size_t idx, const string& desc ) {
1622 
1623  if ( idx > (int)_ncols ) {
1624  stringstream ss;
1625  ss << "RDB::setDesc: error with file '" << _filename << "': index out of range [0," << idx << ")";
1626  throw( RDBErr( ss.str( ) ) );
1627  }
1628 
1629  try {
1630  _cols[idx]->setDesc( desc );
1631 
1632  } catch ( RDBErr& e ) {
1633  e.set_message( "RDB::setDesc: error with file '" + _filename + "': " );
1634  throw( e );
1635 
1636  } catch ( ... ) {
1637  throw( RDBErr( "RDB::setDesc: unexpected exception caught with file '" + _filename + "'" ) );
1638  }
1639 }
1640 
1650 void RDB::mapData( const size_t idx, double data[], const size_t nelems ) {
1651  if ( idx > (int)_ncols ) {
1652  stringstream ss;
1653  ss << "RDB::mapData: error with file '" << _filename << "': index out of range [0," << idx << ")";
1654  throw( RDBErr( ss.str( ) ) );
1655  }
1656 
1657  try {
1658  _cols[idx]->mapData( data, nelems );
1659 
1660  } catch ( RDBErr& e ) {
1661  e.set_message( "RDB::mapData: error with file '" + _filename + "': " );
1662  throw( e );
1663 
1664  } catch ( ... ) {
1665  throw( RDBErr( "RDB::mapData: unexpected exception caught with file '" + _filename + "'" ) );
1666  }
1667 }
1668 
1678 void RDB::mapData( const size_t idx, long data[], const size_t nelems ) {
1679 
1680  if ( idx > (int)_ncols ) {
1681  stringstream ss;
1682  ss << "RDB::mapData: error with file '" << _filename << "': index out of range [0," << idx << ")";
1683  throw( RDBErr( ss.str( ) ) );
1684  }
1685 
1686  try {
1687  _cols[idx]->mapData( data, nelems );
1688 
1689  } catch ( RDBErr& e ) {
1690  e.set_message( "RDB::mapData: error with file '" + _filename + "': " );
1691  throw( e );
1692 
1693  } catch ( ... ) {
1694  throw( RDBErr( "RDB::mapData: unexpected exception caught with file '" + _filename + "'" ) );
1695  }
1696 }
1697 
1707 void RDB::mapData( const size_t idx, string data[], const size_t nelems ) {
1708 
1709  if ( idx > (int)_ncols ) {
1710  stringstream ss;
1711  ss << "RDB::mapData: error with file '" << _filename << "': index out of range [0," << idx << ")";
1712  throw( RDBErr( ss.str( ) ) );
1713  }
1714 
1715  try {
1716  _cols[idx]->mapData( data, nelems );
1717 
1718  } catch ( RDBErr& e ) {
1719  e.set_message( "RDB::mapData: error with file '" + _filename + "': " );
1720  throw( e );
1721 
1722  } catch ( ... ) {
1723  throw( RDBErr( "RDB::mapData: unexpected exception caught with file '" + _filename + "'" ) );
1724  }
1725 }
1726 
1735 void RDB::setData( const size_t idx, const double data ) {
1736 
1737  if ( idx > (int)_ncols ) {
1738  stringstream ss;
1739  ss << "RDB::setData: error with file '" << _filename << "': index out of range [0," << idx << ")";
1740  throw( RDBErr( ss.str( ) ) );
1741  }
1742 
1743  try {
1744  _cols[idx]->setData( data );
1745 
1746  } catch ( RDBErr& e ) {
1747  e.set_message( "RDB::setData: error with file '" + _filename + "': " );
1748  throw( e );
1749 
1750  } catch ( ... ) {
1751  throw( RDBErr( "RDB::setData: unexpected exception caught with file '" + _filename + "'" ) );
1752  }
1753 }
1754 
1763 void RDB::setData( const size_t idx, const long data ) {
1764 
1765  if ( idx > (int)_ncols ) {
1766  stringstream ss;
1767  ss << "RDB::setData: error with file '" << _filename << "': index out of range [0," << idx << ")";
1768  throw( RDBErr( ss.str( ) ) );
1769  }
1770 
1771  try {
1772  _cols[idx]->setData( data );
1773 
1774  } catch ( RDBErr& e ) {
1775  e.set_message( "RDB::setData: error with file '" + _filename + "': " );
1776  throw( e );
1777 
1778  } catch ( ... ) {
1779  throw( RDBErr( "RDB::setData: unexpected exception caught with file '" + _filename + "'" ) );
1780  }
1781 }
1782 
1791 void RDB::setData( const size_t idx, const string& data ) {
1792 
1793  if ( idx > (int)_ncols ) {
1794  stringstream ss;
1795  ss << "RDB::setData: error with file '" << _filename << "': index out of range [0," << idx << ")";
1796  throw( RDBErr( ss.str( ) ) );
1797  }
1798 
1799  try {
1800  _cols[idx]->setData( data );
1801 
1802  } catch ( RDBErr& e ) {
1803  e.set_message( "RDB::setData: error with file '" + _filename + "': " );
1804  throw( e );
1805 
1806  } catch ( ... ) {
1807  throw( RDBErr( "RDB::setData: unexpected exception caught with file '" + _filename + "'" ) );
1808  }
1809 }
1810 
1818 void RDB::getName( const size_t idx, string& name ) const {
1819 
1820  if ( idx > (int)_ncols ) {
1821  stringstream ss;
1822  ss << "RDB::getName: error with file '" << _filename << "': index out of range [0," << idx << ")";
1823  throw( RDBErr( ss.str( ) ) );
1824  }
1825 
1826  name = _cols[idx]->getName( );
1827 
1828 }
1829 
1837 void RDB::getDef( const size_t idx, string& def ) {
1838 
1839  if ( idx > (int)_ncols ) {
1840  stringstream ss;
1841  ss << "RDB::getDef: error with file '" << _filename << "': index out of range [0," << idx << ")";
1842  throw( RDBErr( ss.str( ) ) );
1843  }
1844 
1845  def = _cols[idx]->getDef( );
1846 
1847 }
1848 
1856 void RDB::getWidth( const size_t idx, long& width ) const {
1857 
1858  if ( idx > (int)_ncols ) {
1859  stringstream ss;
1860  ss << "RDB::getWidth: error with file '" << _filename << "': index out of range [0," << idx << ")";
1861  throw( RDBErr( ss.str( ) ) );
1862  }
1863 
1864  width = _cols[idx]->getWidth( );
1865 
1866 }
1867 
1875 void RDB::getType( const size_t idx, RDBColumn::Type& type ) const {
1876 
1877  if ( idx > (int)_ncols ) {
1878  stringstream ss;
1879  ss << "RDB::getType: error with file '" << _filename << "': index out of range [0," << idx << ")";
1880  throw( RDBErr( ss.str( ) ) );
1881  }
1882 
1883  type = _cols[idx]->getType( );
1884 
1885 }
1886 
1894 void RDB::getJust( const size_t idx, RDBColumn::Just& just ) const {
1895 
1896  if ( idx > (int)_ncols ) {
1897  stringstream ss;
1898  ss << "RDB::getJust: error with file '" << _filename << "': index out of range [0," << idx << ")";
1899  throw( RDBErr( ss.str( ) ) );
1900  }
1901 
1902  just = _cols[idx]->getJust( );
1903 
1904 }
1905 
1913 void RDB::getDesc( const size_t idx, string& desc ) const {
1914 
1915  if ( idx > (int)_ncols ) {
1916  stringstream ss;
1917  ss << "RDB::getDesc: error with file '" << _filename << "': index out of range [0," << idx << ")";
1918  throw( RDBErr( ss.str( ) ) );
1919  }
1920 
1921  desc = _cols[idx]->getDesc( );
1922 
1923 }
1924 
1933 void RDB::getData( const size_t idx, double& data ) {
1934 
1935  if ( idx > (int)_ncols ) {
1936  stringstream ss;
1937  ss << "RDB::getData: error with file '" << _filename << "': index out of range [0," << idx << ")";
1938  throw( RDBErr( ss.str( ) ) );
1939  }
1940 
1941  try {
1942  data = _cols[idx]->getDataDouble( );
1943 
1944  } catch ( RDBErr& e ) {
1945  e.set_message( "RDB::getData: error with file '" + _filename + "': " );
1946  throw( e );
1947 
1948  } catch ( ... ) {
1949  throw( RDBErr( "RDB::getData: unexpected exception caught with file '" + _filename + "'" ) );
1950  }
1951 }
1952 
1961 void RDB::getData( const size_t idx, long& data ) {
1962 
1963  if ( idx > (int)_ncols ) {
1964  stringstream ss;
1965  ss << "RDB::getData: error with file '" << _filename << "': index out of range [0," << idx << ")";
1966  throw( RDBErr( ss.str( ) ) );
1967  }
1968 
1969  try {
1970  data = _cols[idx]->getDataLong( );
1971 
1972  } catch ( RDBErr& e ) {
1973  e.set_message( "RDB::getData: error with file '" + _filename + "': " );
1974  throw( e );
1975 
1976  } catch ( ... ) {
1977  throw( RDBErr( "RDB::getData: unexpected exception caught with file '" + _filename + "'" ) );
1978  }
1979 }
1980 
1989 void RDB::getData( const size_t idx, string& data ) {
1990 
1991  if ( idx > (int)_ncols ) {
1992  stringstream ss;
1993  ss << "RDB::getData: error with file '" << _filename << "': index out of range [0," << idx << ")";
1994  throw( RDBErr( ss.str( ) ) );
1995  }
1996 
1997  try {
1998  data = _cols[idx]->getDataString( );
1999 
2000  } catch ( RDBErr& e ) {
2001  e.set_message( "RDB::getData: error with file '" + _filename + "': " );
2002  throw( e );
2003 
2004  } catch ( ... ) {
2005  throw( RDBErr( "RDB::getData: unexpected exception caught with file '" + _filename + "': " ) );
2006  }
2007 }
2008 
2017 string RDB::getName( const size_t idx ) const {
2018 
2019  if ( idx > (int)_ncols ) {
2020  stringstream ss;
2021  ss << "RDB::getName: error with file '" << _filename << "': index out of range [0," << idx << ")";
2022  throw( RDBErr( ss.str( ) ) );
2023  }
2024 
2025  return _cols[idx]->getName( );
2026 
2027 }
2028 
2037 string RDB::getDef( const size_t idx ) {
2038 
2039  if ( idx > (int)_ncols ) {
2040  stringstream ss;
2041  ss << "RDB::getDef: error with file '" << _filename << "': index out of range [0," << idx << ")";
2042  throw( RDBErr( ss.str( ) ) );
2043  }
2044 
2045  return _cols[idx]->getDef( );
2046 
2047 }
2048 
2057 long RDB::getWidth( const size_t idx ) const {
2058 
2059  if ( idx > (int)_ncols ) {
2060  stringstream ss;
2061  ss << "RDB::getWidth: error with file '" << _filename << "': index out of range [0," << idx << ")";
2062  throw( RDBErr( ss.str( ) ) );
2063  }
2064 
2065  return _cols[idx]->getWidth( );
2066 
2067 }
2068 
2077 RDBColumn::Type RDB::getType( const size_t idx ) const {
2078 
2079  if ( idx > (int)_ncols ) {
2080  stringstream ss;
2081  ss << "RDB::getType: error with file '" << _filename << "': index out of range [0," << idx << ")";
2082  throw( RDBErr( ss.str( ) ) );
2083  }
2084 
2085  return _cols[idx]->getType( );
2086 
2087 }
2088 
2097 RDBColumn::Just RDB::getJust( const size_t idx ) const {
2098 
2099  if ( idx > (int)_ncols ) {
2100  stringstream ss;
2101  ss << "RDB::getJust: error with file '" << _filename << "': index out of range [0," << idx << ")";
2102  throw( RDBErr( ss.str( ) ) );
2103  }
2104 
2105  return _cols[idx]->getJust( );
2106 
2107 }
2108 
2117 string RDB::getDesc( const size_t idx ) const {
2118 
2119  if ( idx > (int)_ncols ) {
2120  stringstream ss;
2121  ss << "RDB::getDesc: error with file '" << _filename << "': index out of range [0," << idx << ")";
2122  throw( RDBErr( ss.str( ) ) );
2123  }
2124 
2125  return _cols[idx]->getDesc( );
2126 
2127 }
2128 
2138 double RDB::getDataDouble( const size_t idx ) {
2139 
2140  if ( idx > (int)_ncols ) {
2141  stringstream ss;
2142  ss << "RDB::getDataDouble: error with file '" << _filename << "': index out of range [0," << idx << ")";
2143  throw( RDBErr( ss.str( ) ) );
2144  }
2145 
2146  try {
2147  return _cols[idx]->getDataDouble( );
2148 
2149  } catch ( RDBErr& e ) {
2150  e.set_message( "RDB::getDataDouble: error with file '" + _filename + "': " );
2151  throw( e );
2152 
2153  } catch ( ... ) {
2154  throw( RDBErr( "RDB::getDataDouble: unexpected exception caught with file '" + _filename + "':" ) );
2155  }
2156 }
2157 
2167 long RDB::getDataLong( const size_t idx ) {
2168 
2169  if ( idx > (int)_ncols ) {
2170  stringstream ss;
2171  ss << "RDB::getDataLong: error with file '" << _filename << "': index out of range [0," << idx << ")";
2172  throw( RDBErr( ss.str( ) ) );
2173  }
2174 
2175  try {
2176  return _cols[idx]->getDataLong( );
2177 
2178  } catch ( RDBErr& e ) {
2179  e.set_message( "RDB::getDataLong: error with file '" + _filename + "': " );
2180  throw( e );
2181 
2182  } catch ( ... ) {
2183  throw( RDBErr( "RDB::getDataLong: unexpected exception caught with file '" + _filename + "':" ) );
2184  }
2185 }
2186 
2196 string RDB::getDataString( const size_t idx ) {
2197 
2198  if ( idx > (int)_ncols ) {
2199  stringstream ss;
2200  ss << "RDB::getDataString: error with file '" << _filename << "': index out of range [0," << idx << ")";
2201  throw( RDBErr( ss.str( ) ) );
2202  }
2203 
2204  try {
2205  return _cols[idx]->getDataString( );
2206 
2207  } catch ( RDBErr& e ) {
2208  e.set_message( "RDB::getDataString: error with file '" + _filename + "': " );
2209  throw( e );
2210 
2211  } catch ( ... ) {
2212  throw( RDBErr( "RDB::getDataString: unexpected exception caught with file '" + _filename + "':" ) );
2213  }
2214 }
2215 
2224 void RDB::setName( const string& name, const string& newname ) {
2225 
2226  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2227  if ( name == _cols[jdx]->getName( ) ) {
2228  _cols[jdx]->setName( newname );
2229  return;
2230 
2231  }
2232  }
2233 
2234  if ( "_NR" != name ) {
2235  throw ( RDBErr( string("RDB::setName(string&,string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
2236  }
2237 
2238  _nrcol.setName( newname );
2239 
2240 }
2241 
2250 void RDB::setDef( const string& name, const string& def ) {
2251 
2252  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2253  if ( name == _cols[jdx]->getName( ) ) {
2254  try {
2255  _cols[jdx]->setDef( def );
2256 
2257  } catch ( RDBErr& e ) {
2258  e.set_message( "RDB::setDef: error with file '" + _filename + "': " );
2259  throw( e );
2260 
2261  } catch ( ... ) {
2262  throw( RDBErr( "RDB::setDef: unexpected exception caught with file '" + _filename + "':" ) );
2263  }
2264 
2265  return;
2266 
2267  }
2268  }
2269 
2270  if ( "_NR" != name ) {
2271  throw ( RDBErr( string("RDB::setDef(string&,string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
2272  }
2273 
2274  _nrcol.setDef( def );
2275 }
2276 
2285 void RDB::setWidth( const string& name, const long width ) {
2286 
2287  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2288  if ( name == _cols[jdx]->getName( ) ) {
2289  try {
2290  _cols[jdx]->setWidth( width );
2291 
2292  } catch ( RDBErr& e ) {
2293  e.set_message( "RDB::setWidth: error with file '" + _filename + "': " );
2294  throw( e );
2295 
2296  } catch ( ... ) {
2297  throw( RDBErr( "RDB::setWidth: unexpected exception caught with file '" + _filename + "':" ) );
2298  }
2299 
2300  return;
2301 
2302  }
2303  }
2304 
2305  if ( "_NR" != name ) {
2306  throw ( RDBErr( string("RDB::setWidth(string&,long): error with file '" + _filename + "': Column ") + name + " not found" ) );
2307  }
2308 
2309  _nrcol.setWidth( width );
2310 }
2311 
2320 void RDB::setType( const string& name, const RDBColumn::Type type ) {
2321 
2322  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2323  if ( name == _cols[jdx]->getName( ) ) {
2324  try {
2325  _cols[jdx]->setType( type );
2326 
2327  } catch ( RDBErr& e ) {
2328  e.set_message( "RDB::setType: error with file '" + _filename + "': " );
2329  throw( e );
2330 
2331  } catch ( ... ) {
2332  throw( RDBErr( "RDB::setType: error with file '" + _filename + "': unexpected exception caught" ) );
2333  }
2334 
2335  return;
2336 
2337  }
2338  }
2339 
2340  if ( "_NR" != name ) {
2341  throw ( RDBErr( string("RDB::setType(string&,RDBColumn::Type): error with file '" + _filename + "': Column ") + name + " not found" ) );
2342  }
2343 
2344  _nrcol.setType( type );
2345 }
2346 
2355 void RDB::setJust( const string& name, const RDBColumn::Just just ) {
2356 
2357  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2358  if ( name == _cols[jdx]->getName( ) ) {
2359  try {
2360  _cols[jdx]->setJust( just );
2361 
2362  } catch ( RDBErr& e ) {
2363  e.set_message( "RDB::setJust: error with file '" + _filename + "': " );
2364  throw( e );
2365 
2366  } catch ( ... ) {
2367  throw( RDBErr( "RDB::setJust: error with file '" + _filename + "': unexpected exception caught" ) );
2368  }
2369 
2370  return;
2371 
2372  }
2373  }
2374 
2375  if ( "_NR" != name ) {
2376  throw ( RDBErr( string("RDB::setJust(string&,RDBColumn::Just): error with file '" + _filename + "': Column ") + name + " not found" ) );
2377  }
2378 
2379  _nrcol.setJust( just );
2380 }
2381 
2390 void RDB::setDesc( const string& name, const string& desc ) {
2391 
2392  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2393  if ( name == _cols[jdx]->getName( ) ) {
2394  try {
2395  _cols[jdx]->setDesc( desc );
2396 
2397  } catch ( RDBErr& e ) {
2398  e.set_message( "RDB::setDesc: error with file '" + _filename + "': " );
2399  throw( e );
2400 
2401  } catch ( ... ) {
2402  throw( RDBErr( "RDB::setDesc: error with file '" + _filename + "': unexpected exception caught" ) );
2403  }
2404 
2405  return;
2406 
2407  }
2408  }
2409 
2410  if ( "_NR" != name ) {
2411  throw ( RDBErr( string("RDB::setDesc(string&,string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
2412  }
2413 
2414  _nrcol.setDesc( desc );
2415 }
2416 
2426 void RDB::mapData( const string& name, double data[], const size_t nelems ) {
2427 
2428  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2429  if ( name == _cols[jdx]->getName( ) ) {
2430  try {
2431  _cols[jdx]->mapData( data, nelems );
2432 
2433  } catch ( RDBErr& e ) {
2434  e.set_message( "RDB::mapData: error with file '" + _filename + "': " );
2435  throw( e );
2436 
2437  } catch ( ... ) {
2438  throw( RDBErr( "RDB::mapData: error with file '" + _filename + "': unexpected exception caught" ) );
2439  }
2440 
2441  return;
2442 
2443  }
2444  }
2445 
2446  if ( "_NR" != name ) {
2447  throw ( RDBErr( string("RDB::mapData(string&,double[],size_t): error with file '" + _filename + "': Column ") + name + " not found" ) );
2448  } else {
2449  throw( RDBErr( "RDB::mapData('_NR',double[],size_t): error with file '" + _filename + "': mapping double[] to '_NR' column not allowed" ) );
2450  }
2451 }
2452 
2462 void RDB::mapData( const string& name, long data[], const size_t nelems ) {
2463 
2464  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2465  if ( name == _cols[jdx]->getName( ) ) {
2466  try {
2467  _cols[jdx]->mapData( data, nelems );
2468 
2469  } catch ( RDBErr& e ) {
2470  e.set_message( "RDB::mapData: error with file '" + _filename + "': " );
2471  throw( e );
2472 
2473  } catch ( ... ) {
2474  throw( RDBErr( "RDB::mapData: unexpected exception caught with file '" + _filename + "':" ) );
2475 
2476  }
2477 
2478  return;
2479 
2480  }
2481  }
2482 
2483  if ( "_NR" != name ) {
2484  throw ( RDBErr( string("RDB::mapData(string&,long[],size_t): error with file '" + _filename + "': Column ") + name + " not found" ) );
2485  }
2486 
2487  _nrcol.mapData( data, nelems );
2488 }
2489 
2499 void RDB::mapData( const string& name, string data[], const size_t nelems ) {
2500 
2501  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2502  if ( name == _cols[jdx]->getName( ) ) {
2503  try {
2504  _cols[jdx]->mapData( data, nelems );
2505 
2506  } catch ( RDBErr& e ) {
2507  e.set_message( "RDB::mapData: error with file '" + _filename + "': " );
2508  throw( e );
2509 
2510  } catch ( ... ) {
2511  throw( RDBErr( "RDB::mapData: unexpected exception caught with file '" + _filename + "':" ) );
2512  }
2513 
2514  return;
2515 
2516  }
2517  }
2518 
2519  if ( "_NR" != name ) {
2520  throw ( RDBErr( string("RDB::mapData(string&,string[],size_t): error with file '" + _filename + "': Column ") + name + " not found" ) );
2521  } else {
2522  throw( RDBErr( "RDB::mapData('_NR',string[],size_t): error with file '" + _filename + "': mapping string[] to '_NR' column not allowed" ) );
2523  }
2524 }
2525 
2534 void RDB::setData( const string& name, const double data ) {
2535 
2536  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2537  if ( name == _cols[jdx]->getName( ) ) {
2538  try {
2539  _cols[jdx]->setData( data );
2540 
2541  } catch ( RDBErr& e ) {
2542  e.set_message( "RDB::setData: error with file '" + _filename + "': " );
2543  throw( e );
2544 
2545  } catch ( ... ) {
2546  throw( RDBErr( "RDB::setData: unexpected exception caught with file '" + _filename + "':" ) );
2547  }
2548  return;
2549  }
2550  }
2551 
2552  if ( "_NR" != name ) {
2553  throw ( RDBErr( string("RDB::setData(string&,double): error with file '" + _filename + "': Column ") + name + " not found" ) );
2554  }
2555 
2556  _nrcol.setData( data );
2557 }
2558 
2567 void RDB::setData( const string& name, const long data ) {
2568 
2569  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2570  if ( name == _cols[jdx]->getName( ) ) {
2571  try {
2572  _cols[jdx]->setData( data );
2573 
2574  } catch ( RDBErr& e ) {
2575  e.set_message( "RDB::setData: error with file '" + _filename + "': " );
2576  throw( e );
2577 
2578  } catch ( ... ) {
2579  throw( RDBErr( "RDB::setData: unexpected exception caught with file '" + _filename + "':" ) );
2580  }
2581  return;
2582  }
2583  }
2584 
2585  if ( "_NR" != name ) {
2586  throw ( RDBErr( string("RDB::setData(string&,long): error with file '" + _filename + "': Column ") + name + " not found" ) );
2587  }
2588 
2589  _nrcol.setData( data );
2590 }
2591 
2600 void RDB::setData( const string& name, const string& data ) {
2601 
2602  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2603  if ( name == _cols[jdx]->getName( ) ) {
2604  try {
2605  _cols[jdx]->setData( data );
2606 
2607  } catch ( RDBErr& e ) {
2608  e.set_message( "RDB::setData: error with file '" + _filename + "': " );
2609  throw( e );
2610 
2611  } catch ( ... ) {
2612  throw( RDBErr( "RDB::setData: unexpected exception caught with file '" + _filename + "':" ) );
2613  }
2614  return;
2615 
2616  }
2617  }
2618 
2619  if ( "_NR" != name ) {
2620  throw ( RDBErr( string("RDB::setData(string&,string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
2621  }
2622 
2623  _nrcol.setData( data );
2624 }
2625 
2633 void RDB::getName( const string& name, string& namefound ) const {
2634 
2635  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2636  if ( name == _cols[jdx]->getName( ) ) {
2637  namefound = _cols[jdx]->getName( );
2638  return;
2639 
2640  }
2641  }
2642 
2643  if ( "_NR" != name ) {
2644  throw ( RDBErr( string("RDB::getName(string&,string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
2645  }
2646 
2647  namefound = _nrcol.getName( );
2648 }
2649 
2657 void RDB::getDef( const string& name, string& def ) {
2658 
2659  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2660  if ( name == _cols[jdx]->getName( ) ) {
2661  def = _cols[jdx]->getDef( );
2662  return;
2663 
2664  }
2665  }
2666 
2667  if ( "_NR" != name ) {
2668  throw ( RDBErr( string("RDB::getDef(string&,string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
2669  }
2670 
2671  def = _nrcol.getDef( );
2672 }
2673 
2681 void RDB::getWidth( const string& name, long& width ) const {
2682 
2683  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2684  if ( name == _cols[jdx]->getName( ) ) {
2685  width = _cols[jdx]->getWidth( );
2686  return;
2687 
2688  }
2689  }
2690 
2691  if ( "_NR" != name ) {
2692  throw ( RDBErr( string("RDB::getWidth(string&,long): error with file '" + _filename + "': Column ") + name + " not found" ) );
2693  }
2694 
2695  width = _nrcol.getWidth( );
2696 }
2697 
2705 void RDB::getType( const string& name, RDBColumn::Type& type ) const {
2706 
2707  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2708  if ( name == _cols[jdx]->getName( ) ) {
2709  type = _cols[jdx]->getType( );
2710  return;
2711 
2712  }
2713  }
2714 
2715  if ( "_NR" != name ) {
2716  throw ( RDBErr( string("RDB::getType(string&,RDBColumn::Type): error with file '" + _filename + "': Column ") + name + " not found" ) );
2717  }
2718 
2719  type = _nrcol.getType( );
2720 }
2721 
2729 void RDB::getJust( const string& name, RDBColumn::Just& just ) const {
2730 
2731  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2732  if ( name == _cols[jdx]->getName( ) ) {
2733  just = _cols[jdx]->getJust( );
2734  return;
2735 
2736  }
2737  }
2738 
2739  if ( "_NR" != name ) {
2740  throw ( RDBErr( string("RDB::getJust(string&,RDBColumn::Just): error with file '" + _filename + "': Column ") + name + " not found" ) );
2741  }
2742 
2743  just = _nrcol.getJust( );
2744 }
2745 
2753 void RDB::getDesc( const string& name, string& desc ) const {
2754 
2755  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2756  if ( name == _cols[jdx]->getName( ) ) {
2757  desc = _cols[jdx]->getDesc( );
2758  return;
2759 
2760  }
2761  }
2762 
2763  if ( "_NR" != name ) {
2764  throw ( RDBErr( string("RDB::getDesc(string&,string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
2765  }
2766 
2767  desc = _nrcol.getDesc( );
2768 }
2769 
2778 void RDB::getData( const string& name, double& data ) {
2779 
2780  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2781  if ( name == _cols[jdx]->getName( ) ) {
2782  try {
2783  data = _cols[jdx]->getDataDouble( );
2784 
2785  } catch ( RDBErr& e ) {
2786  e.set_message( "RDB::getData: error with file '" + _filename + "': " );
2787  throw( e );
2788 
2789  } catch ( ... ) {
2790  throw( RDBErr( "RDB::getData: unexpected exception caught with file '" + _filename + "':" ) );
2791  }
2792  return;
2793 
2794  }
2795  }
2796 
2797  if ( "_NR" != name ) {
2798  throw ( RDBErr( string("RDB::getData(string&,double): error with file '" + _filename + "': Column ") + name + " not found" ) );
2799  }
2800 
2801  data = _nrcol.getDataDouble( );
2802 }
2803 
2812 void RDB::getData( const string& name, long& data ) {
2813 
2814  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2815  if ( name == _cols[jdx]->getName( ) ) {
2816  try {
2817  data = _cols[jdx]->getDataLong( );
2818 
2819  } catch ( RDBErr& e ) {
2820  e.set_message( "RDB::getData: error with file '" + _filename + "': " );
2821  throw( e );
2822 
2823  } catch ( ... ) {
2824  throw( RDBErr( "RDB::getData: unexpected exception caught with file '" + _filename + "':" ) );
2825  }
2826  return;
2827 
2828  }
2829  }
2830 
2831  if ( "_NR" != name ) {
2832  throw ( RDBErr( string("RDB::getData(string&,long&): error with file '" + _filename + "': Column ") + name + " not found" ) );
2833  }
2834 
2835  data = _nrcol.getDataLong( );
2836 }
2837 
2846 void RDB::getData( const string& name, string& data ) {
2847 
2848  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2849  if ( name == _cols[jdx]->getName( ) ) {
2850  try {
2851  data = _cols[jdx]->getDataString( );
2852 
2853  } catch ( RDBErr& e ) {
2854  e.set_message( "RDB::getData: error with file '" + _filename + "': " );
2855  throw( e );
2856 
2857  } catch ( ... ) {
2858  throw( RDBErr( "RDB::getData: unexpected exception caught with file '" + _filename + "':" ) );
2859  }
2860  return;
2861 
2862  }
2863  }
2864 
2865  if ( "_NR" != name ) {
2866  throw ( RDBErr( string("RDB::getData(string&,string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
2867  }
2868 
2869  data = _nrcol.getDataString( );
2870 }
2871 
2880 string RDB::getName( const string& name ) const {
2881 
2882  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2883  if ( name == _cols[jdx]->getName( ) ) {
2884  return _cols[jdx]->getName( );
2885 
2886  }
2887  }
2888 
2889  if ( "_NR" != name ) {
2890  throw ( RDBErr( string("RDB::getName(string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
2891  }
2892 
2893  return _nrcol.getName( );
2894 }
2895 
2904 string RDB::getDef( const string& name ) {
2905 
2906  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2907  if ( name == _cols[jdx]->getName( ) ) {
2908  return _cols[jdx]->getDef( );
2909 
2910  }
2911  }
2912 
2913  if ( "_NR" != name ) {
2914  throw ( RDBErr( string("RDB::getDef(string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
2915  }
2916 
2917  return _nrcol.getDef( );
2918 }
2919 
2928 long RDB::getWidth( const string& name ) const {
2929 
2930  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2931  if ( name == _cols[jdx]->getName( ) ) {
2932  return _cols[jdx]->getWidth( );
2933 
2934  }
2935  }
2936 
2937  if ( "_NR" != name ) {
2938  throw ( RDBErr( string("RDB::getWidth(string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
2939  }
2940 
2941  return _nrcol.getWidth( );
2942 }
2943 
2952 RDBColumn::Type RDB::getType( const string& name ) const {
2953 
2954  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2955  if ( name == _cols[jdx]->getName( ) ) {
2956  return _cols[jdx]->getType( );
2957 
2958  }
2959  }
2960 
2961  if ( "_NR" != name ) {
2962  throw ( RDBErr( string("RDB::getType(string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
2963  }
2964 
2965  return _nrcol.getType( );
2966 }
2967 
2976 RDBColumn::Just RDB::getJust( const string& name ) const {
2977 
2978  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
2979  if ( name == _cols[jdx]->getName( ) ) {
2980  return _cols[jdx]->getJust( );
2981 
2982  }
2983  }
2984 
2985  if ( "_NR" != name ) {
2986  throw ( RDBErr( string("RDB::getJust(string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
2987  }
2988 
2989  return _nrcol.getJust( );
2990 }
2991 
3000 string RDB::getDesc( const string& name ) const {
3001 
3002  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
3003  if ( name == _cols[jdx]->getName( ) ) {
3004  return _cols[jdx]->getDesc( );
3005 
3006  }
3007  }
3008 
3009  if ( "_NR" != name ) {
3010  throw ( RDBErr( string("RDB::getDesc(string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
3011  }
3012 
3013  return _nrcol.getDesc( );
3014 }
3015 
3025 double RDB::getDataDouble( const string& name ) {
3026 
3027  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
3028  if ( name == _cols[jdx]->getName( ) ) {
3029  try {
3030  return _cols[jdx]->getDataDouble( );
3031 
3032  } catch ( RDBErr& e ) {
3033  e.set_message( "RDB::getDataDouble: error with file '" + _filename + "': " );
3034  throw( e );
3035 
3036  } catch ( ... ) {
3037  throw( RDBErr( "RDB::getDataDouble: unexpected exception caught with file '" + _filename + "':" ) );
3038  }
3039  }
3040  }
3041 
3042  if ( "_NR" != name ) {
3043  throw ( RDBErr( string("RDB::getDataDouble(string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
3044  }
3045 
3046  return _nrcol.getDataDouble( );
3047 }
3048 
3058 long RDB::getDataLong( const string& name ) {
3059 
3060  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
3061  if ( name == _cols[jdx]->getName( ) ) {
3062  try {
3063  return _cols[jdx]->getDataLong( );
3064 
3065  } catch ( RDBErr& e ) {
3066  e.set_message( "RDB::getDataLong: error with file '" + _filename + "': " );
3067  throw( e );
3068 
3069  } catch ( ... ) {
3070  throw( RDBErr( "RDB::getDataLong: unexpected exception caught with file '" + _filename + "':" ) );
3071  }
3072  }
3073  }
3074 
3075  if ( "_NR" != name ) {
3076  throw ( RDBErr( string("RDB::getDataLong(string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
3077  }
3078 
3079  return _nrcol.getDataLong( );
3080 }
3081 
3091 string RDB::getDataString( const string& name ) {
3092 
3093  for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
3094  if ( name == _cols[jdx]->getName( ) ) {
3095  try {
3096  return _cols[jdx]->getDataString( );
3097 
3098  } catch ( RDBErr& e ) {
3099  e.set_message( "RDB::getDataString: error with file '" + _filename + "': " );
3100  throw( e );
3101 
3102  } catch ( ... ) {
3103  throw( RDBErr( "RDB::getDataString: unexpected exception caught with file '" + _filename + "':" ) );
3104  }
3105  }
3106  }
3107 
3108  if ( "_NR" != name ) {
3109  throw ( RDBErr( string("RDB::getDataString(string&): error with file '" + _filename + "': Column ") + name + " not found" ) );
3110  }
3111 
3112  return _nrcol.getDataString( );
3113 }
3114 
3119 size_t
3121  void
3122  ) const {
3123 
3124  return _ncomms;
3125 
3126 }
3127 
3132 size_t
3134  void
3135  ) const {
3136 
3137  return _ncols;
3138 
3139 }
3140 
3150 size_t
3152  void
3153  ) {
3154 
3155  if ( ! _knowrows ) {
3156  _nrows = 0;
3157  long position;
3158 
3159  if ( ios::in & _mode && _isptr ) {
3160  _isptr->clear( );
3161 
3162  position = _isptr->tellg( );
3163  _isptr->seekg( _rewindto );
3164 
3165  while ( EOF != _isptr->peek( ) && getline( *_isptr, _line, '\n' ) )
3166  _nrows++;
3167 
3168  _knowrows = true;
3169  _isptr->clear( );
3170  _isptr->seekg( position );
3171 
3172  }
3173  }
3174 
3175  return _nrows;
3176 
3177 }
3178 
3184 void
3186  void
3187  ) {
3188 
3189  string line0, line1;
3190  getline( *_isptr, line0, '\n' );
3191 
3192  while ( suplib::iscomment( line0 ) ) {
3193  try {
3194  RDBComment tmpcomm(line0);
3195  setComment( tmpcomm, -1 );
3196 
3197  } catch ( RDBErr& e ) {
3198  stringstream ss;
3199  ss << "RDB::parseHeader(void): error at comment " << _ncomms + _nrows << ": ";
3200  e.set_message( ss.str( ) );
3201  throw( e );
3202 
3203  } catch ( ... ) {
3204  stringstream ss;
3205  ss << "RDB::parseHeader(void): unexpected exception caught at comment " << _ncomms + _nrows ;
3206  throw( RDBErr( ss.str( ) ) );
3207 
3208  }
3209 
3210  line0.erase( );
3211  getline( *_isptr, line0, '\n' );
3212  }
3213 
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 );
3219 
3220  if ( nametokens.size( ) != deftokens.size( ) ) {
3221  stringstream ss;
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( ) ) );
3224 
3225  } else {
3226  _ncols = nametokens.size( );
3227 
3228  if ( _cols ) {
3229  for ( size_t idx = 0; idx < _ncols; idx++ ) {
3230  if ( _mycols[idx] ) {
3231  delete _cols[idx];
3232 
3233  }
3234  }
3235  delete [] _cols;
3236  delete [] _mycols;
3237 
3238  }
3239 
3240  _cols = new RDBColumn*[_ncols];
3241  _mycols = new bool[_ncols];
3242 
3243  size_t idx;
3244  size_t typepos;
3245  for ( idx = 0; idx < _ncols; idx++ ) {
3246  try {
3247  if ( deftokens[idx].npos != (typepos = deftokens[idx].find_first_not_of( "0123456789" )) && 'N' == deftokens[idx][typepos] ) {
3248  _cols[idx]
3249  = new RDBDoubleColumn( nametokens[idx], deftokens[idx] );
3250 
3251  } else {
3252  _cols[idx]
3253  = new RDBStringColumn( nametokens[idx], deftokens[idx] );
3254 
3255  }
3256  } catch ( RDBErr& rdberr ) {
3257  rdberr.set_message( "RDB::parseHeader(void): column definition error: " );
3258  throw( rdberr );
3259 
3260  } catch ( ... ) {
3261  throw( RDBErr( "RDB::parse::Header(void): unexpected exception caught" ) );
3262 
3263  }
3264 
3265  _mycols[idx] = true;
3266 
3267  }
3268  }
3269 
3270  _rownum = 0;
3271  _rewindto = _isptr->tellg( );
3272 
3273 }
3274 
3283 vector<string>
3285  const string& line
3286  ) const {
3287 
3288  vector<string> tokens;
3289  if ( ! line.empty( ) ) {
3290  size_t st0 = 0, st1 = 0;
3291 
3292  do {
3293  st1 = line.find( '\t', st0 );
3294  if ( line.size( ) < st1 ) {
3295  st1 = line.size( );
3296 
3297  }
3298 
3299  tokens.push_back( line.substr( st0, st1 - st0 ) );
3300  st0 = st1 + 1;
3301 
3302  } while ( line.size( ) > st1 );
3303  }
3304 
3305  return tokens;
3306 
3307 }
3308 
3315 size_t
3317  bool& newgroup
3318  ) {
3319 
3320  size_t ntoks = 0;
3321  size_t begin = 0;
3322  size_t end = _line.find( '\t' );
3323 
3324  try {
3325  do {
3326  end = _line.find( '\t', begin );
3327 
3328  _cols[ntoks]->setData( _line.substr( begin, end - begin ) );
3329 
3330  if ( RBOG & _cols[ntoks]->newGroup( ) )
3331  newgroup = true;
3332 
3333  ntoks++;
3334  begin = end + 1;
3335 
3336  } while ( _line.npos != end );
3337 
3338  } catch ( RDBErr& rdberr ) {
3339  stringstream ss;
3340  ss << "RDB::parseLine(void): error at row " << _rownum << ": ";
3341  rdberr.set_message( ss.str( ) );
3342  throw( rdberr );
3343 
3344  } catch ( ... ) {
3345  stringstream ss;
3346  ss << "RDB::parseLine(void): unexpected exception caught at row " << _rownum;
3347  throw( RDBErr( ss.str( ) ) );
3348 
3349  }
3350 
3351  return ntoks;
3352 
3353 }
void setComment(const string &comm, const int idx=-1)
Add RDBComment in header of RDB object.
Definition: RDB.cc:1015
size_t _ncols
Number of columns.
Definition: RDB.h:321
void getData(const size_t idx, double &data)
Return the data of the RDBColumn at idx, converting if necessary.
Definition: RDB.cc:1933
size_t nColumns(void) const
Return number of columns in RDB object.
Definition: RDB.cc:3133
string getName(void) const
Returns the name.
Definition: RDBColumn.cc:484
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.
Definition: RDB.cc:3284
string _filename
Name of RDB file.
Definition: RDB.h:303
Just
Acceptable column justifications.
Definition: RDBColumn.h:60
size_t _nrows
Number of rows.
Definition: RDB.h:323
void setName(const string &name)
Sets the name.
Definition: RDBColumn.cc:247
bool _knowrows
Indicates if associated file must be scanned to determine number of rows.
Definition: RDB.h:325
bool rewind(void)
Rewind the stream to the beginning of the first row of data.
Definition: RDB.cc:772
bool _myosptr
Indicates if RDB object is responsible for deallocating the ostream.
Definition: RDB.h:314
void setGroup(const string &name, bool group=true)
Turn on/off group status for the named column.
Definition: RDB.cc:878
RDBComment & getComment(const size_t idx)
Return RDBComment at given index.
Definition: RDB.cc:1148
bool _myisptr
Indicates if RDB object is responsible for deallocating the istream.
Definition: RDB.h:312
void setDesc(const size_t idx, const string &desc)
Modify the description of the RDBColumn at idx.
Definition: RDB.cc:1621
bool _firstread
Indicates if this is the first call to RDB::read.
Definition: RDB.h:334
void setWidth(const long width)
Sets the width.
Definition: RDBColumn.cc:340
void setJust(const RDBColumn::Just just)
Sets the justification.
Definition: RDBColumn.cc:375
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.
Definition: RDB.cc:2196
bool _writehdr
Indicates if the header has been output.
Definition: RDB.h:338
void close(void)
Closes the stream attached to RDB object.
Definition: RDB.cc:526
void setType(const RDBColumn::Type type)
Sets the type.
Definition: RDBColumn.cc:357
void setDef(const string &def)
Sets the definition.
Definition: RDBColumn.cc:266
void setDef(const size_t idx, const string &def)
Modify the definition of the RDBColumn at idx.
Definition: RDB.cc:1509
RDBLongColumn _nrcol
Hidden column, containing row number.
Definition: RDB.h:345
The parent class for all RDB related exceptions.
Definition: RDBErr.h:33
int read(void)
Read a line of data from the istream.
Definition: RDB.cc:589
void parseHeader(void)
Parse header, i.e. comments and column names and definitions.
Definition: RDB.cc:3185
void getDef(const size_t idx, string &def)
Return the definition of the RDBColumn at idx.
Definition: RDB.cc:1837
~RDB(void)
Deletes resources allocated by the RDB object.
Definition: RDB.cc:271
RDBColumn ** _cols
Array of RDBColumns.
Definition: RDB.h:343
virtual bool setData(const Tmplt0 &data)
Sets the data value, converting as necessary.
bool write(void)
Write a line of data to the ostream.
Definition: RDB.cc:712
void setWidth(const size_t idx, const long width)
Modify the width of the RDBColumn at idx.
Definition: RDB.cc:1537
void open(const string &name, ios::openmode mode=ios::in)
Attaches RDB object to a file.
Definition: RDB.cc:316
void setType(const size_t idx, const RDBColumn::Type type)
Modify the type of the RDBColumn at idx.
Definition: RDB.cc:1565
Provides interface for manipulating RDB comments.
Definition: RDBComment.h:35
virtual void setGroup(bool group)
Turn on/off group tracking for this column object.
Definition: RDBColumn.cc:219
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...
Definition: RDBColumn.cc:232
void setData(const size_t idx, const double data)
Sets the data value of RDBColumn, converting as necessary.
Definition: RDB.cc:1735
RDBColumn * getColumn(const size_t idx)
Return pointer to RDBColumn at given index.
Definition: RDB.cc:1433
size_t nRows(void)
Return number of rows in RDB object.
Definition: RDB.cc:3151
ostream * _osptr
Ostream attached to data file.
Definition: RDB.h:310
bool autoIdx(void) const
Indicates if auto-indexing is activated.
Definition: RDB.cc:843
string getDesc(void) const
Returns the description.
Definition: RDBColumn.cc:579
RDBComment * _comms
Array of RDBComments.
Definition: RDB.h:341
istream * _isptr
Istream attached to data file.
Definition: RDB.h:308
RDBColumn::Type getType(void) const
Returns the type.
Definition: RDBColumn.cc:553
bool newGroup(void)
Checks if any column indicates a new group.
Definition: RDB.cc:989
size_t _rewindto
Position of beginning of first row of data.
Definition: RDB.h:317
Provides interface for manipulating RDB tables.
Definition: RDB.h:43
RDB(const string &name="", ios::openmode mode=ios::in)
Attaches RDB object to a file.
Definition: RDB.cc:118
virtual void mapData(double data[], const size_t nelems=1)
Maps data to user-supplied memory, if possible.
Definition: RDBColumn.cc:448
size_t _ncomms
Number of comments.
Definition: RDB.h:319
void getType(const size_t idx, RDBColumn::Type &type) const
Return the type of the RDBColumn at idx.
Definition: RDB.cc:1875
virtual long getDataLong(void)
Returns the value of the current data element, converting if necessary.
Type
Acceptable column types.
Definition: RDBColumn.h:62
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.
Definition: RDB.cc:1856
void mapData(const size_t idx, double data[], const size_t nelems=1)
Map RDBColumn data to user-supplied memory.
Definition: RDB.cc:1650
void setDesc(const string &desc)
Sets the description.
Definition: RDBColumn.cc:391
long getDataLong(const size_t idx)
Return the data of the RDBColumn at idx, converting if necessary.
Definition: RDB.cc:2167
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.
Definition: RDB.cc:3120
long getWidth(void) const
Returns the width.
Definition: RDBColumn.cc:540
void advanceIdx(void)
Increments the indices in the RDBColumn data elements.
Definition: RDB.cc:857
string _line
Line from RDB table.
Definition: RDB.h:350
void setColumn(const string &name, const string &def, const int idx=-1)
Add an RDBColumn in RDB object.
Definition: RDB.cc:1208
void getDesc(const size_t idx, string &desc) const
Return the description of the RDBColumn at idx.
Definition: RDB.cc:1913
ios::openmode _mode
Open mode of the associated stream.
Definition: RDB.h:305
string getDef(void)
Returns the definition.
Definition: RDBColumn.cc:498
bool _autoidx
Indicates if RDBColumn data elements should be advanced.
Definition: RDB.h:332
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.
Definition: RDB.cc:1488
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.
Definition: RDB.h:336
RDBColumn::Just getJust(void) const
Returns the justification.
Definition: RDBColumn.cc:566
double getDataDouble(const size_t idx)
Return the data of the RDBColumn at idx, converting if necessary.
Definition: RDB.cc:2138
virtual long getDataLong(void)=0
Returns the value of the current data element, converting if necessary.
long _rownum
Current table row number.
Definition: RDB.h:327
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.
Definition: RDB.cc:938
void getName(const size_t idx, string &name) const
Return the name of the RDBColumn at idx.
Definition: RDB.cc:1818
Provides interface for general column related methods.
Definition: RDBColumn.h:43
bool * _mycols
Indicates if RDB object is responsible for deallocating given RDBColumn.
Definition: RDB.h:347
void getJust(const size_t idx, RDBColumn::Just &just) const
Return the just of the RDBColumn at idx.
Definition: RDB.cc:1894
void setJust(const size_t idx, const RDBColumn::Just just)
Modify the justification of the RDBColumn at idx.
Definition: RDB.cc:1593