Ref counting
[iotcloud.git] / version2 / src / C / SlotIndexer.cc
index f093c40c3dfb9f9760c3856fe650ff85101c6cb5..b49ca454e749953f152d9ef85f0caf75933675b9 100644 (file)
@@ -1,4 +1,7 @@
-
+#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.
@@ -6,25 +9,19 @@
  * @version 1.0
  */
 
-class SlotIndexer {
-       Slot[] updates;
-       SlotBuffer buffer;
-       int64_t firstslotseqnum;
-
-       SlotIndexer(Slot[] _updates, SlotBuffer _buffer) {
-               buffer = _buffer;
-               updates = _updates;
-               firstslotseqnum = updates[0].getSequenceNumber();
-       }
+SlotIndexer::SlotIndexer(Array<Slot *> *_updates, SlotBuffer *_buffer) :
+       updates(_updates),
+       buffer(_buffer),
+       firstslotseqnum(updates->get(0)->getSequenceNumber()) {
+}
 
-       Slot getSlot(int64_t seqnum) {
-               if (seqnum >= firstslotseqnum) {
-                       int offset = (int) (seqnum - firstslotseqnum);
-                       if (offset >= updates.length)
-                               throw new Error("Invalid Slot Sequence Number Reference");
-                       else
-                               return updates[offset];
-               } else
-                       return buffer.getSlot(seqnum);
-       }
+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);
 }