Parcourir la source

added UnitsQueue

GeorgeKolog il y a 6 ans
Parent
commit
ef32bb4e09
3 fichiers modifiés avec 52 ajouts et 0 suppressions
  1. 15 0
      include/UnitsQueue.h
  2. 33 0
      source/UnitsQueue.cpp
  3. 4 0
      testQueue.cpp

+ 15 - 0
include/UnitsQueue.h

@@ -0,0 +1,15 @@
+#include <vector>
+
+class Unit;
+
+class UnitsQueue{
+private:
+    std::vector<Unit*> queue_;
+    typedef std::vector<Unit*>::iterator viterator;
+public:
+    void add(Unit*);
+    void remove(viterator);
+    void remove(Unit*);
+    viterator beginIterator();
+    viterator endIterator();
+};

+ 33 - 0
source/UnitsQueue.cpp

@@ -0,0 +1,33 @@
+#include "../include/UnitsQueue.h"
+#include <vector>
+#include <string>
+
+void UnitsQueue::add(Unit* unit){
+    queue_.push_back(unit);
+}
+
+void UnitsQueue::remove(viterator iter){
+    if (beginIterator() <= iter && iter < endIterator()){
+        queue_.erase(iter);
+        return;
+    }
+    throw std::string("Iterator is not in UnitsQueue");
+}
+
+void UnitsQueue::remove(Unit* unit){
+    for (viterator it = beginIterator(); it != endIterator();++it){
+        if( (*it) == unit){
+            remove(it);
+            return;
+        }
+    }
+    throw std::string("Unit* is not in UnitsQueue");
+}
+
+UnitsQueue::viterator UnitsQueue::beginIterator() {
+    return queue_.begin();
+}
+
+UnitsQueue::viterator UnitsQueue::endIterator(){
+    return queue_.end();
+}

+ 4 - 0
testQueue.cpp

@@ -0,0 +1,4 @@
+//
+// Created by 1 on 23.04.2018.
+//
+