aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/hybrid/xdr/string-sequence.cxx
blob: 53054acb1d9a4f5b140a7d0bdfcf86e57f6376e1 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// file      : xsde/cxx/hybrid/xdr/string-sequence.cxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#include <xsde/cxx/hybrid/xdr/istream.hxx>
#include <xsde/cxx/hybrid/xdr/ostream.hxx>

namespace xsde
{
  namespace cxx
  {
    namespace hybrid
    {
#ifdef XSDE_EXCEPTIONS

      void
      operator<< (oxdrstream& s, const string_sequence& x)
      {
        s << oxdrstream::as_size (x.size ());

        for (string_sequence::const_iterator i = x.begin ();
             i != x.end (); ++i)
        {
          s << *i;
        }
      }

      void
      operator>> (ixdrstream& s, string_sequence& x)
      {
        size_t n;
        ixdrstream::as_size as_size (n);
        s >> as_size;

        x.clear ();

        if (n > 0)
        {
          x.reserve (n);

#ifdef XSDE_STL
          std::string i;
#else
          char* i;
#endif
          while (n--)
          {
            s >> i;
            x.push_back (i);
          }
        }
      }

#else // XSDE_EXCEPTIONS

      bool
      operator<< (oxdrstream& s, const string_sequence& x)
      {
        if (!(s << oxdrstream::as_size (x.size ())))
          return false;

        for (string_sequence::const_iterator i = x.begin ();
             i != x.end (); ++i)
        {
          if (!(s << *i))
            return false;
        }

        return true;
      }

      bool
      operator>> (ixdrstream& s, string_sequence& x)
      {
        size_t n;
        ixdrstream::as_size as_size (n);

        if (!(s >> as_size))
          return false;

        x.clear ();

        if (n > 0)
        {
          if (x.reserve (n))
            return false;

#ifdef XSDE_STL
          std::string i;
#else
          char* i;
#endif
          while (n--)
          {
            if (!(s >> i) || x.push_back (i))
              return false;
          }
        }

        return true;
      }

#endif // XSDE_EXCEPTIONS
    }
  }
}