streams.h

Go to the documentation of this file.
00001  /* 
00002   *     Streams.h - stream family for MAXScript
00003   *
00004   *         Copyright � John Wainwright 1996
00005   *
00006   */
00007  
00008 #pragma once
00009  
00010  class Listener;
00011  class FileStream;
00012  class StringStream;
00013  class Parser;
00014  
00015 #include "..\ScripterExport.h"
00016 #include "..\kernel\value.h"
00017 #include "..\compiler\codetree.h"
00018 
00019  visible_class_debug_ok (CharStream)
00020  
00021 // Collectable::flags3 - bit 1 set if have attempted to load resource file
00022 // Collectable::flags3 - bit 2 set if Parser::get_char() doesn't echo character to error line buffer. This
00023 //      is used when converting a resource id to resource value, where the string corresponding to the resource
00024 //      value is placed in a stringstream, and that stringstream is set as the parser source. We don't want the
00025 //      resource value string in the error buffer since the resource id is already there.
00026 class CharStream : public Value
00027  {
00028  protected:
00029      unsigned int   mlineNumber;
00030 //   bool           mTrippedLineFeed;
00031 
00032      Value*         file_name;          // source file
00033      HashTable*     resourceMap;        // resource hashtable associated with source file
00034      StringStream*  resourceValueStream; // resource stream used to process the resource value string by the parser
00035 
00036  public:
00037     ScripterExport CharStream();
00038     ScripterExport virtual ~CharStream();
00039 
00040                     classof_methods (CharStream, Value);
00041             BOOL    _is_charstream() { DbgAssert(!is_sourcepositionwrapper(this)); return 1; }
00042  #  define          is_charstream(v) ((v)->_is_charstream())
00043 
00044     virtual void    gc_trace();
00045  
00046     virtual MCHAR   get_char() = 0;
00047     virtual void    unget_char(MCHAR c) = 0;
00048     virtual MCHAR   peek_char() = 0;
00049     virtual int     at_eos() = 0;
00050     virtual void    rewind() = 0;
00051 
00052     virtual unsigned int pos();
00053     virtual unsigned int line(); // Get the current line
00054 
00055 //  bool            getTrippedLineFeed(bool reset = true); // get whether passed a line feed since last setTrippedLineFeed(false)/reset
00056 //  void            setTrippedLineFeed(bool val); // set whether passed a line feed
00057 
00058     virtual void    seek(int pos);
00059     virtual void    flush_to_eol() = 0;
00060     virtual void    flush_to_eobuf();
00061     virtual void    flush_whitespace();
00062  
00063     virtual MCHAR   putch(MCHAR c) { return c; }
00064     virtual const MCHAR*    puts(const MCHAR* str) { return str; }
00065     #pragma warning(push)
00066     #pragma warning(disable:4100)
00067     virtual int     printf(const MCHAR* format, ...) { return 0; }
00068     #pragma warning(pop)
00069     virtual void    close();
00070     virtual void    flush();
00071  
00072     virtual void    log_to(CharStream* log);
00073     virtual void    close_log();
00074     virtual Listener* get_listener() { return NULL; }
00075     virtual CharStream* get_log() { return NULL; }
00076 
00077     virtual Value*  get_file_name();
00078     virtual void    set_file_name(const TCHAR* fileName); // just sets the file_name member variable
00079     virtual CharStream* get_resource_value_stream(Value* resourceID);
00080  };
00081  
00082  visible_class_debug_ok (FileStream)
00083  
00084  class FileStream : public CharStream
00085  {
00086  public:
00087     MCHAR*  mode;
00088     FILE*   file;
00089     CharStream* log;
00090     Parser* reader;
00091     DWORD   decrypt;
00092     int     ungetchar_count;
00093     MCHAR   ungetchar_buf[8];
00094     // Constructor / Destructor
00095             ScripterExport FileStream();
00096             ScripterExport ~FileStream();
00097  
00098             classof_methods (FileStream, CharStream);
00099  #  define  is_filestream(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(FileStream))
00100     void    collect() { delete this; }
00101     void    gc_trace();
00102     ScripterExport void sprin1(CharStream* s);
00103  
00104  #include "..\macros\define_implementations.h"
00105  #  include "..\protocols\streams.inl"
00106  
00107     /* internal char stream protocol */
00108     ScripterExport MCHAR    get_char();
00109     ScripterExport void     unget_char(MCHAR c);
00110     ScripterExport MCHAR    peek_char();
00111     ScripterExport int      at_eos();
00112     ScripterExport unsigned int pos();
00113     ScripterExport unsigned int line(); // Gets the current line number
00114     ScripterExport void     seek(int pos);
00115     ScripterExport void     rewind();
00116     ScripterExport void     flush_to_eol();
00117  
00118     ScripterExport MCHAR    putch(MCHAR c);
00119     ScripterExport const MCHAR* puts(const MCHAR* str);
00120     ScripterExport int      printf(const MCHAR *format, ...);
00121  
00122     ScripterExport FileStream* open_decrypt(const MCHAR* ifile_name, int seed);
00123     ScripterExport FileStream* open(const MCHAR* ifile_name, const MCHAR* imode);
00124     ScripterExport void flush();
00125     ScripterExport void close();
00126     void    log_to(CharStream* log);
00127     void    close_log();
00128 
00129     void    undo_lookahead();
00130 
00131     void    check_readable();
00132     void    check_writeable();
00133  };
00134  
00135  visible_class_debug_ok (WindowStream)
00136  
00137  // Collectable::flags3 - bit 0 set if WindowStream is wrapping a MXS_Scintilla edit control. If not, standard
00138  // edit control is assumed
00139  class WindowStream : public CharStream
00140  {
00141  public:
00142     HWND        window;
00143     int         cursor;
00144     MCHAR*      title;
00145     Listener*   listener;
00146     CharStream* log;
00147     MCHAR       wputs_buf[512];         // edit control output buffer
00148     MCHAR*      wputs_p;
00149     HWND        echo;
00150  
00151     // Constructor / Destructor
00152                 WindowStream(HWND iwin);
00153                 WindowStream(MCHAR* title);     /* for background scripts; window with given title will open if output generated */
00154                ~WindowStream();
00155  
00156                 classof_methods (WindowStream, CharStream);
00157     void        collect() { delete this; }
00158     void        gc_trace();
00159     ScripterExport void sprin1(CharStream* s);
00160  
00161  #include "..\macros\define_implementations.h"
00162     def_generic(sprint,   "sprint");
00163     use_generic( coerce,  "coerce");
00164     use_generic( flush,   "flush"); 
00165         
00166     /* internal MCHAR stream protocol */
00167     
00168     MCHAR       get_char() { return 0; }
00169     void        unget_char(MCHAR c) { UNUSED_PARAM(c); }
00170     MCHAR       peek_char() {return 0; }
00171     int         at_eos() { return TRUE; }
00172     void        rewind() {}
00173     void        flush_to_eol() {}
00174  
00175     ScripterExport MCHAR    putch(MCHAR c);
00176     ScripterExport const MCHAR* puts(const MCHAR* str);
00177     ScripterExport int      printf(const MCHAR *format, ...);
00178     ScripterExport void     flush();
00179 
00180     void        ensure_window_open();
00181  
00182     void        log_to(CharStream* log);
00183     void        close_log();
00184     Listener*   get_listener() { return listener; }
00185     CharStream* get_log() { return log; }
00186 
00187     // edit control output primitives
00188     ScripterExport MCHAR*   wputs(const MCHAR *str);
00189     ScripterExport void     wflush();
00190     ScripterExport MCHAR    wputch(const MCHAR c);
00191     ScripterExport int      wprintf(const MCHAR *format, ...);
00192                    void     set_echo_window(HWND wnd) { echo = wnd; }
00193                    void     echo_cur_line();
00194                    int      get_cur_line(MSTR& line);
00195 };
00196  
00197