BasicTypeConversion.h
Go to the documentation of this file.
1 // -*- C++ -*-
20 #ifndef DOIL_CORBA_BASICTYPECONVERSION_H
21 #define DOIL_CORBA_BASICTYPECONVERSION_H
22 
23 #include <coil/stringutil.h>
24 #include <doil/corba/CORBA.h>
25 
26 //-------------------------------------------------------------
27 // local -> corba
28 inline bool local_to_corba(const short int _from, ::CORBA::Short& _to)
29 {
30  _to = _from;
31  return true;
32 }
33 
34 inline bool local_to_corba(const unsigned short _from, ::CORBA::UShort& _to)
35 {
36  _to = _from;
37  return true;
38 }
39 
40 inline bool local_to_corba(const long int _from, ::CORBA::Long& _to)
41 {
42  _to = _from;
43  return true;
44 }
45 
46 inline bool local_to_corba(const unsigned long int _from, ::CORBA::ULong& _to)
47 {
48  _to = _from;
49  return true;
50 }
51 
52 inline bool local_to_corba(const float _from, ::CORBA::Float& _to)
53 {
54  _to = _from;
55  return true;
56 }
57 
58 inline bool local_to_corba(const double _from, ::CORBA::Double& _to)
59 {
60  _to = _from;
61  return true;
62 }
63 
64 inline bool local_to_corba(const char _from, ::CORBA::Char& _to)
65 {
66  _to = _from;
67  return true;
68 }
69 
70 inline bool local_to_corba(const bool _from, ::CORBA::Boolean& _to)
71 {
72  _to = _from;
73  return true;
74 }
75 
76 inline bool local_to_corba(const unsigned char _from, ::CORBA::Octet& _to)
77 {
78  _to = _from;
79  return true;
80 }
81 
82 #if defined ORB_IS_TAO
83 #elif defined ORB_IS_OMNIORB
84 inline bool local_to_corba(const std::string& _from, ::CORBA::String_member& _to)
85 {
86  _to.out() = ::CORBA::string_dup(_from.c_str());
87  return true;
88 }
89 
90 
91 inline bool local_to_corba(const std::string& _from, _CORBA_String_element::_CORBA_String_element _to)
92 {
93  _to.out() = ::CORBA::string_dup(_from.c_str());
94  return true;
95 }
96 #elif defined ORB_IS_MICO
97 #elif defined ORB_IS_ORBIT2
98 #endif
99 inline bool local_to_corba(const ::std::string& _from, char*& _to)
100 {
101  _to = ::CORBA::string_dup(_from.c_str());
102  return true;
103 }
104 
105 inline bool local_to_corba(const std::string& _from, ::CORBA::Any& _to)
106 {
107  _to <<= ::CORBA::Any::from_string(_from.c_str(), _from.size());
108  return true;
109 }
110 
111 inline bool local_to_corba(const std::string& _from, CORBA::TypeCode* _to)
112 {
113  // if (_from == "tk_null")
114  // _to = new ::CORBA::TypeCode(CORBA::tk_null);
115  // else if (_from == "tk_void")
116  // _to = new ::CORBA::TypeCode(CORBA::tk_void);
117  // else if (_from == "tk_short")
118  // _to = new ::CORBA::TypeCode(CORBA::tk_short);
119  // else if (_from == "tk_long")
120  // _to = new ::CORBA::TypeCode(CORBA::tk_long);
121  // else if (_from == "tk_ushort")
122  // _to = new ::CORBA::TypeCode(CORBA::tk_ushort);
123  // else if (_from == "tk_ulong")
124  // _to = new ::CORBA::TypeCode(CORBA::tk_ulong);
125  // else if (_from == "tk_float")
126  // _to = new ::CORBA::TypeCode(CORBA::tk_float);
127  // else if (_from == "tk_double")
128  // _to = new ::CORBA::TypeCode(CORBA::tk_double);
129  // else if (_from == "tk_boolean")
130  // _to = new ::CORBA::TypeCode(CORBA::tk_boolean);
131  // else if (_from == "tk_char")
132  // _to = new ::CORBA::TypeCode(CORBA::tk_char);
133  // else if (_from == "tk_octet")
134  // _to = new ::CORBA::TypeCode(CORBA::tk_octet);
135  // else if (_from == "tk_any")
136  // _to = new ::CORBA::TypeCode(CORBA::tk_any);
137  // else if (_from == "tk_TypeCode")
138  // _to = new ::CORBA::TypeCode(CORBA::tk_TypeCode);
139  // else if (_from == "tk_Principal")
140  // _to = new ::CORBA::TypeCode(CORBA::tk_Principal);
141  // else if (_from == "tk_longlong")
142  // _to = new ::CORBA::TypeCode(CORBA::tk_longlong);
143  // else if (_from == "tk_ulonglong")
144  // _to = new ::CORBA::TypeCode(CORBA::tk_ulonglong);
145  // else if (_from == "tk_longdouble")
146  // _to = new ::CORBA::TypeCode(CORBA::tk_longdouble);
147  // else if (_from == "tk_wchar")
148  // _to = new ::CORBA::TypeCode(CORBA::tk_wchar);
149  // else if (_from == "tk_fixed")
150  // _to = new ::CORBA::TypeCode(CORBA::tk_fixed);
151  // else if (_from == "tk_value")
152  // _to = new ::CORBA::TypeCode(CORBA::tk_value);
153  // else if (_from == "tk_value_box")
154  // _to = new ::CORBA::TypeCode(CORBA::tk_value_box);
155  // else if (_from == "native")
156  // _to = new ::CORBA::TypeCode(CORBA::native);
157  // else if (_from == "tk_abstract_interface")
158  // _to = new ::CORBA::TypeCode(CORBA::tk_abstract_interface);
159  // else
160  // return false;
161  return true;
162 }
163 
164 //-------------------------------------------------------------
165 // corba -> local
166 inline bool corba_to_local(const ::CORBA::Short _from, short& _to)
167 {
168  _to = _from;
169  return true;
170 }
171 
172 inline bool corba_to_local(const ::CORBA::UShort _from, unsigned short& _to)
173 {
174  _to = _from;
175  return true;
176 }
177 
178 inline bool corba_to_local(const ::CORBA::Long _from, int& _to)
179 {
180  _to = _from;
181  return true;
182 }
183 
184 inline bool corba_to_local(const ::CORBA::ULong _from, unsigned int& _to)
185 {
186  _to = _from;
187  return true;
188 }
189 
190 inline bool corba_to_local(const ::CORBA::Float _from, float& _to)
191 {
192  _to = _from;
193  return true;
194 }
195 
196 inline bool corba_to_local(const ::CORBA::Double _from, double& _to)
197 {
198  _to = _from;
199  return true;
200 }
201 
202 inline bool corba_to_local(const ::CORBA::Char _from, char& _to)
203 {
204  _to = _from;
205  return true;
206 }
207 
208 inline bool corba_to_local(const ::CORBA::Boolean _from, unsigned char& _to)
209 {
210  _to = _from;
211  return true;
212 }
213 
214 inline bool corba_to_local(const ::CORBA::Octet _from, unsigned char& _to)
215 {
216  _to = _from;
217  return true;
218 }
219 
220 inline bool corba_to_local(const ::CORBA::Boolean _from, bool& _to)
221 {
222  _to = _from;
223  return true;
224 }
225 
226 inline bool corba_to_local(const char* _from, std::string& _to)
227 {
228  _to = _from;
229  return true;
230 }
231 
232 // inline bool corba_to_local(char* _from, std::string& _to)
233 // {
234 // _to = _from;
235 // }
236 
237 inline bool corba_to_local(const ::CORBA::Any& _from, std::string& _to)
238 {
239  const char* str;
240  if (_from >>= str)
241  {
242  _to = str;
243  return true;
244  }
245  ::CORBA::Short short_var;
246  if (_from >>= short_var)
247  {
248  _to = ::coil::otos(short_var);
249  return true;
250  }
251  ::CORBA::UShort ushort_var;
252  if (_from >>= ushort_var)
253  {
254  _to = ::coil::otos(ushort_var);
255  return true;
256  }
257  ::CORBA::Long long_var;
258  if (_from >>= long_var)
259  {
260  _to = ::coil::otos(long_var);
261  return true;
262  }
263  ::CORBA::ULong ulong_var;
264  if (_from >>= ulong_var)
265  {
266  _to = ::coil::otos(ulong_var);
267  return true;
268  }
269  ::CORBA::Float float_var;
270  if (_from >>= float_var)
271  {
272  _to = ::coil::otos(float_var);
273  return true;
274  }
275  ::CORBA::Double double_var;
276  if (_from >>= double_var)
277  {
278  _to = ::coil::otos(double_var);
279  return true;
280  }
281 }
282 
283 inline bool
284 corba_to_local(const CORBA::TypeCode_member& _from, std::string& _to)
285 {
286  try
287  {
288  _to = _from->name();
289  return true;
290  }
291  catch ( ::CORBA::TypeCode::BadKind& e )
292  {
293  return false;
294  }
295  return true;
296 }
297 
298 
299 #endif // DOIL_CORBA_UTIL_H
std::string otos(Printable n)
Convert the given object to std::string.
Definition: stringutil.h:566
bool local_to_corba(const short int _from,::CORBA::Short &_to)
bool corba_to_local(const ::CORBA::Short _from, short &_to)
doil CORBA header


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:50