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

#ifndef IOWEAKLINK_DEFINED 
#define IOWEAKLINK_DEFINED 1

#include "Common.h"
#include "IoObject_struct.h"
#include "IoStore.h"
#include "BStream.h"

#ifdef __cplusplus
extern "C" {
#endif

#define ISWEAKLINK(self) IoObject_hasCloneFunc_(self, (TagCloneFunc *)IoWeakLink_rawClone)

typedef IoObject IoWeakLink;

typedef struct 
{
    IoWeakLink *previousWeakLink; // linked list of weaklinks pointing to the same value 
    IoWeakLink *nextWeakLink;  
    IoObject *link;
    IoObject *delegate;
    IoObject *identifier;
} IoWeakLinkData;

IoObject *IoWeakLink_proto(void *state);
IoObject *IoWeakLink_new(void *state);

void IoWeakLink_writeToStore_stream_(IoWeakLink *self, IoStore *store, BStream *stream);
void IoWeakLink_readFromStore_stream_(IoWeakLink *self, IoStore *store, BStream *stream);

IoObject *IoWeakLink_rawClone(IoWeakLink *self);
void IoWeakLink_free(IoWeakLink *self);
void IoWeakLink_mark(IoWeakLink *self);

IoObject *IoWeakLink_rawLink(IoWeakLink *self);
IoObject *IoWeakLink_rawNextWeakLink(IoWeakLink *self);

// special weaklink methods 

void IoWeakLink_appendWeakLink_(IoWeakLink *self, IoObject *other);
void IoWeakLink_unlink(IoObject *self);
void IoWeakLink_collected(IoWeakLink *self);
void IoWeakLink_unlinkItem_(IoWeakLink *self, IoObject *other);

// ----------------------------------------------------------- 

void IoWeakLink_didCollect(IoWeakLink *self);

// ----------------------------------------------------------- 

IoObject *IoWeakLink_setLink(IoWeakLink *self, IoObject *locals, IoMessage *m);
void IoWeakLink_justSetLink(IoObject *self, IoObject *v);
IoObject *IoWeakLink_link(IoWeakLink *self, IoObject *locals, IoMessage *m);

IoObject *IoWeakLink_setDelegate(IoWeakLink *self, IoObject *locals, IoMessage *m);
IoObject *IoWeakLink_delegate(IoWeakLink *self, IoObject *locals, IoMessage *m);

IoObject *IoWeakLink_setIdentifier(IoWeakLink *self, IoObject *locals, IoMessage *m);
IoObject *IoWeakLink_identifier(IoWeakLink *self, IoObject *locals, IoMessage *m);

#ifdef __cplusplus
}
#endif
#endif
