GeorgeKolog před 6 roky
rodič
revize
ef32bb4e09
3 změnil soubory, kde provedl 52 přidání a 0 odebrání
  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.
+//
+