2 //metadoc SkipDBCursor copyright Steve Dekorte 2002
3 //metadoc SkipDBCursor license BSD revised
4 //metadoc SkipDBCursor category Databases")
6 An interator object for a SkipDB.
9 #include "IoSkipDBCursor.h"
17 #define CURSOR(self) ((SkipDBCursor *)(IoObject_dataPointer(self)))
19 IoTag
*IoSkipDBCursor_newTag(void *state
)
21 IoTag
*tag
= IoTag_newWithName_("SkipDBCursor");
22 IoTag_state_(tag
, state
);
23 IoTag_freeFunc_(tag
, (IoTagFreeFunc
*)IoSkipDBCursor_free
);
24 IoTag_cloneFunc_(tag
, (IoTagCloneFunc
*)IoSkipDBCursor_rawClone
);
25 //IoTag_markFunc_(tag, (IoTagMarkFunc *)IoSkipDBCursor_mark);
26 //IoTag_writeToStreamFunc_(tag, (IoTagWriteToStoreOnStreamFunc *)IoSkipDBCursor_writeToStore_stream_);
27 //IoTag_readFromStreamFunc_(tag, (IoTagReadFromStoreOnStreamFunc *)IoSkipDBCursor_readFromStore_stream_);
32 void IoSkipDBCursor_writeToStream_(IoObject *self, BStream *stream)
36 void IoSkipDBCursor_readFromStream_(IoObject *self, BStream *stream)
41 IoSkipDBCursor
*IoSkipDBCursor_proto(void *state
)
43 IoMethodTable methodTable
[] = {
44 {"goto", IoSkipDBCursor_goto
},
45 {"first", IoSkipDBCursor_first
},
46 {"last", IoSkipDBCursor_last
},
47 {"next", IoSkipDBCursor_next
},
48 {"previous", IoSkipDBCursor_previous
},
49 {"key", IoSkipDBCursor_key
},
50 {"value", IoSkipDBCursor_value
},
54 IoObject
*self
= IoObject_new(state
);
55 IoObject_tag_(self
, IoSkipDBCursor_newTag(state
));
57 IoObject_setDataPointer_(self
, NULL
);
58 IoState_registerProtoWithFunc_((IoState
*)state
, self
, IoSkipDBCursor_proto
);
60 IoObject_addMethodTable_(self
, methodTable
);
64 IoSkipDBCursor
*IoSkipDBCursor_rawClone(IoSkipDBCursor
*proto
)
66 IoObject
*self
= IoObject_rawClonePrimitive(proto
);
67 IoObject_tag_(self
, IoObject_tag(proto
));
68 IoObject_setDataPointer_(self
, NULL
);
72 IoSkipDBCursor
*IoSkipDBCursor_new(void *state
)
74 IoObject
*proto
= IoState_protoWithInitFunction_((IoState
*)state
, IoSkipDBCursor_proto
);
75 return IOCLONE(proto
);
78 IoSkipDBCursor
*IoSkipDBCursor_newWithSDBCursor(void *state
, SkipDBCursor
*cursor
)
80 IoSkipDBCursor
*self
= IoSkipDBCursor_new(state
);
81 SkipDBCursor_retain(cursor
);
82 IoObject_setDataPointer_(self
, cursor
);
86 void IoSkipDBCursor_free(IoSkipDBCursor
*self
)
88 if (CURSOR(self
)) SkipDBCursor_release(CURSOR(self
));
92 void IoSkipDBCursor_mark(IoSkipDBCursor *self)
97 // --------------------------------------------------------
99 IoObject
*IoSkipDBCursor_goto(IoObject
*self
, IoObject
*locals
, IoMessage
*m
)
101 /*doc SkipDBCursor goto(aKey)
102 Move cursor to the specified key or nearest preceeding key. Returns self
105 IoSeq
*key
= IoMessage_locals_seqArgAt_(m
, locals
, 0);
106 IOASSERT(CURSOR(self
), "SkipDBCursor invalid");
107 SkipDBCursor_goto_(CURSOR(self
), IoSeq_asDatum(key
));
111 IoObject
*IoSkipDBCursor_first(IoObject
*self
, IoObject
*locals
, IoMessage
*m
)
113 /*doc SkipDBCursor first
114 Move cursor to first item. Returns self.
117 IOASSERT(CURSOR(self
), "SkipDBCursor invalid");
118 SkipDBCursor_first(CURSOR(self
));
122 IoObject
*IoSkipDBCursor_last(IoObject
*self
, IoObject
*locals
, IoMessage
*m
)
124 /*doc SkipDBCursor last
125 Move cursor to last item. Returns self.
128 IOASSERT(CURSOR(self
), "SkipDBCursor invalid");
129 SkipDBCursor_last(CURSOR(self
));
133 IoObject
*IoSkipDBCursor_next(IoObject
*self
, IoObject
*locals
, IoMessage
*m
)
135 /*doc SkipDBCursor next
136 Move cursor to next item. Returns self.
139 IOASSERT(CURSOR(self
), "SkipDBCursor invalid");
140 SkipDBCursor_next(CURSOR(self
));
144 IoObject
*IoSkipDBCursor_previous(IoObject
*self
, IoObject
*locals
, IoMessage
*m
)
146 /*doc SkipDBCursor previous
147 Move cursor to previous item. Returns self.
150 IOASSERT(CURSOR(self
), "SkipDBCursor invalid");
151 SkipDBCursor_previous(CURSOR(self
));
155 IoObject
*IoSkipDBCursor_key(IoObject
*self
, IoObject
*locals
, IoMessage
*m
)
157 /*doc SkipDBCursor key
158 Returns the current cursor key, or nil if the cursor is out of range.
161 IOASSERT(CURSOR(self
), "SkipDBCursor invalid");
164 SkipDBRecord
*r
= SkipDBCursor_current(CURSOR(self
));
168 Datum k
= SkipDBRecord_keyDatum(r
);
169 return IoSeq_newWithDatum_(IOSTATE
, &k
);
176 IoObject
*IoSkipDBCursor_value(IoObject
*self
, IoObject
*locals
, IoMessage
*m
)
178 /*doc SkipDBCursor value
179 Returns the current cursor key, or nil if the cursor is out of range.
182 IOASSERT(CURSOR(self
), "SkipDBCursor invalid");
185 SkipDBRecord
*r
= SkipDBCursor_current(CURSOR(self
));
189 Datum v
= SkipDBRecord_valueDatum(r
);
190 return IoSeq_newWithDatum_(IOSTATE
, &v
);