Click here to Skip to main content
15,885,985 members
Articles / Programming Languages / C++

Building a simple C++ script compiler from Scintilla and CINT

Rate me:
Please Sign up or sign in to vote.
4.73/5 (25 votes)
8 Jul 2006CPOL7 min read 153.9K   7.6K   85  
How to build a simple C++ script compiler from Scintilla and CINT.
/* /% C++ %/ */
/***********************************************************************
 * cint (C/C++ interpreter)
 ************************************************************************
 * header file sstrm.h
 ************************************************************************
 * Description:
 *  Stub file for making iostream library
 ************************************************************************
 * Copyright(c) 1999       Masaharu Goto (MXJ02154@niftyserve.or.jp)
 *
 ************************************************************************/

#ifndef G__SSTREAM_H
#define G__SSTREAM_H

#ifndef __CINT__

#include <sstream>
using namespace std;

#else // __CINT__

#include <string>
//#include <memory>
class allocator<char>;
class allocator<wchar_t>;
#include "iostrm.h"

template<class charT, class traits, class Allocator>
class basic_stringbuf : public basic_streambuf<charT, traits>
{
 public:
  typedef charT                                    char_type;
  typedef traits::int_type               int_type;
  typedef traits::pos_type               pos_type;
  typedef traits::off_type               off_type;
  typedef traits                                   traits_type;
  
  typedef basic_ios<charT, traits>                 ios_type;
#ifdef __CINT__
  typedef string  string_type;
#else
  typedef basic_string<charT, traits, Allocator >  string_type;
#endif
  
  explicit basic_stringbuf(ios_base::openmode which = 
			   ios_base::in | ios_base::out );
  
  explicit basic_stringbuf(const string_type& str,
			   ios_base::openmode which = 
			   ios_base::in | ios_base::out );
  
  virtual ~basic_stringbuf();
  
  string_type str() const;
  void str(const string_type& str_arg);
  
 protected:

  virtual int_type overflow(int_type c = traits::eof());
  virtual int_type pbackfail(int_type c = traits::eof());
  virtual int_type underflow();
  virtual pos_type seekoff(off_type off, ios_base::seekdir way,
			   ios_base::openmode which =
			   ios_base::in | ios_base::out);

  virtual pos_type seekpos(pos_type sp,
			   ios_base::openmode which =
			   ios_base::in | ios_base::out);

  virtual basic_streambuf<charT,traits>* setbuf(char_type* s, streamsize n);
  virtual streamsize xsputn(const char_type *s, streamsize n);
 private:
  basic_stringbuf& operator=(const basic_stringbuf& x);
};


template<class charT, class traits, class Allocator>
class basic_istringstream : public basic_istream<charT, traits>
{
 public:
  typedef charT                                           char_type;
  typedef traits::int_type                      int_type;
  typedef traits::pos_type                      pos_type;
  typedef traits::off_type                      off_type;
  typedef traits                                          traits_type;
  
  typedef basic_stringbuf<charT, traits, Allocator>       sb_type;
  typedef basic_ios<charT, traits>                        ios_type;
#ifdef __CINT__
  typedef string         string_type;
#else
  typedef basic_string<charT, traits, Allocator >         string_type;
#endif
  
  explicit basic_istringstream(ios_base::openmode which = ios_base::in);
  explicit basic_istringstream(const string_type& str,
			       ios_base::openmode which = ios_base::in);

  virtual ~basic_istringstream();
  
  basic_stringbuf<charT, traits, Allocator> *rdbuf() const;
  string_type str() const;

  void str(const string_type& str);
};


template<class charT, class traits, class Allocator>
class basic_ostringstream : public basic_ostream<charT, traits>
{
 public:
  typedef charT                                             char_type;
  typedef traits::int_type                        int_type;
  typedef traits::pos_type                        pos_type;
  typedef traits::off_type                        off_type;
  typedef traits                                            traits_type;
      
  typedef basic_stringbuf<charT, traits, Allocator>         sb_type;
  typedef basic_ios<charT, traits>                          ios_type;
#ifdef __CINT__
  typedef string          string_type;
#else
  typedef basic_string<charT, traits, Allocator>            string_type;
#endif

  explicit basic_ostringstream(ios_base::openmode which = ios_base::out);
  explicit basic_ostringstream(const string_type& str,
			       ios_base::openmode which = ios_base::out);

  virtual ~basic_ostringstream();
  basic_stringbuf<charT, traits, Allocator> *rdbuf() const;

  string_type str() const;
  void str(const string_type& str);
};


template<class charT, class traits, class Allocator>
class basic_stringstream : public basic_iostream<charT, traits>
{
 public:
  typedef charT                                             char_type;
  typedef traits::int_type                        int_type;
  typedef traits::pos_type                        pos_type;
  typedef traits::off_type                        off_type;
  typedef traits                                            traits_type;
      
  typedef basic_stringbuf<charT, traits, Allocator>         sb_type;
  typedef basic_ios<charT, traits>                          ios_type;
#ifdef __CINT__
  typedef string            string_type;
#else
  typedef basic_string<charT, traits, Allocator>            string_type;
#endif

  explicit basic_stringstream(ios_base::openmode which = ios_base::out | 
			      ios_base::in);
  
  explicit basic_stringstream(const string_type& str,
			      ios_base::openmode which = 
			      ios_base::out | ios_base::in);
  
  virtual ~basic_stringstream();
  basic_stringbuf<charT, traits, Allocator> *rdbuf() const;
  string_type str() const;
  void str(const string_type& str);
};


//typedef basic_stringbuf<char>    stringbuf;
typedef basic_stringbuf<char,char_traits<char>,allocator<char> > stringbuf;
  
//typedef basic_stringbuf<wchar_t>           wstringbuf;
//typedef basic_stringbuf<wchar_t,char_traits<wchar_t>,allocator<wchar_t> > wstringbuf;

//typedef basic_istringstream<char>      istringstream;
typedef basic_istringstream<char,char_traits<char>,allocator<char> > istringstream;
  
//typedef basic_istringstream<wchar_t>       wistringstream;
//typedef basic_istringstream<wchar_t,char_traits<wchar_t>,allocator<wchar_t> > wistringstream;

//typedef basic_ostringstream<char>    ostringstream;
typedef basic_ostringstream<char,char_traits<char>,allocator<char> > ostringstream;
  
//typedef basic_ostringstream<wchar_t>    wostringstream;
//typedef basic_ostringstream<wchar_t,char_traits<wchar_t>,allocator<wchar_t> > wostringstream;

//typedef basic_stringstream<char>   stringstream;
typedef basic_stringstream<char,char_traits<char>,allocator<char> > stringstream;

//typedef basic_stringstream<wchar_t>  wstringstream;
//typedef basic_stringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstringstream;

#endif // __CINT__

#endif // G__SSTREAM_H

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions