edits
[iotcloud.git] / version2 / src / C / SlotIndexer.cc
1 #include "SlotIndexer.h"
2
3 /**
4  * Slot indexer allows slots in both the slot buffer and the new
5  * server response to looked up in a consistent fashion.
6  * @author Brian Demsky
7  * @version 1.0
8  */
9
10 SlotIndexer::SlotIndexer(Array<Slot*> * _updates, SlotBuffer * _buffer) :
11         buffer(_buffer),
12         updates(_updates),
13         firstslotseqnum(updates->get(0)->getSequenceNumber()) {
14 }
15
16 Slot * SlotIndexer::getSlot(int64_t seqnum) {
17         if (seqnum >= firstslotseqnum) {
18                 int32_t offset = (int32_t) (seqnum - firstslotseqnum);
19                 if (offset >= updates->length())
20                         throw new Error("Invalid Slot Sequence Number Reference");
21                 else
22                         return updates->get(offset);
23         } else
24                 return buffer->getSlot(seqnum);
25 }