DataSourceAdaptor.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Tue Apr 5 16:53:25 CEST 2005  DataSourceAdaptor.hpp
00003 
00004                         DataSourceAdaptor.hpp -  description
00005                            -------------------
00006     begin                : Tue April 05 2005
00007     copyright            : (C) 2005 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.ac.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/
00037 
00038 #include "DataSource.hpp"
00039 
00040 #ifndef DATASOURCE_ADAPTOR_HPP
00041 #define DATASOURCE_ADAPTOR_HPP
00042 
00043 namespace RTT
00044 {
00045     namespace detail {
00046 
00047         template<class From, class To>
00048         struct DataSourceAdaptor;
00049 
00050         template<class From, class To>
00051         struct AssignableDataSourceAdaptor;
00052 
00089     template<class From, class To>
00090     struct DataSourceAdaptor
00091         : public DataSource<To>
00092     {
00093         typename DataSource<From>::shared_ptr orig_;
00094 
00095         DataSourceAdaptor( typename DataSource<From>::shared_ptr orig)
00096             : orig_(orig) {}
00097 
00098         virtual typename DataSource<To>::result_t  get() const { return orig_->get(); }
00099 
00100         virtual typename DataSource<To>::result_t  value() const { return orig_->value(); }
00101 
00102         virtual void reset() { orig_->reset(); }
00103 
00104         virtual bool evaluate() const { return orig_->evaluate(); }
00105 
00106         virtual DataSource<To>* clone() const {
00107             return new DataSourceAdaptor( orig_->clone() );
00108         }
00109 
00110         virtual DataSource<To>* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00111             std::map<const DataSourceBase*,  DataSourceBase*>::iterator i = alreadyCloned.find( this );
00112             if ( i == alreadyCloned.end() ) {
00113                 DataSourceAdaptor<From,To>* n = new DataSourceAdaptor<From,To>( orig_->copy( alreadyCloned) );
00114                 alreadyCloned[this] = n;
00115                 return n;
00116             }
00117             typedef DataSourceAdaptor<From,To> CastType;
00118             assert( dynamic_cast< CastType* >( i->second ) == static_cast< CastType* >( i->second ) );
00119             return static_cast< CastType* >( i->second );
00120         }
00121     };
00122 
00123 #ifndef ORO_EMBEDDED
00124 
00131     template<class TFrom>
00132     struct DataSourceAdaptor<TFrom&, TFrom>
00133         : public AssignableDataSource<TFrom>
00134     {
00135         typedef TFrom& From;
00136         typedef TFrom  To;
00137         typename DataSource<From>::shared_ptr orig_;
00138 
00139         DataSourceAdaptor( typename DataSource<From>::shared_ptr orig)
00140             : orig_(orig) {}
00141 
00142         virtual typename DataSource<To>::result_t  get() const { return orig_->get(); }
00143 
00144         virtual typename DataSource<To>::result_t  value() const { return orig_->value(); }
00145 
00146         virtual typename AssignableDataSource<To>::const_reference_t rvalue() const { return orig_->value(); }
00147 
00148         virtual typename AssignableDataSource<To>::reference_t set() { return orig_->get(); }
00149 
00150         virtual void set(typename AssignableDataSource<To>::param_t v) { orig_->get() = v; }
00151 
00152         virtual void reset() { orig_->reset(); }
00153 
00154         virtual bool evaluate() const { return orig_->evaluate(); }
00155 
00156         virtual AssignableDataSource<To>* clone() const {
00157             return new DataSourceAdaptor( orig_->clone() );
00158         }
00159 
00160         virtual AssignableDataSource<To>* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00161             std::map<const DataSourceBase*,  DataSourceBase*>::iterator i = alreadyCloned.find( this );
00162             if ( i == alreadyCloned.end() ) {
00163                 DataSourceAdaptor<From,To>* n = new DataSourceAdaptor<From,To>( orig_->copy( alreadyCloned) );
00164                 alreadyCloned[this] = n;
00165                 return n;
00166             }
00167             typedef DataSourceAdaptor<From,To> CastType;
00168             assert( dynamic_cast< CastType* >( i->second ) == static_cast< CastType* >( i->second ) );
00169             return static_cast< CastType* >( i->second );
00170         }
00171     };
00172 
00177     template<class TFrom>
00178     struct DataSourceAdaptor<const TFrom&, const TFrom>
00179         : public DataSource<const TFrom>
00180     {
00181         typedef const TFrom& From;
00182         typedef const TFrom  To;
00183         typename DataSource<From>::shared_ptr orig_;
00184 
00185         DataSourceAdaptor( typename DataSource<From>::shared_ptr orig)
00186             : orig_(orig) {}
00187 
00188         virtual typename DataSource<To>::result_t  get() const { return orig_->get(); }
00189 
00190         virtual typename DataSource<To>::result_t  value() const { return orig_->value(); }
00191 
00192         virtual void reset() { orig_->reset(); }
00193 
00194         virtual bool evaluate() const { return orig_->evaluate(); }
00195 
00196         virtual DataSource<To>* clone() const {
00197             return new DataSourceAdaptor( orig_->clone() );
00198         }
00199 
00200         virtual DataSource<To>* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00201             std::map<const DataSourceBase*,  DataSourceBase*>::iterator i = alreadyCloned.find( this );
00202             if ( i == alreadyCloned.end() ) {
00203                 DataSourceAdaptor<From,To>* n = new DataSourceAdaptor<From,To>( orig_->copy( alreadyCloned) );
00204                 alreadyCloned[this] = n;
00205                 return n;
00206             }
00207             typedef DataSourceAdaptor<From,To> CastType;
00208             assert( dynamic_cast< CastType* >( i->second ) == static_cast< CastType* >( i->second ) );
00209             return static_cast< CastType* >( i->second );
00210         }
00211     };
00212 
00218     template<class TFrom>
00219     struct DataSourceAdaptor<TFrom&, TFrom&>
00220         : public AssignableDataSource<TFrom&>
00221     {
00222         typedef TFrom& From;
00223         typedef TFrom& To;
00224         typename DataSource<From>::shared_ptr orig_;
00225 
00226         DataSourceAdaptor( typename DataSource<From>::shared_ptr orig)
00227             : orig_(orig) {}
00228 
00229         virtual typename DataSource<To>::result_t  get() const { return orig_->get(); }
00230 
00231         virtual typename DataSource<To>::result_t  value() const { return orig_->value(); }
00232 
00233         virtual typename AssignableDataSource<To>::const_reference_t rvalue() const { return orig_->value(); }
00234 
00235         virtual typename AssignableDataSource<To>::reference_t set() { return orig_->get(); }
00236 
00237         virtual void set(typename AssignableDataSource<To>::param_t v) { orig_->get() = v; }
00238 
00239         virtual void reset() { orig_->reset(); }
00240 
00241         virtual bool evaluate() const { return orig_->evaluate(); }
00242 
00243         virtual AssignableDataSource<To>* clone() const {
00244             return new DataSourceAdaptor( orig_->clone() );
00245         }
00246 
00247         virtual AssignableDataSource<To>* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00248             std::map<const DataSourceBase*,  DataSourceBase*>::iterator i = alreadyCloned.find( this );
00249             if ( i == alreadyCloned.end() ) {
00250                 DataSourceAdaptor<From,To>* n = new DataSourceAdaptor<From,To>( orig_->copy( alreadyCloned) );
00251                 alreadyCloned[this] = n;
00252                 return n;
00253             }
00254             typedef DataSourceAdaptor<From,To> CastType;
00255             assert( dynamic_cast< CastType* >( i->second ) == static_cast< CastType* >( i->second ) );
00256             return static_cast< CastType* >( i->second );
00257         }
00258     };
00259 
00260 #endif
00261 
00267     template<class TFrom>
00268     struct DataSourceAdaptor<TFrom,const TFrom&>
00269         : public DataSource<const TFrom&>
00270     {
00271         typedef const TFrom& To;
00272         typedef TFrom  From;
00273 
00274         typename DataSource<From>::shared_ptr orig_;
00275 
00276         DataSourceAdaptor( typename DataSource<From>::shared_ptr orig)
00277             : orig_(orig) {}
00278 
00279         mutable From copy_;  
00280 
00281         virtual typename DataSource<To>::result_t get() const { copy_ = orig_->get(); return copy_; }
00282 
00283         virtual typename DataSource<To>::result_t value() const { copy_ = orig_->value(); return copy_; }
00284 
00285         virtual void reset() { orig_->reset(); }
00286 
00287         virtual bool evaluate() const { return orig_->evaluate(); }
00288 
00289         virtual DataSource<To>* clone() const {
00290             return new DataSourceAdaptor( orig_->clone() );
00291         }
00292 
00293         virtual DataSource<To>* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00294             std::map<const DataSourceBase*,  DataSourceBase*>::iterator i = alreadyCloned.find( this );
00295             if ( i == alreadyCloned.end() ) {
00296                 DataSourceAdaptor<From,To>* n = new DataSourceAdaptor<From,To>( orig_->copy( alreadyCloned) );
00297                 alreadyCloned[this] = n;
00298                 return n;
00299             }
00300             typedef DataSourceAdaptor<From,To> CastType;
00301             assert( dynamic_cast< CastType* >( i->second ) == static_cast< CastType* >( i->second ) );
00302             return static_cast< CastType* >( i->second );
00303         }
00304 
00305     };
00306 
00307 #ifndef ORO_EMBEDDED
00308 
00315     template<class TFrom>
00316     struct DataSourceAdaptor<const TFrom, const TFrom&>
00317         : public DataSource<const TFrom&>
00318     {
00319         typedef const TFrom& To;
00320         typedef const TFrom From;
00321 
00322         typename DataSource<From>::shared_ptr orig_;
00323 
00324         DataSourceAdaptor( typename DataSource<From>::shared_ptr orig)
00325             : orig_(orig) {}
00326 
00327         mutable TFrom copy_;  
00328 
00329         virtual typename DataSource<To>::result_t get() const { copy_ = orig_->get(); return copy_; }
00330 
00331         virtual typename DataSource<To>::result_t value() const { copy_ = orig_->value(); return copy_; }
00332 
00333         virtual void reset() { orig_->reset(); }
00334 
00335         virtual bool evaluate() const { return orig_->evaluate(); }
00336 
00337         virtual DataSource<To>* clone() const {
00338             return new DataSourceAdaptor( orig_->clone() );
00339         }
00340 
00341         virtual DataSource<To>* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00342             std::map<const DataSourceBase*,  DataSourceBase*>::iterator i = alreadyCloned.find( this );
00343             if ( i == alreadyCloned.end() ) {
00344                 DataSourceAdaptor<From,To>* n = new DataSourceAdaptor<From,To>( orig_->copy( alreadyCloned) );
00345                 alreadyCloned[this] = n;
00346                 return n;
00347             }
00348             typedef DataSourceAdaptor<From,To> CastType;
00349             assert( dynamic_cast< CastType* >( i->second ) == static_cast< CastType* >( i->second ) );
00350             return static_cast< CastType* >( i->second );
00351         }
00352 
00353     };
00354 
00363     template<class From, class To>
00364     struct AssignableDataSourceAdaptor
00365         : public DataSource<To>
00366     {
00367         typename AssignableDataSource<From>::shared_ptr orig_;
00368         mutable typename DataSource<To>::value_t mcache;
00369 
00370         AssignableDataSourceAdaptor( typename AssignableDataSource<From>::shared_ptr orig)
00371             : orig_(orig) {}
00372 
00373         virtual typename DataSource<To>::result_t get() const { mcache = orig_->get(); return mcache; }
00374 
00375         virtual typename DataSource<To>::result_t value() const { mcache = orig_->value(); return mcache; }
00376 
00377         virtual void updated() { orig_->set( mcache ); }
00378 
00379         virtual void reset() { orig_->reset(); }
00380 
00381         virtual bool evaluate() const { return orig_->evaluate(); }
00382 
00383         virtual DataSource<To>* clone() const {
00384             return new AssignableDataSourceAdaptor( orig_->clone() );
00385         }
00386 
00387         virtual DataSource<To>* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00388             std::map<const DataSourceBase*,  DataSourceBase*>::iterator i = alreadyCloned.find( this );
00389             if ( i == alreadyCloned.end() ) {
00390                 AssignableDataSourceAdaptor<From,To>* n = new AssignableDataSourceAdaptor<From,To>( orig_->copy( alreadyCloned) );
00391                 alreadyCloned[this] = n;
00392                 return n;
00393             }
00394             typedef AssignableDataSourceAdaptor<From,To> CastType;
00395             assert( dynamic_cast< CastType* >( i->second ) == static_cast< CastType* >( i->second ) );
00396             return static_cast< CastType* >( i->second );
00397         }
00398 
00399     };
00400 #endif
00401 
00406     template<class From>
00407     struct AssignableDataSourceAdaptor<From, const From& >
00408         : public DataSource<const From&>
00409     {
00410         typedef const From& To;
00411         typename AssignableDataSource<From>::shared_ptr orig_;
00412 
00413         AssignableDataSourceAdaptor( typename AssignableDataSource<From>::shared_ptr orig)
00414             : orig_(orig) {}
00415 
00416         virtual typename DataSource<To>::result_t get() const { orig_->evaluate(); return orig_->rvalue(); }
00417 
00418         virtual typename DataSource<To>::result_t value() const { return orig_->rvalue(); }
00419 
00420         virtual void reset() { orig_->reset(); }
00421 
00422         virtual bool evaluate() const { return orig_->evaluate(); }
00423 
00424         virtual DataSource<To>* clone() const {
00425             return new AssignableDataSourceAdaptor( orig_->clone() );
00426         }
00427 
00428         virtual DataSource<To>* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00429             std::map<const DataSourceBase*,  DataSourceBase*>::iterator i = alreadyCloned.find( this );
00430             if ( i == alreadyCloned.end() ) {
00431                 AssignableDataSourceAdaptor<From,To>* n = new AssignableDataSourceAdaptor<From,To>( orig_->copy( alreadyCloned) );
00432                 alreadyCloned[this] = n;
00433                 return n;
00434             }
00435             typedef AssignableDataSourceAdaptor<From,To> CastType;
00436             assert( dynamic_cast< CastType* >( i->second ) == static_cast< CastType* >( i->second ) );
00437             return static_cast< CastType* >( i->second );
00438         }
00439 
00440     };
00441 
00446     template<class To>
00447     struct AssignableDataSourceAdaptor<To const&, To>
00448         : public AssignableDataSource<To>
00449     {
00450         typedef To const& From;
00451         typename AssignableDataSource<From>::shared_ptr orig_;
00452 
00453         AssignableDataSourceAdaptor( typename AssignableDataSource<From>::shared_ptr orig)
00454             : orig_(orig) {}
00455 
00456         virtual typename DataSource<To>::result_t get() const { return orig_->get(); }
00457 
00458         virtual typename DataSource<To>::result_t value() const { return orig_->value(); }
00459 
00460         virtual typename AssignableDataSource<To>::const_reference_t rvalue() const { return orig_->rvalue(); }
00461 
00462         virtual typename AssignableDataSource<To>::reference_t set() { return orig_->set(); }
00463 
00464         virtual void set( typename AssignableDataSource<To>::param_t v) { orig_->set(v); }
00465 
00466         virtual void updated() { orig_->updated(); }
00467 
00468         virtual void reset() { orig_->reset(); }
00469 
00470         virtual bool evaluate() const { return orig_->evaluate(); }
00471 
00472         virtual bool updatePart( DataSourceBase* part, DataSourceBase* other ) { return orig_->updatePart( part, other); }
00473 
00474         virtual CommandInterface* updatePartCommand( DataSourceBase* part, DataSourceBase* other) { return orig_->updatePartCommand(part, other ); }
00475 
00476         virtual AssignableDataSource<To>* clone() const {
00477             return new AssignableDataSourceAdaptor( orig_->clone() );
00478         }
00479 
00480         virtual AssignableDataSource<To>* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00481             std::map<const DataSourceBase*,  DataSourceBase*>::iterator i = alreadyCloned.find( this );
00482             if ( i == alreadyCloned.end() ) {
00483                 AssignableDataSourceAdaptor<From,To>* n = new AssignableDataSourceAdaptor<From,To>( orig_->copy( alreadyCloned) );
00484                 alreadyCloned[this] = n;
00485                 return n;
00486             }
00487             typedef AssignableDataSourceAdaptor<From,To> CastType;
00488             assert( dynamic_cast< CastType* >( i->second ) == static_cast< CastType* >( i->second ) );
00489             return static_cast< CastType* >( i->second );
00490         }
00491 
00492     };
00493 
00494     }
00495 
00499     template< class TResult >
00500     struct AdaptDataSource
00501     {
00502         typedef TResult Result;
00503 
00504         typename DataSource<Result>::shared_ptr operator()( DataSourceBase::shared_ptr dsb) const
00505         {
00506             // equal case
00507             typename DataSource<Result>::shared_ptr t1 = DataSource<Result>::narrow( dsb.get() );
00508             if (t1)
00509                 return t1;
00510 
00511             // const ref to value case
00512             typename DataSource<const Result&>::shared_ptr t2 = DataSource<const Result&>::narrow( dsb.get() );
00513             if ( t2 )
00514                 return new detail::DataSourceAdaptor<const Result&, Result>( t2 );
00515 
00516 #ifndef ORO_EMBEDDED
00517             // ref to value case
00518             typename DataSource<Result&>::shared_ptr t3 = DataSource<Result&>::narrow( dsb.get() );
00519             if ( t3 )
00520                 return new detail::DataSourceAdaptor<Result&, Result>( t3 );
00521 
00522             // const value to value case
00523             typename DataSource<const Result>::shared_ptr t4 = DataSource<const Result>::narrow( dsb.get() );
00524             if ( t4 )
00525                 return new detail::DataSourceAdaptor<const Result, Result>( t4 );
00526 #endif
00527 
00528             // complete type failure.
00529             return 0;
00530         }
00531 
00532     };
00533 
00537     template< class TResult >
00538     struct AdaptAssignableDataSource
00539     {
00540         typedef TResult Result;
00541 
00542         typename AssignableDataSource<Result>::shared_ptr operator()( DataSourceBase::shared_ptr dsb) const
00543         {
00544             // equal case
00545             typename AssignableDataSource<Result>::shared_ptr t1 = AssignableDataSource<Result>::narrow( dsb.get() );
00546             if (t1)
00547                 return t1;
00548 
00549 #if 0
00550             // Does this case exist ?
00551             // Assignable const ref case
00552             typename AssignableDataSource<const Result&>::shared_ptr t2 = AssignableDataSource<const Result&>::narrow( dsb.get() );
00553             if ( t2 )
00554                 return new detail::AssignableDataSourceAdaptor<const Result&, Result>( t2 ); // will return AssignableDS !
00555 #endif
00556 
00557 #ifndef ORO_EMBEDDED
00558             // ref to assignable value case
00559             typename DataSource<Result&>::shared_ptr t3 = DataSource<Result&>::narrow( dsb.get() );
00560             if ( t3 )
00561                 return new detail::DataSourceAdaptor<Result&, Result>( t3 ); // will return AssignableDS !
00562 #endif
00563             // complete type failure.
00564             return 0;
00565         }
00566 
00567     };
00568 
00569 #ifndef ORO_EMBEDDED
00570 
00574     template< class TResult >
00575     struct AdaptAssignableDataSource< TResult& >
00576     {
00577         typedef TResult& Result;
00578 
00579         typename AssignableDataSource<Result>::shared_ptr operator()( DataSourceBase::shared_ptr dsb) const
00580         {
00581             // equal case
00582             typename AssignableDataSource<Result>::shared_ptr t1 = AssignableDataSource<Result>::narrow( dsb.get() );
00583             if (t1)
00584                 return t1;
00585 
00586             // ref to assignable value case
00587             typename DataSource<Result>::shared_ptr t3 = DataSource<Result>::narrow( dsb.get() );
00588             if ( t3 )
00589                 return new detail::DataSourceAdaptor<Result, Result>( t3 ); // will return AssignableDS !
00590 
00591             // complete type failure.
00592             return 0;
00593         }
00594 
00595     };
00596 
00600     template< class TResult >
00601     struct AdaptDataSource< const TResult >
00602     {
00603         typedef const TResult Result;
00604 
00605         typename DataSource<Result>::shared_ptr operator()( DataSourceBase::shared_ptr dsb) const
00606         {
00607             // equal case
00608             typename DataSource<Result>::shared_ptr t1 = DataSource<Result>::narrow( dsb.get() );
00609             if (t1)
00610                 return t1;
00611 
00612             // const ref to const value case
00613             typename DataSource<const TResult&>::shared_ptr t2 = DataSource<const TResult&>::narrow( dsb.get() );
00614             if ( t2 )
00615                 return new detail::DataSourceAdaptor<const TResult&, Result>( t2 );
00616 
00617             // ref to const value case
00618             typename DataSource<TResult&>::shared_ptr t3 = DataSource<TResult&>::narrow( dsb.get() );
00619             if ( t3 )
00620                 return new detail::DataSourceAdaptor<TResult&, Result>( t3 );
00621 
00622             // value to const value case
00623             typename DataSource<TResult>::shared_ptr t4 = DataSource<TResult>::narrow( dsb.get() );
00624             if ( t4 )
00625                 return new detail::DataSourceAdaptor<TResult, Result>( t4 );
00626 
00627             // complete type failure.
00628             return 0;
00629         }
00630 
00631     };
00632 
00638     template< class TResult >
00639     struct AdaptDataSource< TResult& >
00640     {
00641         typedef TResult& Result;
00642 
00643         typename DataSource<Result>::shared_ptr operator()( DataSourceBase::shared_ptr dsb) const
00644         {
00645             // equal case
00646             typename DataSource<Result>::shared_ptr t1 = DataSource<Result>::narrow( dsb.get() );
00647             if (t1)
00648                 return t1;
00649 
00650             // assignable case
00651             typename AssignableDataSource<TResult>::shared_ptr t2 = AssignableDataSource<TResult>::narrow( dsb.get() );
00652             if (t2 && &(t2->set()) != 0 )
00653                 return new detail::AssignableDataSourceAdaptor<TResult, TResult&>( t2 );
00654 
00655             // complete type failure.
00656             return 0;
00657         }
00658 
00659     };
00660 
00661 #endif
00662 
00667     template<class TResult>
00668     struct AdaptDataSource<const TResult&>
00669     {
00670         typename DataSource<const TResult&>::shared_ptr operator()( DataSourceBase::shared_ptr dsb) const
00671         {
00672             // equal case
00673             typename DataSource<const TResult&>::shared_ptr t1 = DataSource<const TResult&>::narrow( dsb.get() );
00674             if (t1)
00675                 return t1;
00676 
00677             // assignable case: this is a more efficient implementation than the one below (t2)
00678             // does not involve a copy.
00679             typename AssignableDataSource<TResult>::shared_ptr ta1 =  AssignableDataSource<TResult>::narrow( dsb.get() );
00680             if (ta1 && &(ta1->set()) != 0 ) // check for null set()
00681                 return new detail::AssignableDataSourceAdaptor<TResult, const TResult&>( ta1 );
00682 
00683             // value to const ref case
00684             // makes a copy !
00685             typename DataSource<TResult>::shared_ptr t2 = DataSource<TResult>::narrow( dsb.get() );
00686             if ( t2 )
00687                 return new detail::DataSourceAdaptor<TResult, const TResult&>( t2 );
00688 
00689 #ifndef ORO_EMBEDDED
00690             // ref to const ref case
00691             typename DataSource<TResult&>::shared_ptr t3 = DataSource<TResult&>::narrow( dsb.get() );
00692             if ( t3 )
00693                 return new detail::DataSourceAdaptor<TResult&, const TResult&>( t3 );
00694 
00695             // const value to const ref case
00696             typename DataSource<const TResult>::shared_ptr t4 = DataSource<const TResult>::narrow( dsb.get() );
00697             if ( t4 )
00698                 return new detail::DataSourceAdaptor<const TResult, const TResult&>( t4 );
00699 
00700 #endif
00701 
00702             // complete type failure.
00703             return 0;
00704         }
00705 
00706     };
00707 }
00708 
00709 #endif
Generated on Thu Dec 23 13:22:37 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3