RTTCorbaConversion.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002 tag: Peter Soetens  Mon Jun 26 13:25:58 CEST 2006  CorbaConversion.hpp
00003 
00004 CorbaConversion.hpp -  description
00005 -------------------
00006 begin                : Mon June 26 2006
00007 copyright            : (C) 2006 Peter Soetens
00008 email                : peter.soetens@fmtc.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 
00039 #ifndef ORO_RTT_CORBA_CONVERSION_HPP
00040 #define ORO_RTT_CORBA_CONVERSION_HPP
00041 
00042 
00043 #include "CorbaConversion.hpp"
00044 #include "OrocosTypesC.h"
00045 #include "TaskContextC.h"
00046 #include "TaskContextServer.hpp"
00047 #include "TaskContextProxy.hpp"
00048 #include "CorbaConnPolicy.hpp"
00049 #ifdef OS_RT_MALLOC
00050 #include <rtt/rt_string.hpp>
00051 #endif
00052 
00053 namespace RTT { 
00054   namespace corba {
00055 
00056     template<>
00057     struct AnyConversion<double> : public AnyConversionHelper<double> {
00058       typedef CORBA::DoubleSeq sequence;
00059     };
00060 
00061     template<>
00062     struct AnyConversion<float> : public AnyConversionHelper<float> {
00063       typedef CORBA::FloatSeq sequence;
00064     };
00065 
00066     template<>
00067     struct AnyConversion<int> : public AnyConversionHelper<int, CORBA::Long> {
00068       typedef CORBA::LongSeq sequence;
00069     };
00070 
00071     //template<>
00072     //struct AnyConversion<long> : public AnyConversionHelper<long> {};
00073 
00074     template<>
00075     struct AnyConversion<unsigned int> : public AnyConversionHelper<unsigned int, CORBA::ULong> {
00076       typedef CORBA::ULongSeq sequence;
00077     };
00078 
00079     template<>
00080     struct AnyConversion<CORBA::Any_ptr>
00081     {
00082       typedef CORBA::Any_ptr CorbaType;
00083       typedef CORBA::Any_ptr StdType;
00084 
00085       static bool update(const CORBA::Any& any, CORBA::Any_ptr _value) {
00086         //Logger::log() << Logger::Debug << "Updating type CORBA::Any_ptr with CORBA::Any." <<Logger::endl;
00087         *_value = any;
00088         return true;
00089       }
00090 
00091       static CORBA::Any_ptr createAny( CORBA::Any_ptr t ) {
00092         //Logger::log() << Logger::Debug << "Duplicating CORBA::Any_ptr." <<Logger::endl;
00093         return new CORBA::Any(*t);
00094       }
00095 
00096       static bool updateAny( const StdType& t, CORBA::Any& any ) {
00097         //Logger::log() << Logger::Debug << "Duplicating CORBA::Any_ptr." <<Logger::endl;
00098         any <<= CORBA::Any(*t);
00099         return true;
00100       }
00101     };
00102 
00103     template<>
00104     struct AnyConversion<CORBA::Any_var>
00105     {
00106       typedef CORBA::Any_ptr CorbaType;
00107       typedef CORBA::Any_var StdType;
00108 
00109       static bool update(const CORBA::Any& any, CORBA::Any_var _value) {
00110         //Logger::log() << Logger::Debug << "Updating type CORBA::Any_var with CORBA::Any." <<Logger::endl;
00111         *_value.out() = any;
00112         return true;
00113       }
00114 
00115       static CORBA::Any_ptr createAny( CORBA::Any_var t ) {
00116         //Logger::log() << Logger::Debug << "Duplicating CORBA::Any_var." <<Logger::endl;
00117         return new CORBA::Any( t.in() );
00118       }
00119 
00120       static bool updateAny( const StdType& t, CORBA::Any& any ) {
00121         //Logger::log() << Logger::Debug << "Duplicating CORBA::Any_var." <<Logger::endl;
00122         any <<= CORBA::Any( t.in() );
00123         return true;
00124       }
00125     };
00126 
00127     template<>
00128     struct AnyConversion<bool>
00129     {
00130       typedef CORBA::Boolean CorbaType;
00131       typedef bool StdType;
00132 
00133       typedef CORBA::BooleanSeq sequence;
00134 
00135       static CORBA::Any::from_boolean toAny( bool t ) {
00136         //Logger::log() << Logger::Debug << "Converting type 'bool' to from_boolean." <<Logger::endl;
00137         return CORBA::Any::from_boolean(t);
00138       }
00139       static CORBA::Any::to_boolean fromAny( CORBA::Boolean& t ) {
00140         return CORBA::Any::to_boolean(t);
00141       }
00142       static StdType get(const CORBA::Boolean t) {
00143         return t;
00144       }
00145 
00146       static bool toStdType(StdType& tp, const CorbaType& cb) {
00147         tp = get(cb);
00148         return true;
00149       }
00150       static bool toCorbaType(CorbaType& cb, const StdType& tp) {
00151         cb = tp;
00152         return true;
00153       }
00154 
00155       static bool update(const CORBA::Any& any, StdType& _value) {
00156         CorbaType result;
00157         if ( any >>= AnyConversion<bool>::fromAny( result ) ) {
00158           _value = AnyConversion<bool>::get(result);
00159           return true;
00160         }
00161         return false;
00162       }
00163 
00164       static CORBA::Any_ptr createAny( bool t ) {
00165         CORBA::Any_ptr ret = new CORBA::Any();
00166         *ret <<= toAny( t );
00167         return ret;
00168       }
00169 
00170       static bool updateAny( bool t, CORBA::Any& any ) {
00171         any <<= toAny( t );
00172         return true;
00173       }
00174     };
00175 
00176     template<>
00177     struct AnyConversion<char>
00178     {
00179       typedef CORBA::Char CorbaType;
00180       typedef char StdType;
00181 
00182       typedef CORBA::CharSeq sequence;
00183 
00184       static CORBA::Any::from_char toAny( StdType t ) {
00185         return CORBA::Any::from_char(t);
00186       }
00187 
00188       static CORBA::Any::to_char fromAny( CorbaType& t ) {
00189         return CORBA::Any::to_char(t);
00190       }
00191 
00192       static StdType get(const CorbaType t) {
00193         return t;
00194       }
00195 
00196       static bool toStdType(StdType& tp, const CorbaType& cb) {
00197         tp = get(cb);
00198         return true;
00199       }
00200       static bool toCorbaType(CorbaType& cb, const StdType& tp) {
00201         cb = tp;
00202         return true;
00203       }
00204 
00205       static bool update(const CORBA::Any& any, StdType& _value) {
00206         CorbaType result;
00207         if ( any >>= AnyConversion<StdType>::fromAny( result ) ) {
00208           _value = AnyConversion<StdType>::get(result);
00209           return true;
00210         }
00211         return false;
00212       }
00213 
00214       static CORBA::Any_ptr createAny( char t ) {
00215         CORBA::Any_ptr ret = new CORBA::Any();
00216         *ret <<= toAny( t );
00217         return ret;
00218       }
00219 
00220       static bool updateAny( char t, CORBA::Any& any ) {
00221         any <<= toAny( t );
00222         return true;
00223       }
00224     };
00225 
00226     template<>
00227     struct AnyConversion<std::string>
00228     {
00229       typedef CORBA::StringSeq sequence;
00230 
00231       typedef const char* CorbaType;
00232       typedef std::string StdType;
00233 
00234       static CorbaType toAny(const std::string& orig) {
00235         //Logger::log() << Logger::Debug << "Converting type 'string' to const char*." <<Logger::endl;
00236         return orig.c_str();
00237       }
00238 
00239       static StdType get(const CorbaType t) {
00240         return StdType( t );
00241       }
00242 
00243       static bool toStdType(StdType& dest, const CorbaType src) {
00244         dest = get(src);
00245         return true;
00246       }
00247 
00251       template<class dummy>
00252       static bool toCorbaType(dummy dest, const StdType& src) {
00253         dest = src.c_str();
00254         return true;
00255       }
00256 
00257       static bool toCorbaType(CorbaType dest, const StdType& src) {
00258         dest = src.c_str();
00259         return true;
00260       }
00261 
00262       static bool update(const CORBA::Any& any, StdType& _value) {
00263         CorbaType result;
00264         //Logger::log() << Logger::Debug << "Updating std::string with Any." <<Logger::endl;
00265         if ( any >>= result ) {
00266           _value = result;
00267           return true;
00268         }
00269         return false;
00270       }
00271 
00272       static CORBA::Any_ptr createAny( const std::string& t ) {
00273         CORBA::Any_ptr ret = new CORBA::Any();
00274         *ret <<= toAny( t );
00275         return ret;
00276       }
00277 
00278       static bool updateAny( StdType const& t, CORBA::Any& any ) {
00279         any <<= toAny( t );
00280         return true;
00281       }
00282     };
00283 
00288     template<>
00289     struct AnyConversion<ConnPolicy>
00290     {
00291       typedef RTT::corba::CConnPolicy CorbaType;
00292       typedef RTT::ConnPolicy StdType;
00293       static CorbaType toAny(const StdType& orig) {
00294         //Logger::log() << Logger::Debug << "Converting type 'string' to const char*." <<Logger::endl;
00295         return toCORBA(orig);
00296       }
00297 
00298       static StdType get(const CorbaType t) {
00299         return toRTT( t );
00300       }
00301 
00302       static bool update(const CORBA::Any& any, StdType& _value) {
00303         CorbaType* result;
00304         //Logger::log() << Logger::Debug << "Updating std::string with Any." <<Logger::endl;
00305         if ( any >>= result ) {
00306           _value = toRTT(*result);
00307           return true;
00308         }
00309         return false;
00310       }
00311 
00312       static CORBA::Any_ptr createAny( const StdType& t ) {
00313         CORBA::Any_ptr ret = new CORBA::Any();
00314         *ret <<= toAny( t );
00315         return ret;
00316       }
00317 
00318       static bool updateAny( StdType const& t, CORBA::Any& any ) {
00319         any <<= toAny( t );
00320         return true;
00321       }
00322     };
00323 
00324     template<>
00325     struct AnyConversion<RTT::TaskContext*>
00326     {
00327       typedef RTT::corba::CTaskContext_ptr CorbaType;
00328       typedef RTT::TaskContext* StdType;
00329 
00330       static bool update(const CORBA::Any& any, StdType& _value) {
00331         RTT::corba::CTaskContext_ptr task;
00332         if ( any >>= task ) {
00333           // read-only insertion, we duplicate the _ptr in Create:
00334           _value = TaskContextProxy::Create( task );
00335           return true;
00336         }
00337         return true;
00338       }
00339 
00340       static CORBA::Any_ptr createAny( const StdType& t ) {
00341         CORBA::Any_ptr ret = new CORBA::Any();
00342         // copying insertion:
00343         *ret <<= TaskContextServer::CreateServer(t,false,false);
00344         return ret;
00345       }
00346 
00347       static bool updateAny( const StdType& t, CORBA::Any& any ) {
00348         if (t) {
00349           // copying insertion:
00350           any <<= TaskContextServer::CreateServer(t, false, false );
00351         } else {
00352           // leave any.
00353         }
00354         return true;
00355       }
00356     };
00357 
00358 #ifdef OS_RT_MALLOC
00359     template<>
00360     struct AnyConversion< rt_string >
00361     {
00362       typedef const char*     CorbaType;
00363       typedef rt_string     StdType;
00364 
00365       static bool toCorbaType(CorbaType& cb,const StdType& orig) {
00366         cb = orig.c_str();
00367         return true;
00368       }
00369 
00370       static CorbaType toAny(const StdType& orig) {
00371         return orig.c_str();
00372       }
00373 
00374       static bool toStdType(StdType& dest, const CorbaType orig) {
00375         dest = StdType(orig);
00376         return true;
00377       }
00378 
00379       static bool update(const CORBA::Any& any, StdType& ret) {
00380         CorbaType orig;
00381         if ( any >>= orig )
00382           {
00383             ret = orig;
00384             return true;
00385           }
00386         return false;
00387       }
00388 
00389       static CORBA::Any_ptr createAny( const StdType& t ) {
00390         CORBA::Any_ptr ret = new CORBA::Any();
00391         *ret <<= toAny( t );
00392         return ret;
00393       }
00394 
00395       static bool updateAny( StdType const& t, CORBA::Any& any ) {
00396         any <<= toAny( t );
00397         return true;
00398       }
00399 
00400     };
00401 #endif
00402   }
00403 }
00404 
00405 #endif


rtt
Author(s): RTT Developers
autogenerated on Fri Sep 9 2016 04:01:58