aboutsummaryrefslogtreecommitdiff
path: root/examples/cxx/hybrid/binary/custom/irawstream.txx
blob: 635f13123970c313bfe84f0e289abc962a7d02e1 (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
// 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_sequence<T>& x)
{
  size_t n;
  irawstream::as_size as_size (n);
  s >> as_size;

  x.clear ();

  if (n > 0)
    x.assign (
      reinterpret_cast<const T*> (s.align (sizeof (T), sizeof (T) * n)), n);
}

template <typename T>
void
operator>> (irawstream& s, xml_schema::fix_sequence<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_sequence<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_sequence<T>::guard g (p);
      s >> *p;
      g.release ();
      x.push_back (p);
    }
  }
}