1 // file      : xsd/cxx/zc-istream.txx
2 // copyright : Copyright (c) 2005-2017 Code Synthesis Tools CC
3 // license   : GNU GPL v2 + exceptions; see accompanying LICENSE file
4 
5 namespace xsd
6 {
7   namespace cxx
8   {
9     // zc_streambuf
10     //
11     template <typename C>
12     zc_streambuf<C>::
zc_streambuf(const ro_string<C> & str)13     zc_streambuf (const ro_string<C>& str)
14         : str_ (str.data (), str.size ())
15     {
16       init ();
17     }
18 
19     template <typename C>
20     zc_streambuf<C>::
zc_streambuf(const std::basic_string<C> & str)21     zc_streambuf (const std::basic_string<C>& str)
22         : str_ (str)
23     {
24       init ();
25     }
26 
27     template <typename C>
28     void zc_streambuf<C>::
init()29     init ()
30     {
31       C* b (const_cast<C*> (str_.data ()));
32       C* e (b + str_.size ());
33 
34       this->setg (b, b, e);
35     }
36 
37     template <typename C>
38     std::streamsize zc_streambuf<C>::
showmanyc()39     showmanyc ()
40     {
41       return static_cast<std::streamsize> (
42         this->egptr () - this->gptr ());
43     }
44 
45     template <typename C>
46     typename zc_streambuf<C>::int_type zc_streambuf<C>::
underflow()47     underflow ()
48     {
49       int_type r = traits_type::eof ();
50 
51       if (this->gptr () < this->egptr ())
52         r = traits_type::to_int_type (*this->gptr ());
53 
54       return r;
55     }
56 
57 
58     // zc_istream_base
59     //
60     template <typename C>
61     zc_istream_base<C>::
zc_istream_base(const ro_string<C> & str)62     zc_istream_base (const ro_string<C>& str)
63         : buf_ (str)
64     {
65     }
66 
67     template <typename C>
68     zc_istream_base<C>::
zc_istream_base(const std::basic_string<C> & str)69     zc_istream_base (const std::basic_string<C>& str)
70         : buf_ (str)
71     {
72     }
73 
74 
75     // zc_istream
76     //
77     template <typename C>
78     zc_istream<C>::
zc_istream(const ro_string<C> & str)79     zc_istream (const ro_string<C>& str)
80         : zc_istream_base<C> (str),
81           std::basic_istream<C> (&this->buf_)
82     {
83     }
84 
85     template <typename C>
86     zc_istream<C>::
zc_istream(const std::basic_string<C> & str)87     zc_istream (const std::basic_string<C>& str)
88         : zc_istream_base<C> (str),
89           std::basic_istream<C> (&this->buf_)
90     {
91     }
92   }
93 }
94