summaryrefslogtreecommitdiff
path: root/TAO/CIAO/CCF/CCF/CompilerElements/TokenStream.hpp
blob: 27e5c40d6c7ce565a4adc57f2fccc767078927d8 (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
#ifndef TOKEN_STREAM_HPP
#define TOKEN_STREAM_HPP

#include <string>
#include <istream>

namespace CCF
{
  template <typename Token>
  class TokenStream
  {
  public:
    virtual Token
    next () = 0;
  };


  template <>
  class TokenStream<char>
  {
  public:
    typedef
    std::char_traits<char>
    traits;

    typedef
    traits::int_type
    int_type;

    typedef
    traits::char_type
    char_type;

  public:
    virtual int_type
    next () = 0;

    char_type
    to_char_type (int_type i)
    {
      return traits::to_char_type (i);
    }

    bool
    eos (int_type i)
    {
      return i == traits::eof ();
    }
  };

  class InputStreamAdapter : public TokenStream<char>
  {
  public:
    InputStreamAdapter (std::istream& is)
        : is_ (is)
    {
    }

  public:

    virtual int_type
    next ()
    {
      return is_.get ();
    }

  private:
    std::istream& is_;
  };
}

#endif //TOKEN_STREAM_HPP