summaryrefslogtreecommitdiff
path: root/trunk/TAO/tests/Sequence_Unit_Tests/bounded_sequence_cdr.hpp
blob: fba15efe71f63ca77107dd18bd3df4286c5a37bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef guard_bounded_sequence_cdr
#define guard_bounded_sequence_cdr
/**
 * @file
 *
 * @brief Extract the sequence
 *
 * $Id$
 *
 * @author Carlos O'Ryan
 * @author Johnny Willemsen
 */

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

namespace TAO {
  namespace details {
    template <typename stream, typename sequence>
    bool extract_bounded_sequence(stream & strm, sequence & target) {
      ::CORBA::ULong new_length;
      if (!(strm >> new_length)) {
        return false;
      }
      if (new_length > strm.length()) {
         return false;
      }
      if (new_length > target.maximum ()) {
         return false;
      }
      sequence tmp;
      tmp.length(new_length);
      typename sequence::value_type * buffer = tmp.get_buffer();
      for(CORBA::ULong i = 0; i < new_length; ++i) {
        if (!(strm >> buffer[i])) {
          return false;
        }
      }
      tmp.swap(target);
      return true;
    }

    template <typename stream, typename sequence>
    bool insert_bounded_sequence(stream & strm, const sequence & source) {
      const ::CORBA::ULong length = source.length ();
      if (!(strm << length)) {
        return false;
      }
      for(CORBA::ULong i = 0; i < length; ++i) {
        if (!(strm << source[i])) {
          return false;
        }
      }
      return true;
    }
  }
}

TAO_END_VERSIONED_NAMESPACE_DECL
#endif /* guard_bounded_sequence_cdr */