aboutsummaryrefslogtreecommitdiff
path: root/libxsd/xsd/cxx/zc-istream.txx
blob: a6998e4897451760f1c642bdabaf4bc109cbb1b1 (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
// file      : xsd/cxx/zc-istream.txx
// copyright : Copyright (c) 2005-2017 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

namespace xsd
{
  namespace cxx
  {
    // zc_streambuf
    //
    template <typename C>
    zc_streambuf<C>::
    zc_streambuf (const ro_string<C>& str)
        : str_ (str.data (), str.size ())
    {
      init ();
    }

    template <typename C>
    zc_streambuf<C>::
    zc_streambuf (const std::basic_string<C>& str)
        : str_ (str)
    {
      init ();
    }

    template <typename C>
    void zc_streambuf<C>::
    init ()
    {
      C* b (const_cast<C*> (str_.data ()));
      C* e (b + str_.size ());

      this->setg (b, b, e);
    }

    template <typename C>
    std::streamsize zc_streambuf<C>::
    showmanyc ()
    {
      return static_cast<std::streamsize> (
        this->egptr () - this->gptr ());
    }

    template <typename C>
    typename zc_streambuf<C>::int_type zc_streambuf<C>::
    underflow ()
    {
      int_type r = traits_type::eof ();

      if (this->gptr () < this->egptr ())
        r = traits_type::to_int_type (*this->gptr ());

      return r;
    }


    // zc_istream_base
    //
    template <typename C>
    zc_istream_base<C>::
    zc_istream_base (const ro_string<C>& str)
        : buf_ (str)
    {
    }

    template <typename C>
    zc_istream_base<C>::
    zc_istream_base (const std::basic_string<C>& str)
        : buf_ (str)
    {
    }


    // zc_istream
    //
    template <typename C>
    zc_istream<C>::
    zc_istream (const ro_string<C>& str)
        : zc_istream_base<C> (str),
          std::basic_istream<C> (&this->buf_)
    {
    }

    template <typename C>
    zc_istream<C>::
    zc_istream (const std::basic_string<C>& str)
        : zc_istream_base<C> (str),
          std::basic_istream<C> (&this->buf_)
    {
    }
  }
}