rename files
[iotcloud.git] / version2 / src / C / SlotIndexer.cpp
diff --git a/version2/src/C/SlotIndexer.cpp b/version2/src/C/SlotIndexer.cpp
new file mode 100644 (file)
index 0000000..b49ca45
--- /dev/null
@@ -0,0 +1,27 @@
+#include "SlotIndexer.h"
+#include "Slot.h"
+#include "Error.h"
+#include "SlotBuffer.h"
+/**
+ * Slot indexer allows slots in both the slot buffer and the new
+ * server response to looked up in a consistent fashion.
+ * @author Brian Demsky
+ * @version 1.0
+ */
+
+SlotIndexer::SlotIndexer(Array<Slot *> *_updates, SlotBuffer *_buffer) :
+       updates(_updates),
+       buffer(_buffer),
+       firstslotseqnum(updates->get(0)->getSequenceNumber()) {
+}
+
+Slot *SlotIndexer::getSlot(int64_t seqnum) {
+       if (seqnum >= firstslotseqnum) {
+               int32_t offset = (int32_t) (seqnum - firstslotseqnum);
+               if (((uint32_t)offset) >= updates->length())
+                       throw new Error("Invalid Slot Sequence Number Reference");
+               else
+                       return updates->get(offset);
+       } else
+               return buffer->getSlot(seqnum);
+}