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