Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Sequence_Unit_Tests / bounded_sequence_cdr.hpp
blob6e303ed266c089df7ab9ce2a3ef07f6d699a417e
1 #ifndef guard_bounded_sequence_cdr
2 #define guard_bounded_sequence_cdr
3 /**
4 * @file
6 * @brief Extract the sequence
8 * @author Carlos O'Ryan
9 * @author Johnny Willemsen
12 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
14 namespace TAO {
15 namespace details {
16 template <typename stream, typename sequence>
17 bool extract_bounded_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 if (new_length > target.maximum ()) {
26 return false;
28 sequence tmp;
29 tmp.length(new_length);
30 typename sequence::value_type * buffer = tmp.get_buffer();
31 for(CORBA::ULong i = 0; i < new_length; ++i) {
32 if (!(strm >> buffer[i])) {
33 return false;
36 tmp.swap(target);
37 return true;
40 template <typename stream, typename sequence>
41 bool insert_bounded_sequence(stream & strm, const sequence & source) {
42 const ::CORBA::ULong length = source.length ();
43 if (!(strm << length)) {
44 return false;
46 for(CORBA::ULong i = 0; i < length; ++i) {
47 if (!(strm << source[i])) {
48 return false;
51 return true;
56 TAO_END_VERSIONED_NAMESPACE_DECL
57 #endif /* guard_bounded_sequence_cdr */