RDB.cc

00001 // --8<--8<--8<--8<--
00002 //
00003 // Copyright (C) 2006 Smithsonian Astrophysical Observatory
00004 //
00005 // This file is part of RDB
00006 //
00007 // RDB is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // RDB is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with this program; if not, write to the 
00019 //       Free Software Foundation, Inc. 
00020 //       51 Franklin Street, Fifth Floor
00021 //       Boston, MA  02110-1301, USA
00022 //
00023 // -->8-->8-->8-->8--
00024 
00025 #include "RDB.h"
00026 
00037 istream&
00038 operator>>( 
00039   istream& is, 
00040   RDB& rdb 
00041   ) throw ( RDBErr ) {
00042 
00043   try { 
00044     if ( &is != rdb._isptr ) {
00045       rdb.open( &is );
00046       
00047     } else {
00048       if ( RDB::REOF == rdb.read( ) ) {
00049         is.setstate( ios::eofbit | ios::failbit );
00050 
00051       }      
00052     }
00053   } catch ( RDBErr& rdberr ) {
00054     rdberr.set_message( "operator>>(istream&,RDB&):  " );
00055     throw( rdberr );
00056 
00057   } catch ( ... ) {
00058     throw( RDBErr( "operator>>(istream&,RDB&):  unexpected exception caught" ) );
00059 
00060   }
00061 
00062   return is;
00063 
00064 }
00065 
00075 ostream& 
00076 operator<<( 
00077   ostream& os, 
00078   RDB& rdb 
00079   ) throw ( RDBErr ) {
00080 
00081   try {
00082     if ( &os != rdb._osptr ) {
00083       rdb.open( &os );
00084 
00085     } else {
00086       rdb.write( );
00087 
00088     }
00089   } catch ( RDBErr& rdberr ) {
00090     rdberr.set_message( "operator<<(ostream&,RDB&):  " );
00091     throw( rdberr );
00092     
00093   } catch ( ... ) {
00094     throw( RDBErr( "operator<<(ostream&,RDB&):  unexpected exception caught" ) );
00095     
00096   }
00097 
00098   return os;
00099 
00100 }
00101 
00118 RDB::RDB( 
00119   const string& name, 
00120   ios::openmode mode 
00121   ) throw ( RDBErr ) 
00122   : _filename(name), _mode(mode), 
00123     _isptr(NULL), _osptr(NULL),
00124     _myisptr(true), _myosptr(true),
00125     _rewindto(0), 
00126     _ncomms(0), _ncols(0), _nrows(0),
00127     _knowrows(false), _rownum(0),
00128     _autoidx(false),
00129     _firstread(true), _lastread(false), _writehdr(true),
00130     _comms(NULL), _cols(NULL),  
00131     _nrcol("_NR","N"), _mycols(NULL), 
00132     _line(1024,'\0') {
00133     
00134   _nrcol.mapData( &_rownum, 1 );
00135   
00136   if ( name.empty( ) ) {
00137     close( );
00138 
00139   } else {
00140     try {
00141       open( name, mode );
00142       
00143     } catch ( RDBErr& rdberr ) {
00144       rdberr.set_message( "RDB::RDB(string&,ios::openmode):  " );
00145       throw( rdberr );
00146       
00147     } catch ( ... ) { 
00148       throw( RDBErr( "RDB::RDB(string&,ios::openmode):  unexpected exception caught" ) );
00149       
00150     }
00151   }
00152 }
00153 
00164 RDB::RDB( 
00165   istream* isptr 
00166   ) throw ( RDBErr ) : _filename("istream"), 
00167                        _isptr(NULL), _osptr(NULL),
00168                        _myisptr(false), _myosptr(false), 
00169                        _rewindto(0),
00170                        _ncomms(0), _ncols(0), _nrows(0),
00171                        _knowrows(false), _rownum(0), 
00172                        _autoidx(false),
00173                        _firstread(true), _lastread(false), _writehdr(true),
00174                        _comms(NULL), _cols(NULL),  
00175                        _nrcol("_NR","N"), _mycols(NULL),
00176                        _line(1024,'\0') {
00177 
00178   _nrcol.mapData( &_rownum, 1 );
00179 
00180   try {
00181     open( isptr );
00182 
00183   } catch ( RDBErr& rdberr ) {
00184     rdberr.set_message( "RDB::RDB(istream*):  " );
00185     throw( rdberr );
00186     
00187   } catch ( ... ) { 
00188     throw( RDBErr( "RDB::RDB(istream*):  unexpected exception caught" ) );
00189     
00190   }
00191 } 
00192 
00199 RDB::RDB( 
00200   ostream* osptr 
00201   ) throw ( RDBErr ) : _filename("ostream"), 
00202                        _isptr(NULL), _osptr(NULL),
00203                        _myisptr(false), _myosptr(false),
00204                        _rewindto(0),
00205                        _ncomms(0), _ncols(0), _nrows(0),
00206                        _knowrows(false), _rownum(0),
00207                        _autoidx(false),
00208                        _firstread(true), _lastread(false), _writehdr(true),
00209                        _comms(NULL), _cols(NULL),  
00210                        _nrcol("_NR","N"), _mycols(NULL),
00211                        _line(1024,'\0') {   
00212 
00213   _nrcol.mapData( &_rownum, 1 );
00214 
00215   try {
00216     open( osptr );
00217 
00218   } catch ( RDBErr& rdberr ) {
00219     rdberr.set_message( "RDB::RDB(ostream&):  " );
00220     throw( rdberr );
00221     
00222   } catch ( ... ) { 
00223     throw( RDBErr( "RDB::RDB(ostream&):  unexpected exception caught" ) );
00224     
00225   }
00226 } 
00227 
00234 RDB::RDB( 
00235   const RDB& rdb
00236   ) throw ( RDBErr ) : _filename(rdb._filename), _mode(rdb._mode), 
00237                        _isptr(NULL), _osptr(NULL), 
00238                        _myisptr(true), _myosptr(true),
00239                        _rewindto(0), _ncomms(0), _ncols(0), _nrows(0),
00240                        _knowrows(false), _rownum(0),
00241                        _autoidx(false), _firstread(true), _lastread(false),
00242                        _writehdr(true),
00243                        _comms(NULL), _cols(NULL), _nrcol("_NR","N"),
00244                        _mycols(NULL), _line(1024,'\0') { 
00245     
00246   _nrcol.mapData( &_rownum, 1 );
00247 
00248   try { 
00249     open( rdb );
00250 
00251   } catch ( RDBErr& rdberr ) {
00252     rdberr.set_message( "RDB::RDB(RDB&):  " );
00253     throw( rdberr );
00254     
00255   } catch ( ... ) { 
00256     throw( RDBErr( "RDB::RDB(RDB&):  unexpected exception caught" ) );
00257     
00258   }
00259 } 
00260 
00271 RDB::~RDB(
00272   void
00273   ) {
00274 
00275   close( );
00276 
00277   if ( _comms ) {
00278     delete [] _comms; 
00279 
00280   }
00281 
00282   if ( _cols ) {
00283     for ( size_t idx = 0; idx < _ncols; idx++ ) {
00284       if ( _mycols[idx] ) {
00285         delete _cols[idx]; 
00286       }
00287     }
00288     delete [] _cols;
00289     delete [] _mycols;
00290   }
00291 
00292   _isptr  = NULL;
00293   _osptr  = NULL;
00294   _comms  = NULL;
00295   _cols   = NULL;
00296   _mycols = NULL;
00297 
00298 }
00299 
00315 void
00316 RDB::open( 
00317   const string& name, 
00318   ios::openmode mode 
00319   ) throw ( RDBErr ) { 
00320 
00321   close( );
00322 
00323   _filename = name;
00324   _mode     = mode;
00325 
00326   if ( ios::in & _mode ) {
00327     _isptr = new ifstream( _filename.c_str( ), _mode );
00328     _myisptr = true;
00329     if ( ! _isptr || ! *_isptr ) {
00330       stringstream ss;
00331       ss << "RDB::open(string&,ios_base::openmode):  Error opening '" 
00332          << _filename << "' with mode";
00333       if ( ios_base::app & _mode ) 
00334         ss << " ios_base::app";
00335       if ( ios_base::binary & _mode )
00336         ss << " ios_base::binary";
00337       if ( ios_base::in & _mode )
00338         ss << " ios_bae::in";
00339       if ( ios_base::out & _mode )
00340         ss << " ios_base::out";
00341       if ( ios_base::trunc & _mode )
00342         ss << " ios_base::trunc";
00343       if ( ios_base::ate & _mode )
00344         ss << " ios_base::ate";
00345       throw( RDBErr( ss.str( ) ) );
00346 
00347     }
00348 
00349     try { 
00350       parseHeader( );
00351 
00352     } catch ( RDBErr& rdberr ) {
00353       rdberr.set_message( "RDB::open(string&,ios::openmode):  error with file '" + _filename + "':  " );
00354       throw( rdberr );
00355       
00356     } catch ( ... ) { 
00357       throw( RDBErr( "RDB::open(string&,ios::openmode):  unexpected exception caught with file '" + _filename + "'" ) );
00358       
00359     }
00360   }
00361 
00362   if ( ios::out & _mode ) {
00363     _osptr = new ofstream( _filename.c_str( ), _mode );
00364     _myosptr = true;
00365     if ( ! _osptr || ! *_osptr ) {
00366       stringstream ss;
00367       ss << "RDB::open(string&,ios_base::openmode):  Error opening '" 
00368          << _filename << "' with mode";
00369       if ( ios_base::app & _mode ) 
00370         ss << " ios_base::app";
00371       if ( ios_base::binary & _mode )
00372         ss << " ios_base::binary";
00373       if ( ios_base::in & _mode )
00374         ss << " ios_bae::in";
00375       if ( ios_base::out & _mode )
00376         ss << " ios_base::out";
00377       if ( ios_base::trunc & _mode )
00378         ss << " ios_base::trunc";
00379       if ( ios_base::ate & _mode )
00380         ss << " ios_base::ate";
00381       throw( RDBErr( ss.str( ) ) );
00382 
00383     }
00384   }
00385 }
00386 
00399 void
00400 RDB::open( 
00401   istream* isptr
00402   ) throw ( RDBErr ) { 
00403 
00404   close( );
00405 
00406   _filename = "istream";
00407   _mode     = ios::in;
00408   _isptr    = isptr;
00409 
00410   try { 
00411     parseHeader( );
00412 
00413   } catch ( RDBErr& rdberr ) {
00414     rdberr.set_message( "RDB::open(istream&):  " );
00415     throw( rdberr );
00416     
00417   } catch ( ... ) { 
00418     throw( RDBErr( "RDB::open(istream&):  unexpected exception caught" ) );
00419     
00420   }
00421 }
00422 
00431 void
00432 RDB::open( 
00433   ostream* osptr
00434   ) throw ( RDBErr ) { 
00435 
00436   close( );
00437 
00438   _filename = "ostream";
00439   _mode     = ios::out;
00440   _osptr    = osptr;
00441 
00442 }
00443 
00450 void
00451 RDB::open( 
00452   const RDB& rdb
00453   ) throw ( RDBErr ) { 
00454   
00455   close( );
00456 
00457   _filename = rdb._filename;
00458   _mode     = rdb._mode;
00459 
00460   if ( ios::in & _mode ) {
00461     _isptr = new ifstream( _filename.c_str( ), _mode );
00462     _myisptr = true;
00463     if ( ! _isptr ) {
00464       stringstream ss;
00465       ss << "RDB::open(RDB&):  Error opening '" 
00466          << _filename << "' with mode";
00467       if ( ios_base::app & _mode ) 
00468         ss << " ios_base::app";
00469       if ( ios_base::binary & _mode )
00470         ss << " ios_base::binary";
00471       if ( ios_base::in & _mode )
00472         ss << " ios_bae::in";
00473       if ( ios_base::out & _mode )
00474         ss << " ios_base::out";
00475       if ( ios_base::trunc & _mode )
00476         ss << " ios_base::trunc";
00477       if ( ios_base::ate & _mode )
00478         ss << " ios_base::ate";
00479       throw( RDBErr( ss.str( ) ) );
00480 
00481     }
00482 
00483     try { 
00484       parseHeader( );
00485 
00486     } catch ( RDBErr& rdberr ) {
00487       rdberr.set_message( "RDB::open(RDB&):  error with file '" + _filename + "':  " );
00488       throw( rdberr );
00489       
00490     } catch ( ... ) { 
00491       throw( RDBErr( "RDB::open(RDB&):  unexpected exception caught with file '" + _filename + "'" ) );
00492       
00493     }
00494   }
00495 
00496   if ( ios::out & _mode ) {
00497     _osptr = new ofstream( _filename.c_str( ), _mode );
00498     _myosptr = true;
00499     if ( ! _osptr ) {
00500       stringstream ss;
00501       ss << "RDB::open(RDB&):  Error opening '" 
00502          << _filename << "' with mode";
00503       if ( ios_base::app & _mode ) 
00504         ss << " ios_base::app";
00505       if ( ios_base::binary & _mode )
00506         ss << " ios_base::binary";
00507       if ( ios_base::in & _mode )
00508         ss << " ios_bae::in";
00509       if ( ios_base::out & _mode )
00510         ss << " ios_base::out";
00511       if ( ios_base::trunc & _mode )
00512         ss << " ios_base::trunc";
00513       if ( ios_base::ate & _mode )
00514         ss << " ios_base::ate";
00515       throw( RDBErr( ss.str( ) ) );
00516 
00517     }
00518   }
00519 }
00520 
00525 void
00526 RDB::close(
00527   void
00528   ) { 
00529 
00530   if ( _myisptr && _isptr ) {
00531     delete _isptr;
00532 
00533   }
00534 
00535   if ( _osptr && _writehdr ) {
00536     size_t idx;
00537     for ( idx = 0; idx < _ncomms; idx++ )
00538       *_osptr << _comms[idx] << endl;
00539 
00540     if ( _ncols ) {
00541       for ( idx = 0; idx < _ncols - 1; idx++ )
00542         *_osptr << _cols[idx]->getName( ) << "\t";
00543       *_osptr << _cols[idx]->getName( ) << endl;
00544       
00545       for ( idx = 0; idx < _ncols - 1; idx++ )
00546         *_osptr << _cols[idx]->getDef( ) << "\t";
00547       *_osptr << _cols[idx]->getDef( ) << endl;
00548 
00549       _rewindto = _osptr->tellp( );
00550       _rownum   = 0;
00551       _writehdr = false;
00552     
00553     }
00554   }
00555 
00556   if ( _myosptr && _osptr ) {
00557     delete _osptr;
00558 
00559   }
00560 
00561   _filename.erase( );
00562   _isptr    = NULL;
00563   _myisptr  = false;
00564   _osptr    = NULL;
00565   _myosptr  = false;
00566   _autoidx  = false;
00567   _nrows    = 0;
00568   _knowrows = false;
00569   _rownum   = 0;
00570 
00571 }
00572 
00588 int
00589 RDB::read( 
00590   void
00591   ) throw ( RDBErr ) { 
00592 
00593   if ( ios::in & _mode && _isptr && *_isptr ) {
00594     int newgroup = RDB::REOF;
00595     char c = _isptr->peek( );
00596     if ( '\n' == c ) {
00597       _isptr->get( );
00598       c = _isptr->peek( );
00599 
00600     }
00601 
00602     if ( EOF == c ) {
00603       if ( _lastread )
00604         return RDB::REOF;
00605       else 
00606         _lastread = true;
00607     }
00608 
00609     _rownum++;
00610 
00611     if ( ! _lastread ) {
00612       try {
00613         getline( *_isptr, _line, '\n' );
00614         _isptr->clear( );
00615         vector<string> tokens;
00616         suplib::tok( tokens, _line, "\t", false );
00617 
00618         if ( tokens.size( ) != _ncols ) {
00619           stringstream ss;
00620           ss << "RDB::read(void):  error reading file '" << _filename << "':  invalid row at " << _rownum << ":  number of token(" << tokens.size( ) << ") != number of columns(" << _ncols << ")";
00621           throw( RDBErr( ss.str( ) ) );
00622         }
00623 
00624         for ( int idx = 0; idx < _ncols; idx++ ) {
00625           _cols[idx]->setData( tokens[idx] );
00626           if ( _autoidx ) {
00627             _cols[idx]->advanceIdx( );
00628           }
00629           newgroup = newgroup | _cols[idx]->newGroup( );
00630 
00631         }
00632       } catch ( RDBErr& rdberr ) {
00633         rdberr.set_message( "RDB::read(void):  error reading file '" + _filename + "':  " );
00634         throw( rdberr );
00635         
00636       } catch ( ... ) { 
00637         throw( RDBErr( "RDB::read(void):  unexpected exception caught with file '" + _filename + "'" ) );
00638         
00639       }
00640 
00641       if ( _firstread && (RDB::REOL ^ newgroup) ) {
00642         try {
00643           getline( *_isptr, _line, '\n' );
00644           if ( _isptr->eof( ) ) {
00645             newgroup |= REOG;
00646             for ( int idx = 0; idx < _ncols; idx++ ) {
00647               if ( _autoidx ) {
00648                 _cols[idx]->advanceIdx( );
00649               }
00650             }
00651           } else {
00652             _isptr->clear( );
00653             vector<string> tokens;
00654             suplib::tok( tokens, _line, "\t", false );
00655           
00656             if ( tokens.size( ) != _ncols ) {
00657               stringstream ss;
00658               ss << "RDB::read(void):  error reading file '" << _filename << "':  invalid row at " << _rownum+1 << ":  number of token(" << tokens.size( ) << ") != number of columns(" << _ncols << ")";
00659               throw( RDBErr( ss.str( ) ) );
00660             }
00661 
00662             for ( int idx = 0; idx < _ncols; idx++ ) {
00663               _cols[idx]->setData( tokens[idx] );
00664               if ( _autoidx ) {
00665                 _cols[idx]->advanceIdx( );
00666               }
00667               //            newgroup = _cols[idx]->newGroup( );
00668             }
00669           }
00670         } catch ( RDBErr& rdberr ) {
00671           rdberr.set_message( "RDB::read(void):  error reading file '" + _filename + "':  " );
00672           throw( rdberr );
00673           
00674         } catch ( ... ) { 
00675           throw( RDBErr( "RDB::read(void):  unexpected exception caught reading file '" + _filename + "'" ) );
00676           
00677         }
00678 
00679         _firstread = false;
00680         
00681       }
00682     } else {
00683       if ( _autoidx ) {
00684         advanceIdx( );
00685         newgroup = RDB::REOG;
00686       } else {
00687         newgroup = RDB::REOF;
00688       }
00689     }
00690     return newgroup;
00691 
00692   } else {
00693     return RDB::REOF;
00694 
00695   }
00696 }
00697 
00711 bool
00712 RDB::write( 
00713   void
00714   ) throw ( RDBErr ) { 
00715 
00716   if ( ios::out & _mode && _osptr ) {
00717     if ( _writehdr ) {
00718       size_t idx;
00719       for ( idx = 0; idx < _ncomms; idx++ )
00720         *_osptr << _comms[idx] << endl;
00721       
00722       for ( idx = 0; idx < _ncols - 1; idx++ )
00723         *_osptr << _cols[idx]->getName( ) << "\t";
00724       *_osptr << _cols[idx]->getName( ) << endl;
00725       
00726       for ( idx = 0; idx < _ncols - 1; idx++ )
00727         *_osptr << _cols[idx]->getDef( ) << "\t";
00728       *_osptr << _cols[idx]->getDef( ) << endl;
00729       
00730       _rewindto = _osptr->tellp( );
00731       _rownum   = 0;
00732       _writehdr = false;
00733       
00734     }
00735 
00736     if ( _autoidx ) {
00737       advanceIdx( );
00738 
00739     }
00740 
00741     for ( size_t idx = 0; idx < _ncols; idx++ ) {
00742       *_osptr << *_cols[idx] << (( idx < _ncols - 1 ) ? ( '\t' ) : ( '\n' ));
00743 
00744     }
00745 
00746     _rownum++;
00747 
00748     return true;
00749 
00750   } else {
00751     return false;
00752 
00753   }
00754 }
00755 
00771 bool
00772 RDB::rewind( 
00773   void
00774   ) throw ( RDBErr ) { 
00775 
00776   if ( ios::in & _mode ) {
00777     _isptr->clear( );
00778     _isptr->seekg( _rewindto );
00779     _rownum = 0;
00780     
00781     if ( _rewindto != (size_t)_isptr->tellg( ) ) {
00782       return false;
00783 
00784     } else {
00785       for ( size_t idx = 0; idx < _ncols; idx++ ) {
00786         _cols[idx]->rewind( );
00787 
00788       }
00789 
00790       return true;
00791 
00792     }
00793   } else if ( ios::out & _mode ) {
00794     _osptr->clear( );
00795     _osptr->seekp( _rewindto );
00796     _rownum = 0;
00797     
00798     if ( _rewindto != (size_t)_osptr->tellp( ) ) {
00799       return false;
00800 
00801     } else {
00802       for ( size_t idx = 0; idx < _ncols; idx++ ) {
00803         _cols[idx]->rewind( );
00804 
00805       }
00806 
00807       return true;
00808 
00809     }
00810   }
00811 
00812   return false;
00813 
00814 }
00815 
00829 void
00830 RDB::autoIdx(
00831   const bool on
00832   ) { 
00833   
00834   _autoidx = on;
00835 
00836 }
00837 
00842 bool
00843 RDB::autoIdx( 
00844   void
00845   ) const { 
00846 
00847   return _autoidx;
00848 
00849 }
00850 
00856 void
00857 RDB::advanceIdx( 
00858   void
00859   ) {
00860 
00861   for ( size_t idx = 0; idx < _ncols; idx++ ) {
00862     _cols[idx]->advanceIdx( );
00863 
00864   }
00865   _nrcol.advanceIdx( );
00866 
00867 }
00868 
00877 void
00878 RDB::setGroup( 
00879   const string& name, 
00880   bool group
00881   ) throw ( RDBErr ) {
00882 
00883   _autoidx = true;
00884 
00885   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
00886     if ( name == _cols[jdx]->getName( ) ) {
00887       _cols[jdx]->setGroup( group );
00888       return;
00889 
00890     }
00891   }  
00892 
00893   
00894   if ( "_NR" != name ) {
00895     throw( RDBErr( string("RDB::setGroup(string):  error in file '" + _filename + "':  Column ") + name + "(0) not found" ) );
00896 
00897   }
00898 
00899   _nrcol.setGroup( group );
00900 }
00901 
00910 void
00911 RDB::setGroup( 
00912   const int idx, 
00913   bool group 
00914   ) throw ( RDBErr ) {
00915   
00916   _autoidx = true;
00917 
00918   if ( 0 <= idx && idx < (int)_ncols ) {
00919     _cols[idx]->setGroup( group );
00920 
00921   } else {    
00922     stringstream ss;
00923     ss << "RDB::setGroup(string):  error with file '" + _filename + "':  Column "  << idx << " of " << _ncols << " not found";
00924     throw( RDBErr( ss.str( ) ) );
00925 
00926   }
00927 }
00928 
00937 bool
00938 RDB::getGroup( 
00939   const string& name
00940   ) throw ( RDBErr ) {
00941 
00942   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
00943     if ( name == _cols[jdx]->getName( ) ) {
00944       return _cols[jdx]->getGroup( );
00945 
00946     }
00947   }
00948 
00949   if ( "_NR" != name ) {
00950     throw( RDBErr( string("RDB::getGroup(string):  error with file '" + _filename + "':  Column ") + name + "(0) not found" ) );
00951 
00952   }
00953 
00954   return _nrcol.getGroup( );
00955 
00956 }
00957 
00966 bool 
00967 RDB::getGroup( 
00968   const int idx
00969   ) throw ( RDBErr ) {
00970 
00971   if ( 0 > idx && idx >= _ncols ) {
00972     stringstream ss;
00973     ss << "RDB::getGroup(string):  error with file '" + _filename + "':  Column " << idx << " out of " << _ncols << " not found";
00974     throw( RDBErr( ss.str( ) ) );
00975     
00976   }
00977 
00978   return _cols[idx]->getGroup( );
00979 }
00980 
00988 bool
00989 RDB::newGroup( 
00990   void
00991   ) {
00992   
00993   for ( size_t idx = 0; idx < _ncols; idx++ ) {
00994     if ( REOL ^ _cols[idx]->newGroup( ) ) {
00995       return true;
00996 
00997     }
00998   }
00999 
01000   return false;
01001 
01002 }
01003   
01014 void 
01015 RDB::setComment( 
01016   const string& comm,
01017   const int idx 
01018   ) { 
01019 
01020   if ( 0 < idx && idx < (int) _ncomms ) {
01021     _comms[idx] = comm;
01022 
01023   } else {
01024     RDBComment* tmp = new RDBComment[_ncomms+1];
01025 
01026     if ( _comms ) {
01027       for ( size_t jdx = 0; jdx < _ncomms; jdx++ ) {
01028         tmp[jdx] = _comms[jdx];
01029 
01030       }
01031       delete [] _comms;
01032 
01033     }
01034 
01035     tmp[_ncomms++] = comm;
01036 
01037     _comms         = tmp;
01038 
01039   }
01040 }
01041 
01052 void 
01053 RDB::setComment( 
01054   RDBComment& comm,
01055   const int idx 
01056   ) { 
01057 
01058   if ( 0 < idx && idx < (int) _ncomms ) {
01059     _comms[idx] = comm;
01060 
01061   } else {
01062     RDBComment* tmp = new RDBComment[_ncomms+1];
01063 
01064     if ( _comms ) {
01065       for ( size_t jdx = 0; jdx < _ncomms; jdx++ ) {
01066         tmp[jdx] = _comms[jdx];
01067 
01068       }
01069       delete [] _comms;
01070 
01071     }
01072 
01073     tmp[_ncomms++] = comm;
01074 
01075     _comms         = tmp;
01076 
01077   }
01078 }
01079 
01089 void
01090 RDB::setComment( 
01091   RDBComment& comm, 
01092   const string& name, 
01093   const size_t idx 
01094   ) { 
01095 
01096   for ( size_t jdx = 0; jdx < _ncomms; jdx++ ) {
01097     if ( name == _comms[jdx].getKeyword( ) ) {
01098       _comms[jdx] = comm;
01099       return;
01100 
01101     }
01102   }
01103 
01104   setComment( comm, -1 );
01105 
01106 }
01107 
01115 void
01116 RDB::setComment( 
01117   const RDB& rdb
01118   ) { 
01119 
01120   if ( rdb._ncomms > _ncomms ) {
01121     if ( _ncomms )
01122       delete [] _comms;
01123     _comms = new RDBComment[rdb._ncomms];
01124 
01125   }
01126 
01127   _ncomms = rdb._ncomms;
01128 
01129   for ( size_t idx = 0; idx < _ncomms; idx++ ) {
01130     _comms[idx] = rdb._comms[idx];
01131 
01132   }
01133 }
01134 
01147 RDBComment&
01148 RDB::getComment( 
01149   const size_t idx
01150   ) throw ( RDBErr ) { 
01151 
01152   if ( 0 > idx && idx >= _ncomms ) {
01153     stringstream ss;
01154     ss << "RDB::getComment(size_t):  error with file '" + _filename + "':  Comment "  << idx << "out of "<< _ncomms << " not found";
01155     throw( RDBErr( ss.str( ) ) );
01156 
01157   }
01158 
01159   return _comms[idx];
01160 
01161 }
01162 
01172 RDBComment&
01173 RDB::getComment( 
01174   const string& name, 
01175   const size_t idx
01176   ) throw ( RDBErr ) { 
01177 
01178   for ( size_t jdx = 0; jdx < _ncomms; jdx++ ) {
01179     if ( name == _comms[jdx].getKeyword( ) ) {
01180       return _comms[jdx];
01181 
01182     }
01183   }
01184 
01185   stringstream ss;
01186   ss << "RDB::getComment(string):  error with file '" << _filename<< "':  Comment "  << name << "("<< idx << ") not found";
01187   throw( RDBErr( ss.str( ) ) );
01188 
01189 }
01190 
01207 void
01208 RDB::setColumn( 
01209   const string& name, 
01210   const string& def,
01211   const int idx 
01212   ) { 
01213 
01214   if ( 0 <= idx && idx < (int)_ncols ) {
01215 
01216     if ( _mycols[idx] ) {
01217       delete _cols[idx];
01218 
01219     }
01220 
01221     _cols[idx]->setName( name );
01222     _cols[idx]->setDef( def );
01223     _mycols[idx] = true;
01224 
01225   } else {
01226     RDBColumn** tmp = new RDBColumn*[_ncols+2];
01227     bool* tmpmycols = new bool[_ncols+1];
01228     RDBColumn* col;
01229     int pos;
01230     if ( def.npos != (pos = def.find_first_not_of( "0123456789" )) && 'N' == def[pos] ) {
01231       col = new RDBDoubleColumn( name, def );
01232     } else { 
01233       col = new RDBStringColumn( name, def );
01234     }
01235 
01236     if ( _cols ) {
01237       for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
01238         tmp[jdx]       = _cols[jdx];
01239         tmpmycols[jdx] = _mycols[jdx];
01240 
01241       }
01242       
01243       delete [] _cols;
01244       delete [] _mycols;
01245 
01246     }
01247 
01248     tmp[_ncols] = col;
01249     tmpmycols[_ncols++] = true;
01250 
01251     _cols   = tmp;
01252     _mycols = tmpmycols;
01253 
01254   }
01255 }
01256 
01273 void
01274 RDB::setColumn( 
01275   RDBColumn* col,
01276   const int idx 
01277   ) { 
01278 
01279   if ( 0 <= idx && idx < (int)_ncols ) {
01280 
01281     if ( _mycols[idx] ) {
01282       delete _cols[idx];
01283 
01284     }
01285 
01286     _cols[idx]   = col;
01287     _mycols[idx] = false;
01288 
01289   } else {
01290     RDBColumn** tmp  = new RDBColumn*[_ncols+2];
01291     bool* tmpmycols  = new bool[_ncols+1];
01292 
01293     if ( _cols ) {
01294       for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
01295         tmp[jdx]       = _cols[jdx];
01296         tmpmycols[jdx] = _mycols[jdx];
01297 
01298       }
01299       
01300       delete [] _cols;
01301       delete [] _mycols;
01302 
01303     }
01304 
01305     tmp[_ncols]         = col;
01306     tmpmycols[_ncols++] = false;
01307 
01308     _cols   = tmp;
01309     _mycols = tmpmycols;
01310 
01311   }
01312 }
01313 
01330 void 
01331 RDB::setColumn( 
01332   RDBColumn* col, 
01333   const string& name, 
01334   const size_t idx 
01335   ) { 
01336 
01337   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
01338     if ( name == _cols[jdx]->getName( ) ) {
01339       if ( _mycols[jdx] ) {
01340         delete _cols[jdx];
01341 
01342       }
01343 
01344       _cols[jdx]   = col;
01345       _mycols[jdx] = false;
01346       return;
01347 
01348     }
01349   }
01350 
01351   col->setName( name );
01352   setColumn( col, -1 );
01353 
01354 }
01355 
01367 void 
01368 RDB::setColumn( 
01369   const RDB& rdb
01370   ) { 
01371 
01372   size_t idx = 0;
01373   if ( rdb._ncols > _ncols ) {
01374     RDBColumn** tmp = new RDBColumn*[rdb._ncols+1];
01375     bool* tmpmycols = new bool[rdb._ncols];
01376 
01377     if ( _cols ) {
01378       for ( idx = 0; idx < _ncols; idx++ ) {
01379         tmp[idx]       = rdb._cols[idx];
01380         tmpmycols[idx] = false;
01381 
01382         if ( _mycols[idx] ) {
01383           delete _cols[idx];
01384 
01385         }
01386       }
01387       
01388       if ( _ncols ) {
01389         delete [] _cols;
01390         delete [] _mycols;
01391 
01392       }
01393     }
01394     
01395     for ( ; idx < rdb._ncols; idx++ ) {
01396       tmp[idx]       = rdb._cols[idx];
01397       tmpmycols[idx] = false;
01398       
01399     }
01400     _cols   = tmp;
01401     _mycols = tmpmycols;
01402 
01403   } else {
01404     for ( idx = 0; idx < rdb._ncols; idx++ ) {
01405       _cols[idx]   = rdb._cols[idx];
01406       _mycols[idx] = false;
01407 
01408     }
01409 
01410     for ( ; idx < _ncols; idx++ ) {
01411       delete _cols[idx];
01412 
01413     }
01414   }
01415 
01416   _ncols = rdb._ncols;
01417 
01418 }
01419 
01432 RDBColumn*
01433 RDB::getColumn(
01434   const size_t idx
01435   ) throw ( RDBErr ) { 
01436 
01437   if ( 0 > idx && idx >= _ncols ) {
01438     stringstream ss;
01439     ss << "RDB::getColumn(size_t):  error with file '" << _filename << "':  Column "  << idx << " out of "<< _ncols << " not found";
01440     throw( RDBErr( ss.str( ) ) );
01441     
01442   }
01443 
01444   return _cols[idx];
01445 
01446 }
01447 
01457 RDBColumn* 
01458 RDB::getColumn( 
01459   const string& name,
01460   const size_t idx 
01461   ) throw ( RDBErr ) {
01462 
01463   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
01464     if ( name == _cols[jdx]->getName( ) ) {
01465       return _cols[jdx];
01466 
01467     }
01468   }
01469 
01470   if ( "_NR" != name ) {
01471     stringstream ss;
01472     ss << "RDB::getColumn(string):  error with file '" << _filename << "':  Column "  << name << "("<< idx << ") not found";
01473     throw( RDBErr( ss.str( ) ) );
01474 
01475   }
01476 
01477   return &_nrcol;
01478 
01479 }
01480 
01488 void RDB::setName( const size_t idx, const string& name ) throw ( RDBErr ) {
01489 
01490   if ( idx >= (int)_ncols ) {
01491     stringstream ss;
01492     ss << "RDB::setName:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01493     throw( RDBErr( ss.str( ) ) );
01494 
01495   }
01496  
01497   _cols[idx]->setName( name );
01498   
01499 }
01500 
01509 void RDB::setDef( const size_t idx, const string& def  ) throw ( RDBErr ) {
01510 
01511   if ( idx > (int)_ncols ) {
01512     stringstream ss;
01513     ss << "RDB::setDef:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01514     throw( RDBErr( ss.str( ) ) );
01515   }
01516 
01517   try {
01518     _cols[idx]->setDef( def );
01519 
01520   } catch ( RDBErr& e ) {
01521     e.set_message( "RDB::setDef:  error with file '" + _filename + "':  " );
01522     throw( e );
01523 
01524   } catch ( ... ) {
01525     throw( RDBErr( "RDB::setDef:  unexpected exception caught with file '" + _filename +"'" ) );
01526   }
01527 }
01528 
01537 void RDB::setWidth( const size_t idx, const long width ) throw ( RDBErr ) {
01538 
01539   if ( idx > (int)_ncols ) {
01540     stringstream ss;
01541     ss << "RDB::setWidth:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01542     throw( RDBErr( ss.str( ) ) );
01543   }
01544 
01545   try {
01546     _cols[idx]->setWidth( width );
01547 
01548   } catch ( RDBErr& e ) {
01549     e.set_message( "RDB::setWidth:  error with file '" + _filename + "':  " );
01550     throw( e );
01551 
01552   } catch ( ... ) {
01553     throw( RDBErr( "RDB::setWidth:  unexpected exception caught with file '" + _filename + "'" ) );
01554   }
01555 }
01556 
01565 void RDB::setType( const size_t idx, const RDBColumn::Type type ) throw ( RDBErr ) {
01566 
01567   if ( idx > (int)_ncols ) {
01568     stringstream ss;
01569     ss << "RDB::setType:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01570     throw( RDBErr( ss.str( ) ) );
01571   }
01572 
01573   try {
01574     _cols[idx]->setType( type );
01575 
01576   } catch ( RDBErr& e ) {
01577     e.set_message( "RDB::setType:  error with file '" + _filename + "':  " );
01578     throw( e );
01579 
01580   } catch ( ... ) {
01581     throw( RDBErr( "RDB::setType:  unexpected exception caught with file '" + _filename + "'" ) );
01582   }
01583 }
01584 
01593 void RDB::setJust( const size_t idx, const RDBColumn::Just just ) throw ( RDBErr ) {
01594 
01595   if ( idx > (int)_ncols ) {
01596     stringstream ss;
01597     ss << "RDB::setJust:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01598     throw( RDBErr( ss.str( ) ) );
01599   }
01600 
01601   try {
01602     _cols[idx]->setJust( just );
01603 
01604   } catch ( RDBErr& e ) {
01605     e.set_message( "RDB::setJust:  error with file '" + _filename + "':  " );
01606     throw( e );
01607 
01608   } catch ( ... ) {
01609     throw( RDBErr( "RDB::setJust:  unexpected exception caught with file '" + _filename + "'" ) );
01610   }
01611 }
01612 
01621 void RDB::setDesc( const size_t idx, const string& desc ) throw ( RDBErr ) {
01622 
01623   if ( idx > (int)_ncols ) {
01624     stringstream ss;
01625     ss << "RDB::setDesc:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01626     throw( RDBErr( ss.str( ) ) );
01627   }
01628 
01629   try {
01630     _cols[idx]->setDesc( desc );
01631 
01632   } catch ( RDBErr& e ) {
01633     e.set_message( "RDB::setDesc:  error with file '" + _filename + "':  " );
01634     throw( e );
01635 
01636   } catch ( ... ) {
01637     throw( RDBErr( "RDB::setDesc:  unexpected exception caught with file '" + _filename + "'" ) );
01638   }
01639 }
01640 
01650 void RDB::mapData( const size_t idx, double data[], const size_t nelems ) throw ( RDBErr ) {
01651   if ( idx > (int)_ncols ) {
01652     stringstream ss;
01653     ss << "RDB::mapData:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01654     throw( RDBErr( ss.str( ) ) );
01655   }
01656 
01657   try {
01658     _cols[idx]->mapData( data, nelems );
01659 
01660   } catch ( RDBErr& e ) {
01661     e.set_message( "RDB::mapData:  error with file '" + _filename + "':  " );
01662     throw( e );
01663 
01664   } catch ( ... ) {
01665     throw( RDBErr( "RDB::mapData:  unexpected exception caught with file '" + _filename + "'" ) );
01666   }
01667 }
01668 
01678 void RDB::mapData( const size_t idx, long data[], const size_t nelems ) throw ( RDBErr ) {
01679 
01680   if ( idx > (int)_ncols ) {
01681     stringstream ss;
01682     ss << "RDB::mapData:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01683     throw( RDBErr( ss.str( ) ) );
01684   }
01685 
01686   try {
01687     _cols[idx]->mapData( data, nelems );
01688 
01689   } catch ( RDBErr& e ) {
01690     e.set_message( "RDB::mapData:  error with file '" + _filename + "':  " );
01691     throw( e );
01692 
01693   } catch ( ... ) {
01694     throw( RDBErr( "RDB::mapData:  unexpected exception caught with file '" + _filename + "'" ) );
01695   }
01696 }
01697 
01707 void RDB::mapData( const size_t idx, string data[], const size_t nelems ) throw ( RDBErr ) {
01708 
01709   if ( idx > (int)_ncols ) {
01710     stringstream ss;
01711     ss << "RDB::mapData:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01712     throw( RDBErr( ss.str( ) ) );
01713   }
01714 
01715   try {
01716     _cols[idx]->mapData( data, nelems );
01717 
01718   } catch ( RDBErr& e ) {
01719     e.set_message( "RDB::mapData:  error with file '" + _filename + "':  " );
01720     throw( e );
01721 
01722   } catch ( ... ) {
01723     throw( RDBErr( "RDB::mapData:  unexpected exception caught with file '" + _filename + "'" ) );
01724   }
01725 }
01726 
01735 void RDB::setData( const size_t idx, const double data ) throw ( RDBErr ) {
01736 
01737   if ( idx > (int)_ncols ) {
01738     stringstream ss;
01739     ss << "RDB::setData:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01740     throw( RDBErr( ss.str( ) ) );
01741   }
01742 
01743   try {
01744     _cols[idx]->setData( data );
01745 
01746   } catch ( RDBErr& e ) {
01747     e.set_message( "RDB::setData:  error with file '" + _filename + "':  " );
01748     throw( e );
01749 
01750   } catch ( ... ) {
01751     throw( RDBErr( "RDB::setData:  unexpected exception caught with file '" + _filename + "'" ) );
01752   }
01753 }
01754 
01763 void RDB::setData( const size_t idx, const long data ) throw ( RDBErr ) {
01764 
01765   if ( idx > (int)_ncols ) {
01766     stringstream ss;
01767     ss << "RDB::setData:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01768     throw( RDBErr( ss.str( ) ) );
01769   }
01770 
01771   try {
01772     _cols[idx]->setData( data );
01773 
01774   } catch ( RDBErr& e ) {
01775     e.set_message( "RDB::setData:  error with file '" + _filename + "':  " );
01776     throw( e );
01777 
01778   } catch ( ... ) {
01779     throw( RDBErr( "RDB::setData:  unexpected exception caught with file '" + _filename + "'" ) );
01780   }
01781 }
01782 
01791 void RDB::setData( const size_t idx, const string& data ) throw ( RDBErr ) {
01792 
01793   if ( idx > (int)_ncols ) {
01794     stringstream ss;
01795     ss << "RDB::setData:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01796     throw( RDBErr( ss.str( ) ) );
01797   }
01798 
01799   try {
01800     _cols[idx]->setData( data );
01801 
01802   } catch ( RDBErr& e ) {
01803     e.set_message( "RDB::setData:  error with file '" + _filename + "':  " );
01804     throw( e );
01805 
01806   } catch ( ... ) {
01807     throw( RDBErr( "RDB::setData:  unexpected exception caught with file '" + _filename + "'" ) );
01808   }
01809 }
01810 
01818 void RDB::getName( const size_t idx, string& name ) const throw ( RDBErr ) {
01819 
01820   if ( idx > (int)_ncols ) {
01821     stringstream ss;
01822     ss << "RDB::getName:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01823     throw( RDBErr( ss.str( ) ) );
01824   }
01825 
01826   name = _cols[idx]->getName( );
01827 
01828 }
01829 
01837 void RDB::getDef( const size_t idx, string& def  ) throw ( RDBErr ) {
01838 
01839   if ( idx > (int)_ncols ) {
01840     stringstream ss;
01841     ss << "RDB::getDef:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01842     throw( RDBErr( ss.str( ) ) );
01843   }
01844 
01845   def = _cols[idx]->getDef( );
01846 
01847 }
01848 
01856 void RDB::getWidth( const size_t idx, long& width ) const throw ( RDBErr ) {
01857 
01858   if ( idx > (int)_ncols ) {
01859     stringstream ss;
01860     ss << "RDB::getWidth:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01861     throw( RDBErr( ss.str( ) ) );
01862   }
01863 
01864   width = _cols[idx]->getWidth( );
01865 
01866 }
01867 
01875 void RDB::getType( const size_t idx, RDBColumn::Type& type ) const throw ( RDBErr ) {
01876 
01877   if ( idx > (int)_ncols ) {
01878     stringstream ss;
01879     ss << "RDB::getType:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01880     throw( RDBErr( ss.str( ) ) );
01881   }
01882 
01883   type = _cols[idx]->getType( );
01884 
01885 }
01886 
01894 void RDB::getJust( const size_t idx, RDBColumn::Just& just ) const throw ( RDBErr ) {
01895 
01896   if ( idx > (int)_ncols ) {
01897     stringstream ss;
01898     ss << "RDB::getJust:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01899     throw( RDBErr( ss.str( ) ) );
01900   }
01901 
01902   just = _cols[idx]->getJust( );
01903 
01904 }
01905 
01913 void RDB::getDesc( const size_t idx, string& desc ) const throw ( RDBErr ) {
01914 
01915   if ( idx > (int)_ncols ) {
01916     stringstream ss;
01917     ss << "RDB::getDesc:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01918     throw( RDBErr( ss.str( ) ) );
01919   }
01920 
01921   desc = _cols[idx]->getDesc( );
01922 
01923 }
01924 
01933 void RDB::getData( const size_t idx, double& data ) throw ( RDBErr ) {
01934 
01935   if ( idx > (int)_ncols ) {
01936     stringstream ss;
01937     ss << "RDB::getData:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01938     throw( RDBErr( ss.str( ) ) );
01939   }
01940 
01941   try {
01942     data = _cols[idx]->getDataDouble( );
01943 
01944   } catch ( RDBErr& e ) {
01945     e.set_message( "RDB::getData:  error with file '" + _filename + "':  " );
01946     throw( e );
01947 
01948   } catch ( ... ) {
01949     throw( RDBErr( "RDB::getData:  unexpected exception caught with file '" + _filename + "'" ) );
01950   }
01951 }
01952 
01961 void RDB::getData( const size_t idx, long& data ) throw ( RDBErr ) {
01962 
01963   if ( idx > (int)_ncols ) {
01964     stringstream ss;
01965     ss << "RDB::getData:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01966     throw( RDBErr( ss.str( ) ) );
01967   }
01968 
01969   try {
01970     data = _cols[idx]->getDataLong( );
01971 
01972   } catch ( RDBErr& e ) {
01973     e.set_message( "RDB::getData:  error with file '" + _filename + "':  " );
01974     throw( e );
01975 
01976   } catch ( ... ) {
01977     throw( RDBErr( "RDB::getData:  unexpected exception caught with file '" + _filename + "'" ) );
01978   }
01979 }
01980 
01989 void RDB::getData( const size_t idx, string& data ) throw ( RDBErr ) {
01990 
01991   if ( idx > (int)_ncols ) {
01992     stringstream ss;
01993     ss << "RDB::getData:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
01994     throw( RDBErr( ss.str( ) ) );
01995   }
01996 
01997   try {
01998     data = _cols[idx]->getDataString( );
01999 
02000   } catch ( RDBErr& e ) {
02001     e.set_message( "RDB::getData:  error with file '" + _filename + "':  " );
02002     throw( e );
02003 
02004   } catch ( ... ) {
02005     throw( RDBErr( "RDB::getData:  unexpected exception caught with file '" + _filename + "':  " ) );
02006   }
02007 }
02008 
02017 string RDB::getName( const size_t idx ) const throw ( RDBErr ) {
02018 
02019   if ( idx > (int)_ncols ) {
02020     stringstream ss;
02021     ss << "RDB::getName:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
02022     throw( RDBErr( ss.str( ) ) );
02023   }
02024 
02025   return _cols[idx]->getName( );
02026 
02027 }
02028 
02037 string RDB::getDef( const size_t idx  ) throw ( RDBErr ) {
02038 
02039   if ( idx > (int)_ncols ) {
02040     stringstream ss;
02041     ss << "RDB::getDef:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
02042     throw( RDBErr( ss.str( ) ) );
02043   }
02044 
02045   return _cols[idx]->getDef( );
02046 
02047 }
02048 
02057 long RDB::getWidth( const size_t idx ) const throw ( RDBErr ) {
02058 
02059   if ( idx > (int)_ncols ) {
02060     stringstream ss;
02061     ss << "RDB::getWidth:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
02062     throw( RDBErr( ss.str( ) ) );
02063   }
02064 
02065   return _cols[idx]->getWidth( );
02066 
02067 }
02068 
02077 RDBColumn::Type RDB::getType( const size_t idx ) const throw ( RDBErr ) {
02078 
02079   if ( idx > (int)_ncols ) {
02080     stringstream ss;
02081     ss << "RDB::getType:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
02082     throw( RDBErr( ss.str( ) ) );
02083   }
02084 
02085   return _cols[idx]->getType( );
02086 
02087 }
02088 
02097 RDBColumn::Just RDB::getJust( const size_t idx ) const throw ( RDBErr ) {
02098 
02099   if ( idx > (int)_ncols ) {
02100     stringstream ss;
02101     ss << "RDB::getJust:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
02102     throw( RDBErr( ss.str( ) ) );
02103   }
02104 
02105   return _cols[idx]->getJust( );
02106 
02107 }
02108 
02117 string RDB::getDesc( const size_t idx ) const throw ( RDBErr ) {
02118 
02119   if ( idx > (int)_ncols ) {
02120     stringstream ss;
02121     ss << "RDB::getDesc:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
02122     throw( RDBErr( ss.str( ) ) );
02123   }
02124 
02125   return _cols[idx]->getDesc( );
02126 
02127 }
02128 
02138 double RDB::getDataDouble( const size_t idx ) throw ( RDBErr ) {
02139 
02140   if ( idx > (int)_ncols ) {
02141     stringstream ss;
02142     ss << "RDB::getDataDouble:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
02143     throw( RDBErr( ss.str( ) ) );
02144   }
02145 
02146   try {
02147     return _cols[idx]->getDataDouble( );
02148 
02149   } catch ( RDBErr& e ) {
02150     e.set_message( "RDB::getDataDouble:  error with file '" + _filename + "':  " );
02151     throw( e );
02152 
02153   } catch ( ... ) {
02154     throw( RDBErr( "RDB::getDataDouble:  unexpected exception caught with file '" + _filename + "':" ) );
02155   }
02156 }
02157 
02167 long RDB::getDataLong( const size_t idx ) throw ( RDBErr ) {
02168 
02169   if ( idx > (int)_ncols ) {
02170     stringstream ss;
02171     ss << "RDB::getDataLong:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
02172     throw( RDBErr( ss.str( ) ) );
02173   }
02174 
02175   try {
02176     return _cols[idx]->getDataLong( );
02177 
02178   } catch ( RDBErr& e ) {
02179     e.set_message( "RDB::getDataLong:  error with file '" + _filename + "':  " );
02180     throw( e );
02181 
02182   } catch ( ... ) {
02183     throw( RDBErr( "RDB::getDataLong:  unexpected exception caught with file '" + _filename + "':" ) );
02184   }
02185 }
02186 
02196 string RDB::getDataString( const size_t idx ) throw ( RDBErr ) {
02197 
02198   if ( idx > (int)_ncols ) {
02199     stringstream ss;
02200     ss << "RDB::getDataString:  error with file '" << _filename << "':  index out of range [0," << idx << ")";
02201     throw( RDBErr( ss.str( ) ) );
02202   }
02203 
02204   try {
02205     return _cols[idx]->getDataString( );
02206 
02207   } catch ( RDBErr& e ) {
02208     e.set_message( "RDB::getDataString:  error with file '" + _filename + "':  " );
02209     throw( e );
02210 
02211   } catch ( ... ) {
02212     throw( RDBErr( "RDB::getDataString:  unexpected exception caught with file '" + _filename + "':" ) );
02213   }
02214 }
02215 
02224 void RDB::setName( const string& name, const string& newname ) throw ( RDBErr ) {
02225 
02226   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02227     if ( name == _cols[jdx]->getName( ) ) {
02228       _cols[jdx]->setName( newname );
02229       return;
02230 
02231     }
02232   }
02233 
02234   if ( "_NR" != name ) {
02235     throw ( RDBErr( string("RDB::setName(string&,string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02236   }
02237   
02238   _nrcol.setName( newname );
02239   
02240 }
02241 
02250 void RDB::setDef( const string& name, const string& def  ) throw ( RDBErr ) {
02251 
02252   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02253     if ( name == _cols[jdx]->getName( ) ) {
02254       try {
02255         _cols[jdx]->setDef( def );
02256         
02257       } catch ( RDBErr& e ) {
02258         e.set_message( "RDB::setDef:  error with file '" + _filename + "':  " );
02259         throw( e );
02260         
02261       } catch ( ... ) {
02262         throw( RDBErr( "RDB::setDef:  unexpected exception caught with file '" + _filename + "':" ) );
02263       }
02264 
02265       return;
02266       
02267     }
02268   }
02269 
02270   if ( "_NR" != name ) {
02271     throw ( RDBErr( string("RDB::setDef(string&,string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02272   }
02273 
02274   _nrcol.setDef( def );
02275 }
02276 
02285 void RDB::setWidth( const string& name, const long width ) throw ( RDBErr ) {
02286 
02287   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02288     if ( name == _cols[jdx]->getName( ) ) {
02289       try {
02290         _cols[jdx]->setWidth( width );
02291         
02292       } catch ( RDBErr& e ) {
02293         e.set_message( "RDB::setWidth:  error with file '" + _filename + "':  " );
02294         throw( e );
02295         
02296       } catch ( ... ) {
02297         throw( RDBErr( "RDB::setWidth:  unexpected exception caught with file '" + _filename + "':" ) );
02298       }
02299 
02300       return;
02301       
02302     }
02303   }
02304 
02305   if ( "_NR" != name ) {
02306   throw ( RDBErr( string("RDB::setWidth(string&,long):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02307   }
02308   
02309   _nrcol.setWidth( width );
02310 }
02311 
02320 void RDB::setType( const string& name, const RDBColumn::Type type ) throw ( RDBErr ) {
02321 
02322   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02323     if ( name == _cols[jdx]->getName( ) ) {
02324       try {
02325         _cols[jdx]->setType( type );
02326         
02327       } catch ( RDBErr& e ) {
02328         e.set_message( "RDB::setType:  error with file '" + _filename + "':  " );
02329         throw( e );
02330         
02331       } catch ( ... ) {
02332         throw( RDBErr( "RDB::setType:  error with file '" + _filename + "':  unexpected exception caught" ) );
02333       }
02334 
02335       return;
02336 
02337     }
02338   }
02339 
02340   if ( "_NR" != name ) {
02341   throw ( RDBErr( string("RDB::setType(string&,RDBColumn::Type):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02342   }
02343   
02344   _nrcol.setType( type );
02345 }
02346 
02355 void RDB::setJust( const string& name, const RDBColumn::Just just ) throw ( RDBErr ) {
02356 
02357   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02358     if ( name == _cols[jdx]->getName( ) ) {
02359       try {
02360         _cols[jdx]->setJust( just );
02361         
02362       } catch ( RDBErr& e ) {
02363         e.set_message( "RDB::setJust:  error with file '" + _filename + "':  " );
02364         throw( e );
02365         
02366       } catch ( ... ) {
02367         throw( RDBErr( "RDB::setJust:  error with file '" + _filename + "':  unexpected exception caught" ) );
02368       }
02369 
02370       return;
02371 
02372     }
02373   }
02374 
02375   if ( "_NR" != name ) {
02376   throw ( RDBErr( string("RDB::setJust(string&,RDBColumn::Just):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02377   }
02378   
02379   _nrcol.setJust( just );
02380 }
02381 
02390 void RDB::setDesc( const string& name, const string& desc ) throw ( RDBErr ) {
02391 
02392   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02393     if ( name == _cols[jdx]->getName( ) ) {
02394       try {
02395         _cols[jdx]->setDesc( desc );
02396         
02397       } catch ( RDBErr& e ) {
02398         e.set_message( "RDB::setDesc:  error with file '" + _filename + "':  " );
02399         throw( e );
02400         
02401       } catch ( ... ) {
02402         throw( RDBErr( "RDB::setDesc:  error with file '" + _filename + "':  unexpected exception caught" ) );
02403       }
02404 
02405       return;
02406 
02407     }
02408   }
02409 
02410   if ( "_NR" != name ) {
02411   throw ( RDBErr( string("RDB::setDesc(string&,string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02412   }
02413   
02414   _nrcol.setDesc( desc );
02415 }
02416 
02426 void RDB::mapData( const string& name, double data[], const size_t nelems ) throw ( RDBErr ) {
02427 
02428   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02429     if ( name == _cols[jdx]->getName( ) ) {
02430       try {
02431         _cols[jdx]->mapData( data, nelems );
02432         
02433       } catch ( RDBErr& e ) {
02434         e.set_message( "RDB::mapData:  error with file '" + _filename + "':  " );
02435         throw( e );
02436         
02437       } catch ( ... ) {
02438         throw( RDBErr( "RDB::mapData:  error with file '" + _filename + "':  unexpected exception caught" ) );
02439       }
02440 
02441       return;
02442       
02443     }
02444   }
02445 
02446   if ( "_NR" != name ) {
02447     throw ( RDBErr( string("RDB::mapData(string&,double[],size_t):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02448   } else {
02449     throw( RDBErr( "RDB::mapData('_NR',double[],size_t):  error with file '" + _filename + "':  mapping double[] to '_NR' column not allowed" ) );
02450   }
02451 }
02452 
02462 void RDB::mapData( const string& name, long data[], const size_t nelems ) throw ( RDBErr ) {
02463 
02464   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02465     if ( name == _cols[jdx]->getName( ) ) {
02466       try {
02467         _cols[jdx]->mapData( data, nelems );
02468         
02469       } catch ( RDBErr& e ) {
02470         e.set_message( "RDB::mapData:  error with file '" + _filename + "':  " );
02471         throw( e );
02472         
02473       } catch ( ... ) {
02474         throw( RDBErr( "RDB::mapData:  unexpected exception caught with file '" + _filename + "':" ) );
02475 
02476       }
02477 
02478       return;
02479       
02480     }
02481   }
02482 
02483   if ( "_NR" != name ) {
02484   throw ( RDBErr( string("RDB::mapData(string&,long[],size_t):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02485   }
02486 
02487   _nrcol.mapData( data, nelems );
02488 }
02489 
02499 void RDB::mapData( const string& name, string data[], const size_t nelems ) throw ( RDBErr ) {
02500 
02501   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02502     if ( name == _cols[jdx]->getName( ) ) {
02503       try {
02504         _cols[jdx]->mapData( data, nelems );
02505         
02506       } catch ( RDBErr& e ) {
02507         e.set_message( "RDB::mapData:  error with file '" + _filename + "':  " );
02508         throw( e );
02509         
02510       } catch ( ... ) {
02511         throw( RDBErr( "RDB::mapData:  unexpected exception caught with file '" + _filename + "':" ) );
02512       }
02513 
02514       return;
02515 
02516     }
02517   }
02518 
02519   if ( "_NR" != name ) {
02520   throw ( RDBErr( string("RDB::mapData(string&,string[],size_t):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02521   } else {
02522     throw( RDBErr( "RDB::mapData('_NR',string[],size_t):  error with file '" + _filename + "':  mapping string[] to '_NR' column not allowed" ) );
02523   }
02524 }
02525 
02534 void RDB::setData( const string& name, const double data ) throw ( RDBErr ) {
02535 
02536   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02537     if ( name == _cols[jdx]->getName( ) ) {
02538       try {
02539         _cols[jdx]->setData( data );
02540         
02541       } catch ( RDBErr& e ) {
02542         e.set_message( "RDB::setData:  error with file '" + _filename + "':  " );
02543         throw( e );
02544         
02545       } catch ( ... ) {
02546         throw( RDBErr( "RDB::setData:  unexpected exception caught with file '" + _filename + "':" ) );
02547       }
02548       return;
02549     }
02550   }
02551 
02552   if ( "_NR" != name ) {
02553   throw ( RDBErr( string("RDB::setData(string&,double):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02554   }
02555   
02556   _nrcol.setData( data );
02557 }
02558 
02567 void RDB::setData( const string& name, const long data ) throw ( RDBErr ) {
02568 
02569   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02570     if ( name == _cols[jdx]->getName( ) ) {
02571       try {
02572         _cols[jdx]->setData( data );
02573         
02574       } catch ( RDBErr& e ) {
02575         e.set_message( "RDB::setData:  error with file '" + _filename + "':  " );
02576         throw( e );
02577         
02578       } catch ( ... ) {
02579         throw( RDBErr( "RDB::setData:  unexpected exception caught with file '" + _filename + "':" ) );
02580       }
02581       return;
02582     }
02583   }
02584 
02585   if ( "_NR" != name ) {
02586   throw ( RDBErr( string("RDB::setData(string&,long):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02587   }
02588   
02589   _nrcol.setData( data );
02590 }
02591 
02600 void RDB::setData( const string& name, const string& data ) throw ( RDBErr ) {
02601 
02602   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02603     if ( name == _cols[jdx]->getName( ) ) {
02604       try {
02605         _cols[jdx]->setData( data );
02606         
02607       } catch ( RDBErr& e ) {
02608         e.set_message( "RDB::setData:  error with file '" + _filename + "':  " );
02609         throw( e );
02610 
02611       } catch ( ... ) {
02612         throw( RDBErr( "RDB::setData:  unexpected exception caught with file '" + _filename + "':" ) );
02613       }
02614       return;
02615       
02616     }
02617   }
02618 
02619   if ( "_NR" != name ) {
02620   throw ( RDBErr( string("RDB::setData(string&,string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02621   }
02622   
02623   _nrcol.setData( data );
02624 }
02625 
02633 void RDB::getName( const string& name, string& namefound ) const throw ( RDBErr ) {
02634 
02635   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02636     if ( name == _cols[jdx]->getName( ) ) {
02637       namefound = _cols[jdx]->getName( );
02638       return;
02639 
02640     }
02641   }
02642 
02643   if ( "_NR" != name ) {
02644     throw ( RDBErr( string("RDB::getName(string&,string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02645   }
02646   
02647   namefound = _nrcol.getName( );
02648 }
02649 
02657 void RDB::getDef( const string& name, string& def  ) throw ( RDBErr ) {
02658 
02659   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02660     if ( name == _cols[jdx]->getName( ) ) {
02661       def = _cols[jdx]->getDef( );
02662       return;
02663       
02664     }
02665   }
02666 
02667   if ( "_NR" != name ) {
02668     throw ( RDBErr( string("RDB::getDef(string&,string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02669   }
02670   
02671   def = _nrcol.getDef(  );
02672 }
02673 
02681 void RDB::getWidth( const string& name, long& width ) const throw ( RDBErr ) {
02682 
02683   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02684     if ( name == _cols[jdx]->getName( ) ) {
02685       width = _cols[jdx]->getWidth( );
02686       return;
02687       
02688     }
02689   }
02690 
02691   if ( "_NR" != name ) {
02692     throw ( RDBErr( string("RDB::getWidth(string&,long):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02693   }
02694   
02695   width = _nrcol.getWidth( );
02696 }
02697 
02705 void RDB::getType( const string& name, RDBColumn::Type& type ) const throw ( RDBErr ) {
02706 
02707   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02708     if ( name == _cols[jdx]->getName( ) ) {
02709       type = _cols[jdx]->getType( );
02710       return;
02711       
02712     }
02713   }
02714 
02715   if ( "_NR" != name ) {
02716     throw ( RDBErr( string("RDB::getType(string&,RDBColumn::Type):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02717   }
02718   
02719   type = _nrcol.getType( );
02720 }
02721 
02729 void RDB::getJust( const string& name, RDBColumn::Just& just ) const throw ( RDBErr ) {
02730 
02731   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02732     if ( name == _cols[jdx]->getName( ) ) {
02733       just = _cols[jdx]->getJust( );
02734       return;
02735 
02736     }
02737   }
02738 
02739   if ( "_NR" != name ) {
02740     throw ( RDBErr( string("RDB::getJust(string&,RDBColumn::Just):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02741   }
02742   
02743   just = _nrcol.getJust( );
02744 }
02745 
02753 void RDB::getDesc( const string& name, string& desc ) const throw ( RDBErr ) {
02754 
02755   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02756     if ( name == _cols[jdx]->getName( ) ) {
02757       desc = _cols[jdx]->getDesc( );
02758       return;
02759       
02760     }
02761   }
02762 
02763   if ( "_NR" != name ) {
02764     throw ( RDBErr( string("RDB::getDesc(string&,string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02765   }
02766   
02767   desc = _nrcol.getDesc( );
02768 }
02769 
02778 void RDB::getData( const string& name, double& data ) throw ( RDBErr ) {
02779 
02780   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02781     if ( name == _cols[jdx]->getName( ) ) {
02782       try {
02783         data = _cols[jdx]->getDataDouble( );
02784         
02785       } catch ( RDBErr& e ) {
02786         e.set_message( "RDB::getData:  error with file '" + _filename + "':  " );
02787         throw( e );
02788         
02789       } catch ( ... ) {
02790         throw( RDBErr( "RDB::getData:  unexpected exception caught with file '" + _filename + "':" ) );
02791       }
02792       return;
02793       
02794     }
02795   }
02796   
02797   if ( "_NR" != name ) {
02798     throw ( RDBErr( string("RDB::getData(string&,double):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02799   }
02800   
02801   data = _nrcol.getDataDouble( );
02802 }
02803 
02812 void RDB::getData( const string& name, long& data ) throw ( RDBErr ) {
02813 
02814   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02815     if ( name == _cols[jdx]->getName( ) ) {
02816       try {
02817         data = _cols[jdx]->getDataLong( );
02818         
02819       } catch ( RDBErr& e ) {
02820         e.set_message( "RDB::getData:  error with file '" + _filename + "':  " );
02821         throw( e );
02822         
02823       } catch ( ... ) {
02824         throw( RDBErr( "RDB::getData:  unexpected exception caught with file '" + _filename + "':" ) );
02825       }
02826       return;
02827       
02828     }
02829   }
02830   
02831   if ( "_NR" != name ) {
02832     throw ( RDBErr( string("RDB::getData(string&,long&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02833   }
02834   
02835   data = _nrcol.getDataLong( );
02836 }
02837 
02846 void RDB::getData( const string& name, string& data ) throw ( RDBErr ) {
02847 
02848   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02849     if ( name == _cols[jdx]->getName( ) ) {
02850       try {
02851         data = _cols[jdx]->getDataString( );
02852         
02853       } catch ( RDBErr& e ) {
02854         e.set_message( "RDB::getData:  error with file '" + _filename + "':  " );
02855         throw( e );
02856         
02857       } catch ( ... ) {
02858         throw( RDBErr( "RDB::getData:  unexpected exception caught with file '" + _filename + "':" ) );
02859       }
02860       return;
02861       
02862     }
02863   }
02864 
02865   if ( "_NR" != name ) {
02866     throw ( RDBErr( string("RDB::getData(string&,string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02867   }
02868   
02869   data = _nrcol.getDataString( );
02870 }
02871 
02880 string RDB::getName( const string& name ) const throw ( RDBErr ) {
02881 
02882   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02883     if ( name == _cols[jdx]->getName( ) ) {
02884       return _cols[jdx]->getName( );
02885 
02886     }
02887   }
02888 
02889   if ( "_NR" != name ) {
02890     throw ( RDBErr( string("RDB::getName(string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02891   }
02892   
02893   return _nrcol.getName( );
02894 }
02895 
02904 string RDB::getDef( const string& name  ) throw ( RDBErr ) {
02905 
02906   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02907     if ( name == _cols[jdx]->getName( ) ) {
02908       return _cols[jdx]->getDef( );
02909 
02910     }
02911   }
02912 
02913   if ( "_NR" != name ) {
02914     throw ( RDBErr( string("RDB::getDef(string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02915   }
02916   
02917   return _nrcol.getDef( );
02918 }
02919 
02928 long RDB::getWidth( const string& name ) const throw ( RDBErr ) {
02929 
02930   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02931     if ( name == _cols[jdx]->getName( ) ) {
02932       return _cols[jdx]->getWidth( );
02933 
02934     }
02935   }
02936 
02937   if ( "_NR" != name ) {
02938     throw ( RDBErr( string("RDB::getWidth(string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02939   }
02940   
02941   return _nrcol.getWidth( );
02942 }
02943 
02952 RDBColumn::Type RDB::getType( const string& name ) const throw ( RDBErr ) {
02953 
02954   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02955     if ( name == _cols[jdx]->getName( ) ) {
02956       return _cols[jdx]->getType( );
02957 
02958     }
02959   }
02960 
02961   if ( "_NR" != name ) {
02962     throw ( RDBErr( string("RDB::getType(string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02963   }
02964   
02965   return _nrcol.getType( );
02966 }
02967 
02976 RDBColumn::Just RDB::getJust( const string& name ) const throw ( RDBErr ) {
02977 
02978   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
02979     if ( name == _cols[jdx]->getName( ) ) {
02980       return _cols[jdx]->getJust( );
02981 
02982     }
02983   }
02984 
02985   if ( "_NR" != name ) {
02986     throw ( RDBErr( string("RDB::getJust(string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
02987   }
02988   
02989   return _nrcol.getJust( );
02990 }
02991 
03000 string RDB::getDesc( const string& name ) const throw ( RDBErr ) {
03001 
03002   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
03003     if ( name == _cols[jdx]->getName( ) ) {
03004       return _cols[jdx]->getDesc( );
03005 
03006     }
03007   }
03008   
03009   if ( "_NR" != name ) {
03010     throw ( RDBErr( string("RDB::getDesc(string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
03011   }
03012   
03013   return _nrcol.getDesc( );
03014 }
03015 
03025 double RDB::getDataDouble( const string& name ) throw ( RDBErr ) {
03026 
03027   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
03028     if ( name == _cols[jdx]->getName( ) ) {
03029       try {
03030         return _cols[jdx]->getDataDouble( );
03031         
03032       } catch ( RDBErr& e ) {
03033         e.set_message( "RDB::getDataDouble:  error with file '" + _filename + "':  " );
03034         throw( e );
03035         
03036       } catch ( ... ) {
03037         throw( RDBErr( "RDB::getDataDouble:  unexpected exception caught with file '" + _filename + "':" ) );
03038       }
03039     }
03040   }
03041 
03042   if ( "_NR" != name ) {
03043   throw ( RDBErr( string("RDB::getDataDouble(string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
03044   }
03045   
03046   return _nrcol.getDataDouble( );
03047 }
03048 
03058 long RDB::getDataLong( const string& name ) throw ( RDBErr ) {
03059 
03060   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
03061     if ( name == _cols[jdx]->getName( ) ) {
03062       try {
03063         return _cols[jdx]->getDataLong( );
03064         
03065       } catch ( RDBErr& e ) {
03066         e.set_message( "RDB::getDataLong:  error with file '" + _filename + "':  " );
03067         throw( e );
03068         
03069       } catch ( ... ) {
03070         throw( RDBErr( "RDB::getDataLong:  unexpected exception caught with file '" + _filename + "':" ) );
03071       }
03072     }
03073   }
03074 
03075   if ( "_NR" != name ) {
03076   throw ( RDBErr( string("RDB::getDataLong(string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
03077   }
03078   
03079   return _nrcol.getDataLong( );
03080 }
03081 
03091 string RDB::getDataString( const string& name ) throw ( RDBErr ) {
03092 
03093   for ( size_t jdx = 0; jdx < _ncols; jdx++ ) {
03094     if ( name == _cols[jdx]->getName( ) ) {
03095       try {
03096         return _cols[jdx]->getDataString( );
03097         
03098       } catch ( RDBErr& e ) {
03099         e.set_message( "RDB::getDataString:  error with file '" + _filename + "':  " );
03100         throw( e );
03101         
03102       } catch ( ... ) {
03103         throw( RDBErr( "RDB::getDataString:  unexpected exception caught with file '" + _filename + "':" ) );
03104       }
03105     }
03106   }
03107 
03108   if ( "_NR" != name ) {
03109     throw ( RDBErr( string("RDB::getDataString(string&):  error with file '" + _filename + "':  Column ") + name + " not found" ) );
03110   }
03111   
03112   return _nrcol.getDataString( );
03113 }
03114 
03119 size_t
03120 RDB::nComments( 
03121   void
03122   ) const { 
03123 
03124   return _ncomms;
03125 
03126 }
03127 
03132 size_t
03133 RDB::nColumns( 
03134   void
03135   ) const { 
03136 
03137   return _ncols;
03138 
03139 }
03140 
03150 size_t
03151 RDB::nRows(
03152   void
03153   ) { 
03154 
03155   if ( ! _knowrows ) {
03156     _nrows = 0;
03157     long position;
03158 
03159     if ( ios::in & _mode && _isptr ) {
03160       _isptr->clear( );
03161 
03162       position = _isptr->tellg( );
03163       _isptr->seekg( _rewindto );
03164 
03165       while ( EOF != _isptr->peek( ) && getline( *_isptr, _line, '\n' ) )
03166         _nrows++;
03167     
03168       _knowrows = true;
03169       _isptr->clear( );
03170       _isptr->seekg( position );
03171 
03172     }   
03173   }    
03174 
03175   return _nrows;
03176 
03177 }
03178 
03184 void 
03185 RDB::parseHeader( 
03186   void
03187   ) throw ( RDBErr ) {
03188 
03189   string line0, line1;
03190   getline( *_isptr, line0, '\n' );
03191 
03192   while ( suplib::iscomment( line0 ) ) {
03193     try { 
03194       RDBComment tmpcomm(line0);
03195       setComment( tmpcomm, -1 );
03196 
03197     } catch ( RDBErr& e ) {
03198       stringstream ss;
03199       ss << "RDB::parseHeader(void):  error at comment " << _ncomms + _nrows << ":  ";
03200       e.set_message( ss.str( ) );
03201       throw( e );
03202 
03203     } catch ( ... ) {
03204       stringstream ss;
03205       ss << "RDB::parseHeader(void):  unexpected exception caught at comment " << _ncomms + _nrows ;
03206       throw( RDBErr( ss.str( ) ) );
03207 
03208     }
03209 
03210     line0.erase( );
03211     getline( *_isptr, line0, '\n' );
03212   }
03213 
03214   getline( *_isptr, line1, '\n' );
03215   vector<string> nametokens;
03216   vector<string> deftokens; 
03217   suplib::tok( nametokens, line0, "\t", false );
03218   suplib::tok( deftokens,  line1, "\t", false );
03219 
03220   if ( nametokens.size( ) != deftokens.size( ) ) {
03221     stringstream ss;
03222     ss << "RDB::parseHeader(void):  Number of names(" << nametokens.size( ) << ") " << (nametokens.size() > deftokens.size() ? "greater" : "less") << " than number of definitions(" << deftokens.size( ) << ")";
03223     throw( RDBErr( ss.str( ) ) );
03224 
03225   } else {
03226     _ncols = nametokens.size( );
03227 
03228     if ( _cols ) {
03229       for ( size_t idx = 0; idx < _ncols; idx++ ) {
03230         if ( _mycols[idx] ) {
03231           delete _cols[idx]; 
03232 
03233         }
03234       }
03235       delete [] _cols;
03236       delete [] _mycols;
03237 
03238     }
03239 
03240     _cols   = new RDBColumn*[_ncols];
03241     _mycols = new bool[_ncols];
03242 
03243     size_t idx;
03244     size_t typepos;
03245     for ( idx = 0; idx < _ncols; idx++ ) {
03246       try { 
03247         if ( deftokens[idx].npos != (typepos = deftokens[idx].find_first_not_of( "0123456789" )) && 'N' == deftokens[idx][typepos] ) {
03248           _cols[idx] 
03249             = new RDBDoubleColumn( nametokens[idx], deftokens[idx] );
03250           
03251         } else {
03252           _cols[idx] 
03253             = new RDBStringColumn( nametokens[idx], deftokens[idx] );
03254           
03255         }
03256       } catch ( RDBErr& rdberr ) {
03257         rdberr.set_message( "RDB::parseHeader(void):  column definition error:  " );
03258         throw( rdberr );
03259         
03260       } catch ( ... ) {
03261         throw( RDBErr( "RDB::parse::Header(void):  unexpected exception caught" ) );
03262         
03263       }
03264 
03265       _mycols[idx] = true;
03266 
03267     }
03268   }
03269 
03270   _rownum   = 0;
03271   _rewindto = _isptr->tellg( );
03272 
03273 }
03274 
03283 vector<string>
03284 RDB::parseLine( 
03285   const string& line
03286   ) const {
03287 
03288   vector<string> tokens;
03289   if ( ! line.empty( ) ) {
03290     size_t st0 = 0, st1 = 0;
03291 
03292     do {
03293       st1 = line.find( '\t', st0 );
03294       if ( line.size( ) < st1 ) {
03295         st1 = line.size( );
03296 
03297       }
03298 
03299       tokens.push_back( line.substr( st0, st1 - st0 ) );
03300       st0 = st1 + 1;
03301 
03302     } while ( line.size( ) > st1 );
03303   }
03304 
03305   return tokens;
03306 
03307 }
03308 
03315 size_t
03316 RDB::parseLine(
03317   bool& newgroup
03318   ) throw ( RDBErr ) { 
03319 
03320   size_t ntoks = 0;
03321   size_t begin = 0;
03322   size_t end   = _line.find( '\t' );
03323 
03324   try {
03325     do {
03326       end = _line.find( '\t', begin );
03327 
03328       _cols[ntoks]->setData( _line.substr( begin, end - begin ) );
03329 
03330       if ( RBOG & _cols[ntoks]->newGroup( ) )
03331         newgroup = true;
03332 
03333       ntoks++;
03334       begin = end + 1;
03335 
03336     } while (  _line.npos != end );
03337 
03338   } catch ( RDBErr& rdberr ) {
03339     stringstream ss;
03340     ss << "RDB::parseLine(void):  error at row " << _rownum << ":  ";
03341     rdberr.set_message( ss.str( ) );
03342     throw( rdberr );
03343 
03344   } catch ( ... ) {
03345     stringstream ss;
03346     ss << "RDB::parseLine(void):  unexpected exception caught at row " << _rownum;
03347     throw( RDBErr( ss.str( ) ) );
03348 
03349   }
03350 
03351   return ntoks;
03352 
03353 }

Generated on Tue Sep 15 11:07:16 2009 for rdbxx by  doxygen 1.5.6