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