Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tao / CDR.inl
blob2180ec07e88fb9a2f95391353761d2f481d8c1e2
1 // -*- C++ -*-
2 #include "tao/SystemException.h"
3 #include <cstring>
5 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
7 ACE_INLINE
8 TAO_OutputCDR::~TAO_OutputCDR ()
12 ACE_INLINE bool
13 TAO_OutputCDR::more_fragments () const
15   return this->more_fragments_;
18 ACE_INLINE void
19 TAO_OutputCDR::more_fragments (bool more)
21   this->more_fragments_ = more;
24 ACE_INLINE void
25 TAO_OutputCDR::message_attributes (CORBA::ULong request_id,
26                                    TAO_Stub * stub,
27                                    TAO_Message_Semantics message_semantics,
28                                    ACE_Time_Value * timeout)
30   this->request_id_        = request_id;
31   this->stub_              = stub;
32   this->message_semantics_ = message_semantics;
33   this->timeout_           = timeout;
36 ACE_INLINE CORBA::ULong
37 TAO_OutputCDR::request_id () const
39   return this->request_id_;
42 ACE_INLINE TAO_Stub *
43 TAO_OutputCDR::stub () const
45   return this->stub_;
48 ACE_INLINE TAO_Message_Semantics
49 TAO_OutputCDR::message_semantics () const
51   return this->message_semantics_;
54 ACE_INLINE ACE_Time_Value *
55 TAO_OutputCDR::timeout () const
57   return this->timeout_;
60 ACE_INLINE void
61 TAO_OutputCDR::get_version (TAO_GIOP_Message_Version& giop_version)
63   giop_version.set_version (this->major_version_, this->minor_version_);
66 ACE_INLINE TAO_OutputCDR::Repo_Id_Map_Handle&
67 TAO_OutputCDR::get_repo_id_map ()
69   return this->repo_id_map_;
72 #ifdef TAO_HAS_VALUETYPE_CODEBASE
73 ACE_INLINE TAO_OutputCDR::Codebase_URL_Map_Handle&
74 TAO_OutputCDR::get_codebase_url_map ()
76   return this->codebase_map_;
78 #endif
80 ACE_INLINE TAO_OutputCDR::Value_Map_Handle&
81 TAO_OutputCDR::get_value_map ()
83   return this->value_map_;
86 ACE_INLINE void
87 TAO_OutputCDR::set_repo_id_map (TAO_OutputCDR::Repo_Id_Map_Handle& map)
89   this->repo_id_map_ = map;
92 #ifdef TAO_HAS_VALUETYPE_CODEBASE
93 ACE_INLINE void
94 TAO_OutputCDR::set_codebase_url_map (TAO_OutputCDR::Codebase_URL_Map_Handle& map)
96   this->codebase_map_ = map;
98 #endif
100 ACE_INLINE void
101 TAO_OutputCDR::set_value_map (TAO_OutputCDR::Value_Map_Handle& map)
103   this->value_map_ = map;
106 ACE_INLINE void
107 TAO_OutputCDR::reset_vt_indirect_maps ()
109   if (! this->repo_id_map_.is_nil () && this->repo_id_map_->get()->current_size () != 0)
110   {
111     this->repo_id_map_->get()->unbind_all ();
112   }
113 #ifdef TAO_HAS_VALUETYPE_CODEBASE
114   if (! this->codebase_map_.is_nil () && this->codebase_map_->get()->current_size () != 0)
115   {
116     this->codebase_map_->get()->unbind_all ();
117   }
118 #endif
119   if (! this->value_map_.is_nil () && this->value_map_->get()->current_size () != 0)
120   {
121     this->value_map_->get()->unbind_all ();
122   }
125 // -------------------------------------------------------------------
127 ACE_INLINE
128 TAO_InputCDR::TAO_InputCDR (const char *buf,
129                             size_t bufsiz,
130                             int byte_order,
131                             ACE_CDR::Octet major_version,
132                             ACE_CDR::Octet minor_version,
133                             TAO_ORB_Core* orb_core)
134   : ACE_InputCDR (buf,
135                   bufsiz,
136                   byte_order,
137                   major_version,
138                   minor_version),
139     orb_core_ (orb_core)
143 ACE_INLINE
144 TAO_InputCDR::TAO_InputCDR (size_t bufsiz,
145                             int byte_order,
146                             ACE_CDR::Octet major_version,
147                             ACE_CDR::Octet minor_version,
148                             TAO_ORB_Core* orb_core)
149   : ACE_InputCDR (bufsiz,
150                   byte_order,
151                   major_version,
152                   minor_version),
153     orb_core_ (orb_core)
157 ACE_INLINE
158 TAO_InputCDR::TAO_InputCDR (const ACE_Message_Block *data,
159                             int byte_order,
160                             ACE_CDR::Octet major_version,
161                             ACE_CDR::Octet minor_version,
162                             TAO_ORB_Core* orb_core)
163   : ACE_InputCDR (data,
164                   byte_order,
165                   major_version,
166                   minor_version),
167     orb_core_ (orb_core)
171 ACE_INLINE
172 TAO_InputCDR::TAO_InputCDR (const ACE_Message_Block *data,
173                             ACE_Lock* lock,
174                             int byte_order,
175                             ACE_CDR::Octet major_version,
176                             ACE_CDR::Octet minor_version,
177                             TAO_ORB_Core* orb_core)
178   : ACE_InputCDR (data,
179                   byte_order,
180                   major_version,
181                   minor_version,
182                   lock),
183     orb_core_ (orb_core)
187 ACE_INLINE
188 TAO_InputCDR::TAO_InputCDR (ACE_Data_Block *data,
189                             ACE_Message_Block::Message_Flags flag,
190                             int byte_order,
191                             ACE_CDR::Octet major_version,
192                             ACE_CDR::Octet minor_version,
193                             TAO_ORB_Core* orb_core)
194   : ACE_InputCDR (data,
195                   flag,
196                   byte_order,
197                   major_version,
198                   minor_version),
199     orb_core_ (orb_core)
204 ACE_INLINE
205 TAO_InputCDR::TAO_InputCDR (ACE_Data_Block *data,
206                             ACE_Message_Block::Message_Flags flag,
207                             size_t rd_pos,
208                             size_t wr_pos,
209                             int byte_order,
210                             ACE_CDR::Octet major_version,
211                             ACE_CDR::Octet minor_version,
212                             TAO_ORB_Core* orb_core)
213   : ACE_InputCDR (data,
214                   flag,
215                   rd_pos,
216                   wr_pos,
217                   byte_order,
218                   major_version,
219                   minor_version),
220     orb_core_ (orb_core)
225 ACE_INLINE
226 TAO_InputCDR::TAO_InputCDR (const TAO_InputCDR& rhs,
227                             size_t size,
228                             ACE_CDR::Long offset)
229   : ACE_InputCDR (rhs,
230                   size,
231                   offset),
232     orb_core_ (rhs.orb_core_)
236 ACE_INLINE
237 TAO_InputCDR::TAO_InputCDR (const TAO_InputCDR& rhs,
238                             size_t size)
239   : ACE_InputCDR (rhs,
240                   size),
241     orb_core_ (rhs.orb_core_)
245 ACE_INLINE
246 TAO_InputCDR::TAO_InputCDR (const TAO_InputCDR& rhs)
247   : ACE_InputCDR (rhs),
248     orb_core_ (rhs.orb_core_),
249     repo_id_map_ (rhs.repo_id_map_),
250     codebase_map_ (rhs.codebase_map_),
251     value_map_ (rhs.value_map_)
255 ACE_INLINE
256 TAO_InputCDR::TAO_InputCDR (ACE_InputCDR::Transfer_Contents rhs,
257                             TAO_ORB_Core* orb_core)
258   : ACE_InputCDR (rhs),
259     orb_core_ (orb_core)
264 ACE_INLINE
265 TAO_InputCDR::~TAO_InputCDR ()
269 ACE_INLINE TAO_ORB_Core*
270 TAO_InputCDR::orb_core () const
272   return this->orb_core_;
276 ACE_INLINE TAO_InputCDR::Repo_Id_Map_Handle&
277 TAO_InputCDR::get_repo_id_map ()
279   return this->repo_id_map_;
282 ACE_INLINE TAO_InputCDR::Codebase_URL_Map_Handle&
283 TAO_InputCDR::get_codebase_url_map ()
285   return this->codebase_map_;
288 ACE_INLINE TAO_InputCDR::Value_Map_Handle&
289 TAO_InputCDR::get_value_map ()
291   return this->value_map_;
294 ACE_INLINE void
295 TAO_InputCDR::set_repo_id_map (TAO_InputCDR::Repo_Id_Map_Handle& map)
297   this->repo_id_map_ = map;
300 ACE_INLINE void
301 TAO_InputCDR::set_codebase_url_map (TAO_InputCDR::Codebase_URL_Map_Handle& map)
303   this->codebase_map_ = map;
306 ACE_INLINE void
307 TAO_InputCDR::set_value_map (TAO_InputCDR::Value_Map_Handle& map)
309   this->value_map_ = map;
312 ACE_INLINE void
313 TAO_InputCDR::reset_vt_indirect_maps ()
315   if (! this->repo_id_map_.is_nil () && this->repo_id_map_->get()->current_size () != 0)
316   {
317     this->repo_id_map_->get()->unbind_all ();
318   }
319   if (! this->codebase_map_.is_nil () && this->codebase_map_->get()->current_size () != 0)
320   {
321     this->codebase_map_->get()->unbind_all ();
322   }
323   if (! this->value_map_.is_nil () && this->value_map_->get()->current_size () != 0)
324   {
325     this->value_map_->get()->unbind_all ();
326   }
329 // ****************************************************************
331 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
332                                       CORBA::Short x)
334   return
335     os.fragment_stream (ACE_CDR::SHORT_ALIGN,
336                         sizeof (CORBA::Short))
337     && static_cast<ACE_OutputCDR &> (os) << x;
340 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
341                                       CORBA::UShort x)
343   return
344     os.fragment_stream (ACE_CDR::SHORT_ALIGN,
345                         sizeof (CORBA::UShort))
346     && static_cast<ACE_OutputCDR &> (os) << x;
349 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
350                                       CORBA::Long x)
352   return
353     os.fragment_stream (ACE_CDR::LONG_ALIGN,
354                         sizeof (CORBA::Long))
355     && static_cast<ACE_OutputCDR &> (os) << x;
358 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
359                                       CORBA::ULong x)
361   return
362     os.fragment_stream (ACE_CDR::LONG_ALIGN,
363                         sizeof (CORBA::ULong))
364     && static_cast<ACE_OutputCDR &> (os) << x;
367 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
368                                       CORBA::LongLong x)
370   return
371     os.fragment_stream (ACE_CDR::LONGLONG_ALIGN,
372                         sizeof (CORBA::LongLong))
373     && static_cast<ACE_OutputCDR &> (os) << x;
376 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
377                                       CORBA::ULongLong x)
379   return
380     os.fragment_stream (ACE_CDR::LONGLONG_ALIGN,
381                         sizeof (CORBA::ULongLong))
382     && static_cast<ACE_OutputCDR &> (os) << x;
385 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR& os,
386                                       CORBA::LongDouble x)
388   return
389     os.fragment_stream (ACE_CDR::LONGDOUBLE_ALIGN,
390                         sizeof (CORBA::LongDouble))
391     && static_cast<ACE_OutputCDR &> (os) << x;
394 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
395                                       CORBA::Float x)
397   return
398     os.fragment_stream (ACE_CDR::LONG_ALIGN,
399                         sizeof (CORBA::Float))
400     && static_cast<ACE_OutputCDR &> (os) << x;
403 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
404                                       CORBA::Double x)
406   return
407     os.fragment_stream (ACE_CDR::LONGLONG_ALIGN,
408                         sizeof (CORBA::Double))
409     && static_cast<ACE_OutputCDR &> (os) << x;
412 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
413                                       const char * x)
415   return
416     os.fragment_stream (ACE_CDR::OCTET_ALIGN,
417                         sizeof (char))
418     && static_cast<ACE_OutputCDR &> (os) << x;
421 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
422                                       const CORBA::WChar * x)
424   return
425     os.fragment_stream ((sizeof (CORBA::WChar) == 2
426                          ? ACE_CDR::SHORT_ALIGN
427                          : ACE_CDR::LONG_ALIGN),
428                         sizeof (CORBA::WChar))
429     && static_cast<ACE_OutputCDR &> (os) << x;
432 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
433                                       ACE_OutputCDR::from_string x)
435   if (x.bound_ != 0 && x.val_ != 0 &&
436       std::strlen (x.val_) > x.bound_)
437     {
438       throw CORBA::BAD_PARAM ();
439     }
440   return os << x.val_;
443 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
444                                       ACE_OutputCDR::from_wstring x)
446   if (x.bound_ != 0 && x.val_ != 0 &&
447       ACE_OS::strlen (x.val_) > x.bound_)
448     {
449       throw CORBA::BAD_PARAM ();
450     }
451   return os << x.val_;
454 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
455                                       const std::string &x)
457   return
458     os.fragment_stream (ACE_CDR::OCTET_ALIGN,
459                         sizeof (char))
460     && static_cast<ACE_OutputCDR &> (os) << x;
463 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
464                                       ACE_OutputCDR::from_std_string x)
466   if (x.bound_ != 0 &&
467       static_cast<ACE_CDR::ULong> (x.val_.size ()) > x.bound_)
468     {
469       throw CORBA::BAD_PARAM ();
470     }
471   return os << x.val_;
474 #if !defined(ACE_LACKS_STD_WSTRING)
475 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
476                                       const std::wstring &x)
478   return
479     os.fragment_stream ((sizeof (CORBA::WChar) == 2
480                          ? ACE_CDR::SHORT_ALIGN
481                          : ACE_CDR::LONG_ALIGN),
482                         sizeof (CORBA::WChar))
483     && static_cast<ACE_OutputCDR &> (os) << x;
486 ACE_INLINE CORBA::Boolean operator<< (TAO_OutputCDR &os,
487                                       ACE_OutputCDR::from_std_wstring x)
489   if (x.bound_ != 0 &&
490       static_cast<ACE_CDR::ULong> (x.val_.size ()) > x.bound_)
491     {
492       throw CORBA::BAD_PARAM ();
493     }
494   return os << x.val_;
496 #endif /* ACE_LACKS_STD_WSTRING */
498 // ****************************************************************
500 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
501                                       CORBA::Short &x)
503   return static_cast<ACE_InputCDR &> (is) >> x;
506 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
507                                       CORBA::UShort &x)
509   return static_cast<ACE_InputCDR &> (is) >> x;
512 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
513                                       CORBA::Long &x)
515   return static_cast<ACE_InputCDR&> (is) >> x;
518 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
519                                       CORBA::ULong &x)
521   return static_cast<ACE_InputCDR &> (is) >> x;
524 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
525                                       CORBA::LongLong &x)
527   return static_cast<ACE_InputCDR &> (is) >> x;
530 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
531                                       CORBA::ULongLong &x)
533   return static_cast<ACE_InputCDR &> (is) >> x;
536 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
537                                       CORBA::LongDouble &x)
539   return static_cast<ACE_InputCDR &> (is) >> x;
542 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
543                                       CORBA::Float &x)
545   return static_cast<ACE_InputCDR &> (is) >> x;
548 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
549                                       CORBA::Double &x)
551   return static_cast<ACE_InputCDR &> (is) >> x;
554 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
555                                       CORBA::Char* &x)
557   return static_cast<ACE_InputCDR &> (is) >> x;
560 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
561                                       CORBA::WChar* &x)
563   return static_cast<ACE_InputCDR &> (is) >> x;
566 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
567                                       ACE_InputCDR::to_string x)
569   CORBA::Boolean const marshal_flag =
570     is >> const_cast<ACE_CDR::Char *&> (x.val_);
571   if (marshal_flag && x.bound_ != 0 && x.val_ != 0 &&
572       std::strlen (x.val_) > x.bound_)
573     {
574       throw CORBA::BAD_PARAM ();
575     }
576   return marshal_flag;
579 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
580                                       ACE_InputCDR::to_wstring x)
582   CORBA::Boolean const marshal_flag =
583     is >> const_cast<ACE_CDR::WChar *&> (x.val_);
584   if (marshal_flag && x.bound_ != 0 && x.val_ != 0 &&
585       ACE_OS::strlen (x.val_) > x.bound_)
586     {
587       throw CORBA::BAD_PARAM ();
588     }
589   return marshal_flag;
592 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
593                                       std::string &x)
595   return static_cast<ACE_InputCDR &> (is) >> x;
598 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
599                                       ACE_InputCDR::to_std_string x)
601   CORBA::Boolean const marshal_flag = is >> x.val_;
602   if (marshal_flag && x.bound_ != 0 && x.val_.size () > x.bound_)
603     {
604       throw CORBA::BAD_PARAM ();
605     }
606   return marshal_flag;
609 #if !defined(ACE_LACKS_STD_WSTRING)
610 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
611                                       std::wstring &x)
613   return static_cast<ACE_InputCDR &> (is) >> x;
616 ACE_INLINE CORBA::Boolean operator>> (TAO_InputCDR &is,
617                                       ACE_InputCDR::to_std_wstring x)
619   CORBA::Boolean const marshal_flag = is >> x.val_;
620   if (marshal_flag && x.bound_ != 0 && x.val_.size () > x.bound_)
621     {
622       throw CORBA::BAD_PARAM ();
623     }
624   return marshal_flag;
626 #endif /* ACE_LACKS_STD_WSTRING */
628 TAO_END_VERSIONED_NAMESPACE_DECL