aboutsummaryrefslogtreecommitdiff
path: root/examples/cxx/hybrid/binary/custom/irawstream.txx
blob: 2d4965e071f402a28aa238213a14cd9c1155cbdd (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
// file      : examples/cxx/hybrid/binary/custom/irawostream.txx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : not copyrighted - public domain

#include <string.h> // memcpy

template <typename T>
void
operator>> (irawstream& s, xml_schema::pod_seq<T>& x)
{
  size_t n;
  irawstream::as_size as_size (n);
  s >> as_size;

  x.clear ();

  if (n > 0)
  {
    x.reserve (n);
    size_t mn = sizeof (T) * n;
    memcpy (x.data_, s.align (sizeof (T), mn), mn);
    x.size_ = n;
  }
}

template <typename T>
void
operator>> (irawstream& s, xml_schema::fix_seq<T>& x)
{
  size_t n;
  irawstream::as_size as_size (n);
  s >> as_size;

  x.clear ();

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

    while (n--)
    {
      T i;
      s >> i;
      x.push_back (i);
    }
  }
}

template <typename T>
void
operator>> (irawstream& s, xml_schema::var_seq<T>& x)
{
  size_t n;
  irawstream::as_size as_size (n);
  s >> as_size;

  x.clear ();

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

    while (n--)
    {
      T* p = new T;
      typename xml_schema::var_seq<T>::guard g (p);
      s >> *p;
      g.release ();
      x.push_back (p);
    }
  }
}