summaryrefslogtreecommitdiff
path: root/modules/CIAO/CCF/CCF/CompilerElements/TokenStream.hpp
blob: f1d3ab4fb8c91d99f9d26869a60e9c6a16a1e9b7 (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
// file      : CCF/CompilerElements/TokenStream.hpp
// author    : Boris Kolpackov <boris@dre.vanderbilt.edu>
// cvs-id    : $Id$

#ifndef CCF_COMPILER_ELEMENTS_TOKEN_STREAM_HPP
#define CCF_COMPILER_ELEMENTS_TOKEN_STREAM_HPP

#include <string>
#include <istream>

namespace CCF
{
  namespace CompilerElements
  {
    template <typename Token>
    class TokenStream
    {
    public:
      // (JP 06-04-06) Not required by C++ spec, but it
      // eliminates buggy GCC warnings.
      virtual ~TokenStream () {}

      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;

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

      static int_type
      eos ()
      {
        return 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 // CCF_COMPILER_ELEMENTS_TOKEN_STREAM_HPP