strings.h

Go to the documentation of this file.
00001 /*  
00002  *      Strings.h - string family for MAXScript
00003  *
00004  *          Copyright (c) John Wainwright 1996
00005  *
00006  */
00007 
00008 #pragma once
00009 
00010 #include "..\foundation\streams.h"
00011 #include "..\..\assetmanagement\AssetUser.h"
00012 
00013 visible_class_debug_ok (String)
00014 
00015 // Collectable::flags3 - bit 0 set if string is a literal
00016 class String : public Value
00017 {
00018     MCHAR*      string;
00019     const MaxSDK::AssetManagement::AssetId* pAssetId;
00020 
00021 public:
00022  ScripterExport String(const MCHAR *init_string);
00023  ScripterExport String(const MCHAR *init_string, const MaxSDK::AssetManagement::AssetId& assetId);
00024                ~String();
00025 
00026                 classof_methods (String, Value);
00027 #   define      is_string(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(String))
00028     void        collect() { delete this; }
00029     ScripterExport void     sprin1(CharStream* s);
00030 
00031     Value*      append(const MCHAR* str);
00032     Value*      append(Value* str_val) { return append(str_val->to_string()); }
00033 
00034     const MaxSDK::AssetManagement::AssetId* GetAssetId();
00035 
00036 
00037 #include "..\macros\define_implementations.h"
00038 #   include "..\protocols\strings.inl"
00039 
00040     def_property( count );
00041 
00042     MCHAR*      to_string();
00043     MSTR        to_filename();
00044     void        to_fpvalue(FPValue& v) { v.s = to_string(); v.type = TYPE_STRING; }
00045     Value*      eval(); // returns new string if string is a literal
00046 
00047     // scene I/O 
00048     IOResult Save(ISave* isave);
00049     static Value* Load(ILoad* iload, USHORT chunkID, ValueLoader* vload);
00050 
00051     friend class StringStream;
00052 };
00053 
00054 applyable_class_debug_ok (StringStream)
00055 
00056 class StringStream : public CharStream
00057 {
00058 public:
00059     MCHAR*  content_string;     /* the content string               */
00060     MCHAR*  cursor;             /* current read/write cursor        */
00061     size_t  buf_len;            /* allocated buffer length          */
00062     int     ungetchar_count;
00063     Parser* reader;
00064 
00065     ScripterExport StringStream();
00066     ScripterExport ~StringStream();
00067     ScripterExport StringStream(const MCHAR* init_string);
00068     ScripterExport StringStream(int ilen);
00069     ScripterExport StringStream(Value* init_string_value);
00070     ScripterExport void init(const MCHAR* init_string);
00071 
00072             classof_methods (StringStream, CharStream);
00073 #   define  is_stringstream(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(StringStream))
00074     void    collect() { delete this; }
00075     void    gc_trace();
00076     ScripterExport void sprin1(CharStream* s);
00077 
00078  #include "..\macros\define_implementations.h"
00079  #  include "..\protocols\streams.inl"
00080     use_generic( coerce,  "coerce");
00081     use_generic( copy,    "copy");
00082     use_generic( append,  "append");
00083 
00084     Value* get_property(Value** arg_list, int count);
00085     Value* set_property(Value** arg_list, int count);
00086 
00087     // only want CharStream::file_name to be used in context of resolving resource file name
00088     Value*  get_file_name() { return NULL; } 
00089 
00090     ScripterExport MCHAR    get_char();
00091     ScripterExport void     unget_char(MCHAR c);
00092     ScripterExport MCHAR    peek_char();
00093     ScripterExport unsigned int     pos();
00094                    void     seek(int pos);
00095     ScripterExport int      at_eos();
00096     ScripterExport void     rewind();
00097     ScripterExport void     set_size(int size);
00098     ScripterExport void     flush_to_eol();
00099     ScripterExport void     flush_to_eobuf();
00100     ScripterExport void     undo_lookahead();
00101 
00102     ScripterExport  const MCHAR*    puts(const MCHAR* str);
00103     ScripterExport  MCHAR   putch(MCHAR c);
00104     ScripterExport  int     printf(const MCHAR *format, ...);
00105 
00106     MCHAR*  to_string();
00107     void    to_fpvalue(FPValue& v) { v.s = to_string(); v.type = TYPE_STRING; }
00108 };
00109 
00110 ScripterExport MSTR expand_file_name(const MCHAR* file_name);
00111 ScripterExport MSTR expand_file_dir(const MCHAR* dir);
00112