structs.h

Go to the documentation of this file.
00001 /*      Structs.h - the MAXSript struct definition classes
00002  *
00003  *      Copyright (c) John Wainwright, 1996
00004  *      
00005  */
00006 
00007 #pragma once
00008 
00009 #include "..\kernel\value.h"
00010 #include "functions.h"
00011 // forward declarations
00012 class HashTabMapper;
00013 class StructMemberThunk;
00014 
00015 visible_class_debug_ok (StructDef)
00016 
00017 class StructDef : public Value
00018 {
00019     friend StructMemberThunk;
00020     friend Struct;
00021     friend void Function::export_to_scripter();
00022 private:
00023     Value*      name;                       /* struct's global var name */
00024     Value**     member_inits;               /* member init vals         */
00025     int         member_count;               /*   "    count             */
00026     HashTable*  members;                    /* member name to index table */
00027     HashTable*  member_isPublicAccess;      /* member name is public?   */
00028     HashTable*  handlers;                   /* event handlers */
00029 
00030 public:
00031 
00032     // note: if members is null, a default hashtable is created in the ctor
00033     // if member_isPublicAccess is null, all members are considered public. If member cannot be found in member_isPublicAccess, member is considered public
00034     ScripterExport StructDef(Value* name, int member_count, Value** inits, HashTable* members, HashTable* member_isPublicAccess, HashTable* handlers);
00035                 ~StructDef();
00036                 classof_methods (StructDef, Value);
00037 #   define      is_structdef(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(StructDef))
00038 
00039     void        collect() { delete this; }
00040     void        gc_trace();
00041     ScripterExport void     sprin1(CharStream* s);
00042 
00043 #include "..\macros\define_implementations.h"
00044     def_generic ( get_props,    "getPropNames"); // LAM: added 4/27/00
00045     def_generic ( show_props,   "showProperties");
00046 
00047     ScripterExport Value* apply(Value** arglist, int count, CallContext* cc=NULL);
00048     ScripterExport Value* get_property(Value** arg_list, int count);
00049     ScripterExport Value* set_property(Value** arg_list, int count);
00050     ScripterExport bool   IsPropertyPublic(Value* prop);
00051     ScripterExport Value* Name();
00052     ScripterExport void   map_members(HashTabMapper* mapper);
00053     ScripterExport void   map_members(void (*fn)(const void* key, const void* val, void* arg), void* arg);
00054     ScripterExport Value* get_member_value(Value* key);
00055     ScripterExport Value* put_member_value(Value* key, Value* value);
00056 };
00057 
00058 class Struct : public Value
00059 {
00060 public:
00061     StructDef*  definition;                 /* pointer to my struct def                         */
00062     Value**     member_data;                /* data elements, indexed via struct def hashtable  */
00063 
00064     ScripterExport Struct(StructDef* idef, int mem_count);
00065                 ~Struct();
00066 
00067 #   define      is_struct(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == INTERNAL_STRUCT_TAG)
00068     Value*      classOf_vf(Value** arg_list, int count);
00069     Value*      superClassOf_vf(Value** arg_list, int count);
00070     Value*      isKindOf_vf(Value** arg_list, int count);
00071     BOOL        is_kind_of(ValueMetaClass* c) { return (c == class_tag(StructDef)) ? 1 : Value::is_kind_of(c); }
00072 
00073     void        collect() { delete this; }
00074     void        gc_trace();
00075     ScripterExport void     sprin1(CharStream* s);
00076 
00077 #include "..\macros\define_implementations.h"
00078     use_generic ( copy, "copy" );
00079     def_generic ( get_props,    "getPropNames"); // LAM: added 4/27/00
00080     def_generic ( show_props,   "showProperties");
00081 
00082     Value*      get_property(Value** arg_list, int count);
00083     Value*      set_property(Value** arg_list, int count);
00084 
00085     // scene I/O 
00086     IOResult Save(ISave* isave);
00087     static Value* Load(ILoad* iload, USHORT chunkID, ValueLoader* vload);
00088 
00089     // added 3/21/05. Used by debugger to dump locals to standard out
00090     void        dump_local_vars(int indentLevel);
00091 
00092     // added 4/25/08. Used for create handler
00093     Value* call_handler(Value* handler, Value** arg_list, int count);
00094 };
00095 
00096