summaryrefslogtreecommitdiff
path: root/CIAO/CCF/CCF/CompilerElements/TokenStream.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'CIAO/CCF/CCF/CompilerElements/TokenStream.hpp')
-rw-r--r--CIAO/CCF/CCF/CompilerElements/TokenStream.hpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/CIAO/CCF/CCF/CompilerElements/TokenStream.hpp b/CIAO/CCF/CCF/CompilerElements/TokenStream.hpp
new file mode 100644
index 00000000000..f1d3ab4fb8c
--- /dev/null
+++ b/CIAO/CCF/CCF/CompilerElements/TokenStream.hpp
@@ -0,0 +1,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