BasicTypeConversion.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #ifndef DOIL_CORBA_BASICTYPECONVERSION_H
00021 #define DOIL_CORBA_BASICTYPECONVERSION_H
00022 
00023 #include <coil/stringutil.h>
00024 #include <doil/corba/CORBA.h>
00025 
00026 //-------------------------------------------------------------
00027 // local -> corba
00028 inline bool local_to_corba(const short int _from, ::CORBA::Short& _to)
00029 {
00030   _to = _from;
00031   return true;
00032 }
00033 
00034 inline bool local_to_corba(const unsigned short _from, ::CORBA::UShort& _to)
00035 {
00036   _to = _from;
00037   return true;
00038 }
00039 
00040 inline bool local_to_corba(const long int _from, ::CORBA::Long& _to)
00041 {
00042   _to = _from;
00043   return true;
00044 }
00045 
00046 inline bool local_to_corba(const unsigned long int _from, ::CORBA::ULong& _to)
00047 {
00048   _to = _from;
00049   return true;
00050 }
00051 
00052 inline bool local_to_corba(const float _from, ::CORBA::Float& _to)
00053 {
00054   _to = _from;
00055   return true;
00056 }
00057 
00058 inline bool local_to_corba(const double _from, ::CORBA::Double& _to)
00059 {
00060   _to = _from;
00061   return true;
00062 }
00063 
00064 inline bool local_to_corba(const char _from, ::CORBA::Char& _to)
00065 {
00066   _to = _from;
00067   return true;
00068 }
00069 
00070 inline bool local_to_corba(const bool _from, ::CORBA::Boolean& _to)
00071 {
00072   _to = _from;
00073   return true;
00074 }
00075 
00076 inline bool local_to_corba(const unsigned char _from, ::CORBA::Octet& _to)
00077 {
00078   _to = _from;
00079   return true;
00080 }
00081 
00082 #if   defined ORB_IS_TAO
00083 #elif defined ORB_IS_OMNIORB
00084 inline bool local_to_corba(const std::string& _from, ::CORBA::String_member& _to)
00085 {
00086   _to.out() = ::CORBA::string_dup(_from.c_str());
00087   return true;
00088 }
00089 
00090 
00091 inline bool local_to_corba(const std::string& _from, _CORBA_String_element::_CORBA_String_element _to)
00092 {
00093   _to.out() = ::CORBA::string_dup(_from.c_str());
00094   return true;
00095 }
00096 #elif defined ORB_IS_MICO
00097 #elif defined ORB_IS_ORBIT2
00098 #endif
00099 inline bool local_to_corba(const ::std::string& _from, char*& _to)
00100 {
00101   _to = ::CORBA::string_dup(_from.c_str());
00102   return true;
00103 }
00104 
00105 inline bool local_to_corba(const std::string& _from, ::CORBA::Any& _to)
00106 {
00107   _to <<= ::CORBA::Any::from_string(_from.c_str(), _from.size());
00108   return true;
00109 }
00110 
00111 inline bool local_to_corba(const std::string& _from, CORBA::TypeCode* _to)
00112 {
00113   //    if (_from == "tk_null")
00114   //      _to = new ::CORBA::TypeCode(CORBA::tk_null);
00115   //    else if (_from == "tk_void")
00116   //      _to = new ::CORBA::TypeCode(CORBA::tk_void);
00117   //    else if (_from == "tk_short")
00118   //      _to = new ::CORBA::TypeCode(CORBA::tk_short);
00119   //    else if (_from == "tk_long")
00120   //      _to = new ::CORBA::TypeCode(CORBA::tk_long);
00121   //    else if (_from == "tk_ushort")
00122   //      _to = new ::CORBA::TypeCode(CORBA::tk_ushort);
00123   //    else if (_from == "tk_ulong")
00124   //      _to = new ::CORBA::TypeCode(CORBA::tk_ulong);
00125   //    else if (_from == "tk_float")
00126   //      _to = new ::CORBA::TypeCode(CORBA::tk_float);
00127   //    else if (_from == "tk_double")
00128   //      _to = new ::CORBA::TypeCode(CORBA::tk_double);
00129   //    else if (_from == "tk_boolean")
00130   //      _to = new ::CORBA::TypeCode(CORBA::tk_boolean);
00131   //    else if (_from == "tk_char")
00132   //      _to = new ::CORBA::TypeCode(CORBA::tk_char);
00133   //    else if (_from == "tk_octet")
00134   //      _to = new ::CORBA::TypeCode(CORBA::tk_octet);
00135   //    else if (_from == "tk_any")
00136   //      _to = new ::CORBA::TypeCode(CORBA::tk_any);
00137   //    else if (_from == "tk_TypeCode")
00138   //      _to = new ::CORBA::TypeCode(CORBA::tk_TypeCode);
00139   //    else if (_from == "tk_Principal")
00140   //      _to = new ::CORBA::TypeCode(CORBA::tk_Principal);
00141   //    else if (_from == "tk_longlong")
00142   //      _to = new ::CORBA::TypeCode(CORBA::tk_longlong);
00143   //    else if (_from == "tk_ulonglong")
00144   //      _to = new ::CORBA::TypeCode(CORBA::tk_ulonglong);
00145   //    else if (_from == "tk_longdouble")
00146   //      _to = new ::CORBA::TypeCode(CORBA::tk_longdouble);
00147   //    else if (_from == "tk_wchar")
00148   //      _to = new ::CORBA::TypeCode(CORBA::tk_wchar);
00149   //    else if (_from == "tk_fixed")
00150   //      _to = new ::CORBA::TypeCode(CORBA::tk_fixed);
00151   //    else if (_from == "tk_value")
00152   //      _to = new ::CORBA::TypeCode(CORBA::tk_value);
00153   //    else if (_from == "tk_value_box")
00154   //      _to = new ::CORBA::TypeCode(CORBA::tk_value_box);
00155   //    else if (_from == "native")
00156   //      _to = new ::CORBA::TypeCode(CORBA::native);
00157   //    else if (_from == "tk_abstract_interface")
00158   //      _to = new ::CORBA::TypeCode(CORBA::tk_abstract_interface);
00159   //    else
00160   //      return false;
00161   return true;
00162 }
00163 
00164 //-------------------------------------------------------------
00165 // corba -> local
00166 inline bool corba_to_local(const ::CORBA::Short _from, short& _to)
00167 {
00168   _to = _from;
00169   return true;
00170 }
00171 
00172 inline bool corba_to_local(const ::CORBA::UShort _from, unsigned short& _to)
00173 {
00174   _to = _from;
00175   return true;
00176 }
00177 
00178 inline bool corba_to_local(const ::CORBA::Long _from, int& _to)
00179 {
00180   _to = _from;
00181   return true;
00182 }
00183 
00184 inline bool corba_to_local(const ::CORBA::ULong _from, unsigned int& _to)
00185 {
00186   _to = _from;
00187   return true;
00188 }
00189 
00190 inline bool corba_to_local(const ::CORBA::Float _from, float& _to)
00191 {
00192   _to = _from;
00193   return true;
00194 }
00195 
00196 inline bool corba_to_local(const ::CORBA::Double _from, double& _to)
00197 {
00198   _to = _from;
00199   return true;
00200 }
00201 
00202 inline bool corba_to_local(const ::CORBA::Char _from, char& _to)
00203 {
00204   _to = _from;
00205   return true;
00206 }
00207 
00208 inline bool corba_to_local(const ::CORBA::Boolean _from, unsigned char& _to)
00209 {
00210   _to = _from;
00211   return true;
00212 }
00213 
00214 inline bool corba_to_local(const ::CORBA::Octet _from, unsigned char& _to)
00215 {
00216   _to = _from;
00217   return true;
00218 }
00219 
00220 inline bool corba_to_local(const ::CORBA::Boolean _from, bool& _to)
00221 {
00222   _to = _from;
00223   return true;
00224 }
00225 
00226 inline bool corba_to_local(const char* _from, std::string& _to)
00227 {
00228   _to = _from;
00229   return true;
00230 }
00231 
00232 //  inline bool corba_to_local(char* _from, std::string& _to)
00233 //  {
00234 //    _to = _from;
00235 //  }
00236 
00237 inline bool corba_to_local(const ::CORBA::Any& _from, std::string& _to)
00238 {
00239   const char* str;
00240   if (_from >>= str)
00241     {
00242       _to = str;
00243       return true;
00244     }
00245   ::CORBA::Short short_var;
00246   if (_from >>= short_var)
00247     {
00248       _to = ::coil::otos(short_var);
00249       return true;
00250     }
00251   ::CORBA::UShort ushort_var;
00252   if (_from >>= ushort_var)
00253     {
00254       _to = ::coil::otos(ushort_var);
00255       return true;
00256     }
00257   ::CORBA::Long long_var;
00258   if (_from >>= long_var)
00259     {
00260       _to = ::coil::otos(long_var);
00261       return true;
00262     }
00263   ::CORBA::ULong ulong_var;
00264   if (_from >>= ulong_var)
00265     {
00266       _to = ::coil::otos(ulong_var);
00267       return true;
00268     }
00269   ::CORBA::Float float_var;
00270   if (_from >>= float_var)
00271     {
00272       _to = ::coil::otos(float_var);
00273       return true;
00274     }
00275   ::CORBA::Double double_var;
00276   if (_from >>= double_var)
00277     {
00278       _to = ::coil::otos(double_var);
00279       return true;
00280     }
00281 }
00282 
00283 inline bool
00284 corba_to_local(const CORBA::TypeCode_member& _from, std::string& _to)
00285 {
00286   try
00287     {
00288       _to = _from->name();
00289       return true;
00290     }
00291   catch ( ::CORBA::TypeCode::BadKind& e )
00292     {
00293       return false;
00294     }
00295   return true;
00296 }
00297 
00298 
00299 #endif // DOIL_CORBA_UTIL_H


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:03