Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Sequence_Unit_Tests / unbounded_sequence_cdr.hpp
blobe34cdba3e6dd8fa95d82c232286d1c20d3b02c68
1 #ifndef guard_unbounded_sequence_cdr
2 #define guard_unbounded_sequence_cdr
3 /**
4 * @file
6 * @brief Extract the sequence
8 * @author Carlos O'Ryan
9 * @author Johnny Willemsen
12 #include "tao/Basic_Types.h"
13 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
14 namespace TAO {
15 namespace details {
16 template <typename stream, typename sequence>
17 bool extract_unbounded_sequence(stream & strm, sequence & target) {
18 ::CORBA::ULong new_length;
19 if (!(strm >> new_length)) {
20 return false;
22 if (new_length > strm.length()) {
23 return false;
25 sequence tmp(new_length);
26 tmp.length(new_length);
27 typename sequence::value_type * buffer = tmp.get_buffer();
28 for(CORBA::ULong i = 0; i < new_length; ++i) {
29 if (!(strm >> buffer[i])) {
30 return false;
33 tmp.swap(target);
34 return true;
37 template <typename stream, typename sequence>
38 bool insert_unbounded_sequence(stream & strm, const sequence & source) {
39 const CORBA::ULong length = source.length ();
40 if (!(strm << length)) {
41 return false;
43 for(CORBA::ULong i = 0; i < length; ++i) {
44 if (!(strm << source[i])) {
45 return false;
48 return true;
53 TAO_END_VERSIONED_NAMESPACE_DECL
54 #endif /* guard_unbounded_sequence_cdr */