/*   
docCopyright("Steve Dekorte", 2002)
docLicense("BSD revised")
*/

#ifdef IOOBJECTGROUP_C 
#define IO_IN_C_FILE
#endif
#include "Common_inline.h"
#ifdef IO_DECLARE_INLINES

/*
IOINLINE void IoObjectGroup_checkFirst(IoObjectGroup *self)
{
	IoObject *v = self->first;
	unsigned char color = self->mark.color;
	
	if (self->first)
	{ 
		if (self->first->mark.previous)
		{
			printf("ObjectGroup error: first has previous\n");
			exit(-1);
		}
	}
}


IOINLINE void IoObjectGroup_checkColors(IoObjectGroup *self)
{
	IoObject *v = self->first;
	unsigned char color = self->mark.color;
	
	while (v) 
	{ 
		if (v->mark.color != color)
		{
			printf("IoObjectGroup_checkColors - non matching color found!\n");
			exit(-1);
		} 
		
		v = v->mark.next; 
	}
}
*/

IOINLINE void IoObjectGroup_isRemoving_(IoObjectGroup *self,  IoObject *v)
{ 
	IoObject *vNext     = (IoObject *)v->mark.next;
	IoObject *vPrevious = (IoObject *)v->mark.previous;
	
    if (self->first == v) 
    {
		self->first = vNext; 
    }
    
    // unlink it 
	
    if (vPrevious) 
    { 
		vPrevious->mark.next = vNext; 
    }
    
    if (vNext)
    { 
		vNext->mark.previous = vPrevious; 
    }
    
    //v->mark.next     = 0x0;
    //v->mark.previous = 0x0;
}

char *IoObject_colorNameForValue(IoObject *self, unsigned int c);


IOINLINE void IoObjectGroup_append_(IoObjectGroup *self, IoObject *v)
{
	/*
	if (self->first == v)
	{
		printf("\nIoObjectGroup_append_ error: attempt to add '%s' object already in '%s' group\n", 
			  IoObject_colorNameForValue(v, v->mark.color), 
			  IoObject_colorNameForValue(v, self->mark.color) );	
		exit(-1);
	}
	*/
	
    // append it to the beginning 
	
    v->mark.previous = 0x0;
    v->mark.next = self->first;
    
    if (self->first)
    {
		self->first->mark.previous = v;
    }
    
    self->first = v;
    
    v->mark.color = self->mark.color;
    
    //IoObjectGroup_checkFirst(self);
    //IoObjectGroup_checkColors(self);
}

//#endif

#undef IO_IN_C_FILE
#endif
