/*******************************************************
 *                                                     
 *  draw.object Library        GCW  27/12/94          
 *                                                     
 *******************************************************/

/* ------------ object class -------------------- */

/* Base class for storing data in string arrays   */

#ifndef _draw_object
#define _draw_object 1
#endif

class object
{
 obj_end, obj_start,obj_string, p;
}

/* ----------- Object methods ----------------- */

object::object(size)
{
 if (!typeof(p))
 {
    p = obj_start = @(obj_string = newstring(size));     // first object
    obj_end = obj_start + size;
 }
 return this;
}

object::start()
{ return obj_start; }

object::str()
{ return obj_string; }

object::here()
{ return p; }

object::push_word(w)
{ 
 putword(p,w);
 p += 4;
 if (p >= obj_end)
    quit("overflow\n");
}

object::push_byte(c)
{
 putbyte(p++,c);
 if (p >= obj_end)
    quit("overflow\n");
}

object::push_string(s)
{
 local len;
 if (p + (len = sizeof(s)) >= obj_end)
    quit("overflow\n");
 $$(p,s); p += len;    
}

object::read(offset)
{ return word(obj_start+offset); }

object::write(offset,data)
{ putword(obj_start+offset,data); }

/* ------------ end of object definitions ------------- */
