arrays.h

Go to the documentation of this file.
00001 /*      Arrays.h - the Array family of classes for MAXScript
00002  *
00003  *      Copyright (c) John Wainwright, 1996
00004  *      
00005  *
00006  */
00007 
00008 #pragma once
00009 
00010 #include "..\ScripterExport.h"
00011 #include "..\kernel\value.h"
00012 #include "collection.h"
00013 #include "..\..\bitarray.h"
00014 
00015 /* ------------------------ Array ------------------------------ */
00016 
00017 visible_class_debug_ok (Array)
00018 
00019 class Array : public Value, public Collection
00020 {
00021     static bool performDeepCopy;
00022 public:
00023     int         volatile size;          // array size
00024     int         data_size;              // allocated array buffer size (in Value*'s)
00025     Value**     volatile data;          // the array elements (uninitialized are set to undefined)
00026 
00027     ScripterExport static bool ArrayPerformDeepCopy(bool type);
00028 
00029     ScripterExport  static CRITICAL_SECTION array_update;   // for syncing array updates
00030 
00031     ScripterExport   Array(int init_size);
00032     ScripterExport  ~Array();
00033 
00034                 classof_methods (Array, Value);
00035 
00036     static Value* make(Value** arg_list, int count);
00037     static void setup();
00038 
00039     Value*& operator[](const int i) const { return data[i]; } // access ith array entry.
00040     
00041 #   define      is_array(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(Array))
00042     BOOL        _is_collection() { DbgAssert(!is_sourcepositionwrapper(this)); return 1; }
00043     BOOL        _is_selection() { DbgAssert(!is_sourcepositionwrapper(this)); return 1; }
00044     void        gc_trace();
00045     void        collect() { delete this; }
00046     ScripterExport void sprin1(CharStream* s);
00047 
00048     // operations
00049 #include "..\macros\define_implementations.h"
00050 #   include "..\protocols\arrays.inl"
00051     use_generic( plus, "+" );
00052     use_generic( copy, "copy" );
00053     use_generic( coerce,    "coerce");
00054     use_generic( free,      "free");
00055 
00056     ScripterExport Value* map(node_map& m);
00057     ScripterExport Value* map_path(PathName* path, node_map& m);
00058     ScripterExport Value* find_first(BOOL (*test_fn)(INode* node, int level, void* arg), void* test_arg);
00059     ScripterExport Value* get_path(PathName* path);
00060 
00061     // built-in property accessors 
00062     def_property ( count );
00063 
00064     ScripterExport Value* append(Value*);
00065     ScripterExport Value* join(Value*);
00066     ScripterExport Value* sort();
00067     ScripterExport Value* push(Value*);
00068     ScripterExport Value* drop();
00069     ScripterExport Value* get(int index);
00070     ScripterExport BOOL   deep_eq(Value* other);
00071     ScripterExport Value* deep_copy();
00072 
00073     // get selection iterator for an array
00074     SelectionIterator* selection_iterator();
00075 
00076     // scene I/O 
00077     IOResult Save(ISave* isave);
00078     static Value* Load(ILoad* iload, USHORT chunkID, ValueLoader* vload);
00079 
00080     void     to_fpvalue(FPValue& v);
00081 };
00082 
00083 /* ------------------------ BitArray ------------------------------ */
00084 
00085 visible_class_debug_ok (BitArrayValue)
00086 
00087 class BitArrayValue : public Value
00088 {
00089 public:
00090     BitArray    bits;       // the bits
00091 
00092     ScripterExport BitArrayValue();
00093     ScripterExport BitArrayValue(BitArray& b);
00094         ScripterExport BitArrayValue(int count);
00095 
00096                 classof_methods (BitArrayValue, Value);
00097 
00098     static Value* make(Value** arg_list, int count);
00099 
00100 #   define      is_BitArrayValue(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(BitArrayValue))
00101 //  BOOL        _is_collection() { return 1; }
00102     BOOL        _is_selection() { DbgAssert(!is_sourcepositionwrapper(this)); return 1; }
00103     void        collect() { delete this; }
00104     void        sprin1(CharStream* s);
00105     ScripterExport void can_hold(int index); // resize if need to hold specified index
00106 
00107     // operations
00108 #include "..\macros\define_implementations.h"
00109 #   include "..\protocols\arrays.inl"
00110     use_generic( plus, "+" );
00111     use_generic( minus, "-" );
00112     def_generic( uminus, "u-");
00113     use_generic( times, "*" );
00114     use_generic( copy, "copy" );
00115     use_generic( coerce,    "coerce");
00116     use_generic( free,      "free");
00117 
00118     ScripterExport Value* map(node_map& m);
00119 
00120     // built-in property accessors
00121     def_property ( count );
00122     def_property ( numberSet );
00123     def_property ( isEmpty );
00124 
00125     SelectionIterator* selection_iterator();
00126 
00127     BitArray&   to_bitarray() { return bits; }
00128     void        to_fpvalue(FPValue& v) { v.bits = &bits; v.type = TYPE_BITARRAY; }
00129 #   define      is_bitarray(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(BitArrayValue))
00130 
00131 };
00132