RDBColumnTmplt.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 #define RDBColumnTmplt_cc
00026 
00027 #include <rdbxx/RDBColumnTmplt.h>
00028 
00036 template<class Tmplt0,class Tmplt1,class Tmplt2>
00037 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::RDBColumnTmplt( 
00038   const string& name,
00039   const string& def
00040   ) throw ( RDBErr )
00041   : RDBColumn(name,def) {  
00042 
00043   _nelems = 2;
00044   _data   = new Tmplt0[_nelems];
00045   _idx    = 0;
00046   _mine   = true;
00047 
00048 }
00049 
00057 template<class Tmplt0,class Tmplt1,class Tmplt2>
00058 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::RDBColumnTmplt( 
00059   const RDBColumnTmplt& col
00060   ) 
00061   : RDBColumn(col) {
00062 
00063   _nelems = col._nelems;
00064   _data   = new Tmplt0[_nelems];
00065   _idx    = col._idx;
00066   _mine   = true;
00067 
00068 }
00069 
00075 template<class Tmplt0,class Tmplt1,class Tmplt2>
00076 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::~RDBColumnTmplt( 
00077   void 
00078   ) {
00079 
00080   cleanup( );
00081 
00082 }
00083 
00091 template<class Tmplt0,class Tmplt1,class Tmplt2>
00092 RDBColumn& 
00093 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::operator=( 
00094   const RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>& col 
00095   ) {
00096 
00097   if ( this != &col ) {
00098     RDBColumn::operator=( col );
00099 
00100     cleanup( );
00101 
00102     _nelems = col._nelems;
00103     _data   = col._data;
00104     _idx    = col._idx;
00105     _mine   = false;
00106 
00107     if ( _group && 2 > _nelems ) 
00108       throw( RDBErr( "RDBColumnTmplt::operator=(RDBColumnTmplt&):  user supplied column must provide >= 2 data elements" ) );      
00109 
00110   }
00111 
00112   return *this;
00113 
00114 }
00115 
00122 template<class Tmplt0,class Tmplt1,class Tmplt2>
00123 RDBColumn& 
00124 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::operator=( 
00125   const Tmplt0& data 
00126   ) throw ( RDBErr ) {
00127 
00128   try { 
00129     convert( data, _data[_idx] );
00130 
00131   } catch ( RDBErr& rdberr ) {
00132     rdberr.set_message( "RDBColumnTmplt::operator=(Tmplt0&):  " );
00133     throw( rdberr );
00134     
00135   } catch ( ... ) { 
00136     throw( RDBErr( "RDBColumnTmplt::operator=(Tmplt0&):  unexpected exception caught" ) );
00137     
00138   }
00139 
00140   return *this;
00141 
00142 }
00143 
00153 template<class Tmplt0,class Tmplt1,class Tmplt2>
00154 RDBColumn& 
00155 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::operator=( 
00156   const Tmplt1& data 
00157   ) throw ( RDBErr ) {
00158 
00159   try { 
00160     convert( data, _data[_idx] );
00161 
00162   } catch ( RDBErr& rdberr ) {
00163     rdberr.set_message( "RDBColumnTmplt::operator=(Tmplt1&):  " );
00164     throw( rdberr );
00165     
00166   } catch ( ... ) { 
00167     throw( RDBErr( "RDBColumnTmplt::operator=(Tmplt1&):  unexpected exception caught" ) );
00168     
00169   }
00170 
00171   return *this;
00172 
00173 }
00174 
00184 template<class Tmplt0,class Tmplt1,class Tmplt2>
00185 RDBColumn& 
00186 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::operator=( 
00187   const Tmplt2& data 
00188   ) throw ( RDBErr ) {
00189 
00190   try {
00191     convert( data, _data[_idx] );
00192     
00193   } catch ( RDBErr& rdberr ) {
00194     rdberr.set_message( "RDBColumnTmplt::operator=(Tmplt2&):  " );
00195     throw( rdberr );
00196     
00197   } catch ( ... ) { 
00198     throw( RDBErr( "RDBColumnTmplt::operator=(Tmplt2&):  unexpected exception caught" ) );
00199     
00200   }
00201 
00202   return *this;
00203 
00204 }
00205 
00210 template<class Tmplt0,class Tmplt1,class Tmplt2>
00211 void
00212 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::advanceIdx(
00213   void
00214   ) {
00215 
00216   if ( _nelems == ++_idx ) {
00217     _idx  = 0;
00218 
00219   }
00220 }
00221 
00226 template<class Tmplt0,class Tmplt1,class Tmplt2>
00227 void
00228 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::rewind(
00229   void
00230   ) {
00231 
00232   _idx = 0;
00233 
00234 }
00235 
00240 template<class Tmplt0,class Tmplt1,class Tmplt2>
00241 void
00242 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::setGroup( 
00243   bool group
00244   ) {
00245   
00246   RDBColumn::setGroup( group );
00247   if ( _mine ) {
00248     if ( 2 > _nelems ) {
00249       Tmplt0* tmp = _data;
00250       _nelems     = 2;
00251       _data       = new Tmplt0[_nelems];
00252       _data[0]    = tmp[_idx];
00253       _data[1]    = tmp[_idx];
00254       delete [] tmp;    
00255     }
00256   } else if ( 2 > _nelems ) {
00257     throw( RDBErr( "RDBColumnTmplt::setGroup(bool):  user supplied column must provide >= 2 data elements" ) );
00258 
00259   }
00260 }
00261 
00266 template<class Tmplt0,class Tmplt1,class Tmplt2>
00267 void
00268 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::setGroupValue(
00269   void
00270   ) {
00271 
00272   if ( _group ) {
00273     _data[(_idx+1)%_nelems] = _groupvalue;
00274     _groupvalue = _data[_idx];
00275   }
00276 
00277 }
00278 
00283 template<class Tmplt0,class Tmplt1,class Tmplt2>
00284 int
00285 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::newGroup(
00286   void
00287   ) {
00288 
00289   if ( _group ) {
00290     if ( _initgroup ) {
00291       _initgroup = false;
00292       _data[_idx] = _groupvalue;
00293       _groupvalue = _data[(_idx+1)%_nelems];
00294       return RDBColumn::CBOG;
00295 
00296     } else {
00297       int status = RDBColumn::CMOG;
00298       
00299       if ( _data[_idx] != _groupvalue )
00300         status |= RDBColumn::CBOG;
00301 
00302       if ( _data[_idx] != _data[(_idx+1)%_nelems] )
00303         status |= RDBColumn::CEOG;
00304 
00305       _groupvalue = _data[_idx];
00306 
00307       return status;
00308     }
00309   }
00310 
00311   return RDBColumn::CMOG;
00312   
00313   /*
00314   if ( _group ) {
00315     if ( _initgroup ) {
00316       _initgroup  = false;
00317       _data[(_idx+1)%_nelems] = _groupvalue;
00318       _groupvalue = _data[_idx];
00319       return RDBColumn::CBOG;
00320 
00321     } else if ( _data[_idx] != _groupvalue ) {
00322       _data[(_idx+1)%_nelems] = _groupvalue;
00323       _groupvalue = _data[_idx];
00324       return RDBColumn::CBOG;
00325 
00326     }
00327   }
00328 
00329   return RDBColumn::CMOG;
00330   */
00331 }
00332 
00341 template<class Tmplt0,class Tmplt1,class Tmplt2>
00342 bool
00343 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::setData(
00344   const Tmplt0& data
00345   ) throw ( RDBErr ) {
00346 
00347   try {
00348     convert( data, _data[_idx] );
00349 
00350   } catch ( RDBErr& rdberr ) {
00351     rdberr.set_message( "RDBColumnTmplt::setData(Tmplt0&):  " );
00352     throw( rdberr );
00353     
00354   } catch ( ... ) { 
00355     throw( RDBErr( "RDBColumnTmplt::setData(Tmplt0&):  unexpected exception caught" ) );
00356     
00357   }
00358 
00359   return 0 == _errno;
00360 
00361 }
00362 
00374 template<class Tmplt0,class Tmplt1,class Tmplt2>
00375 bool
00376 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::setData(
00377   const Tmplt1& data
00378   ) throw ( RDBErr ) {
00379 
00380   try { 
00381     convert( data, _data[_idx] );
00382 
00383   } catch ( RDBErr& rdberr ) {
00384     rdberr.set_message( "RDBColumnTmplt::setData(Tmplt1&):  " );
00385     throw( rdberr );
00386     
00387   } catch ( ... ) { 
00388     throw( RDBErr( "RDBColumnTmplt::setData(Tmplt1&):  unexpected exception caught" ) );
00389     
00390   }
00391 
00392   return 0 == _errno;
00393 
00394 }
00395 
00407 template<class Tmplt0,class Tmplt1,class Tmplt2>
00408 bool
00409 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::setData(
00410   const Tmplt2& data
00411   ) throw ( RDBErr ) {
00412 
00413   try { 
00414     convert( data, _data[_idx] );
00415 
00416   } catch ( RDBErr& rdberr ) {
00417     rdberr.set_message( "RDBColumnTmplt::setData(Tmplt2&):  " );
00418     throw( rdberr );
00419     
00420   } catch ( ... ) { 
00421     throw( RDBErr( "RDBColumnTmplt::setData(Tmplt2&):  unexpected exception caught" ) );
00422     
00423   }
00424 
00425   return 0 == _errno;
00426 
00427 }
00428 
00438 template<class Tmplt0,class Tmplt1,class Tmplt2>
00439 void
00440 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::mapData(
00441   Tmplt0 data[], 
00442   const size_t nelems
00443   ) throw ( RDBErr ) {
00444 
00445   cleanup( );
00446 
00447   _nelems     = nelems;
00448   _data       = data;
00449   _idx        = _idx % _nelems;
00450   _mine       = false;
00451 
00452   if ( _group && 2 > _nelems ) 
00453     throw( RDBErr( "RDBColumnTmplt::mapData:  user supplied data must provide >= 2 data elements" ) );
00454 
00455 }
00456 
00464 template<class Tmplt0,class Tmplt1,class Tmplt2>
00465 void*
00466 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::getData( 
00467   void 
00468   ) { 
00469 
00470   return ((void *) &_data[_idx]);
00471 
00472 }
00473 
00482 template<class Tmplt0,class Tmplt1,class Tmplt2>
00483 bool
00484 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::getData(
00485   Tmplt0& data
00486   ) throw ( RDBErr ) {
00487 
00488   try { 
00489     convert( _data[_idx], data );
00490 
00491   } catch ( RDBErr& rdberr ) {
00492     rdberr.set_message( "RDBColumnTmplt::getData(Tmplt0&):  " );
00493     throw( rdberr );
00494     
00495   } catch ( ... ) { 
00496     throw( RDBErr( "RDBColumnTmplt::getData(Tmplt0&):  unexpected exception caught" ) );
00497     
00498   }
00499 
00500   return 0 == _errno;
00501 
00502 }
00503 
00515 template<class Tmplt0,class Tmplt1,class Tmplt2>
00516 bool
00517 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::getData(
00518   Tmplt1& data
00519   ) throw ( RDBErr ) {
00520 
00521   try { 
00522     convert( _data[_idx], data );
00523     
00524   } catch ( RDBErr& rdberr ) {
00525     rdberr.set_message( "RDBColumnTmplt::getData(Tmplt1&):  " );
00526     throw( rdberr );
00527     
00528   } catch ( ... ) { 
00529     throw( RDBErr( "RDBColumnTmplt::getData(Tmplt1&):  unexpected exception caught" ) );
00530     
00531   }
00532 
00533   return 0 == _errno;
00534 
00535 }
00536 
00548 template<class Tmplt0,class Tmplt1,class Tmplt2>
00549 bool
00550 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::getData(
00551   Tmplt2& data
00552   ) throw ( RDBErr ) {
00553 
00554   try {
00555     convert( _data[_idx], data );
00556 
00557   } catch ( RDBErr& rdberr ) {
00558     rdberr.set_message( "RDBColumnTmplt::getData(Tmplt2&):  " );
00559     throw( rdberr );
00560     
00561   } catch ( ... ) { 
00562     throw( RDBErr( "RDBColumnTmplt::getData(Tmplt2&):  unexpected exception caught" ) );
00563     
00564   }
00565 
00566   return 0 == _errno;
00567 
00568 }
00569 
00576 template<class Tmplt0,class Tmplt1,class Tmplt2>
00577 double
00578 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::getDataDouble(
00579   void
00580   ) throw ( RDBErr ) {
00581 
00582   double odata;
00583   try { 
00584     convert( _data[_idx], odata );
00585     
00586   } catch ( RDBErr& rdberr ) {
00587     rdberr.set_message( "RDBColumnTmplt::getDataDouble(void):  " );
00588     throw( rdberr );
00589     
00590   } catch ( ... ) { 
00591     throw( RDBErr( "RDBColumnTmplt::getDataDouble(void):  unexpected exception caught" ) );
00592     
00593   }
00594 
00595   return odata;
00596 
00597 }
00598 
00606 template<class Tmplt0,class Tmplt1,class Tmplt2>
00607 long
00608 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::getDataLong(
00609   void
00610   ) throw ( RDBErr ) {
00611 
00612   long odata;
00613   try {
00614     convert( _data[_idx], odata );
00615 
00616   } catch ( RDBErr& rdberr ) {
00617     rdberr.set_message( "RDBColumnTmplt::getDataLong(void):  " );
00618     throw( rdberr );
00619     
00620   } catch ( ... ) { 
00621     throw( RDBErr( "RDBColumnTmplt::getDataLong(void):  unexpected exception caught" ) );
00622     
00623   }
00624 
00625   return odata;
00626 
00627 }
00628 
00633 template<class Tmplt0,class Tmplt1,class Tmplt2>
00634 string
00635 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::getDataString(
00636   void
00637   ) throw ( RDBErr ) {
00638  
00639   string odata;  
00640   try { 
00641     convert( _data[_idx], odata );
00642     
00643   } catch ( RDBErr& rdberr ) {
00644     rdberr.set_message( "RDBColumnTmplt::getDataString(void):  " );
00645     throw( rdberr );
00646     
00647   } catch ( ... ) { 
00648     throw( RDBErr( "RDBColumnTmplt::getDataString(void):  unexpected exception caught" ) );
00649     
00650   }
00651 
00652   return odata;
00653 
00654 }
00655 
00664 template<class Tmplt0,class Tmplt1,class Tmplt2>
00665 istream&
00666 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::read( 
00667   istream& is
00668   )  throw ( RDBErr ) {
00669 
00670   try {
00671     extract( is, _data[_idx] );
00672 
00673   } catch ( RDBErr& rdberr ) {
00674     rdberr.set_message( "RDBColumnTmplt::read(istream&):  " );
00675     throw( rdberr );
00676     
00677   } catch ( ... ) { 
00678     throw( RDBErr( "RDBColumnTmplt::read(istream&):  unexpected exception caught" ) );
00679     
00680   }
00681 
00682   return is;
00683 
00684 }
00685 
00694 template<class Tmplt0,class Tmplt1,class Tmplt2>
00695 ostream&
00696 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::write(
00697   ostream& os
00698   ) const {
00699 
00700   return insert( os, _data[_idx] );
00701 
00702 }
00703 
00708 template<class Tmplt0,class Tmplt1,class Tmplt2>
00709 void
00710 RDBColumnTmplt<Tmplt0,Tmplt1,Tmplt2>::cleanup(
00711   void
00712   ) {
00713 
00714   if ( _mine && _data ) {
00715     delete [] _data;
00716 
00717   }
00718 }
00719 

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