Use descriptive enums for method parameters
[GenericStorageContainerTemplate.git] / GenericStorageContainerTest.cpp
index bae3589..0ffc321 100644 (file)
@@ -1,13 +1,74 @@
+#include "DataStructures.hpp"
 #include "GenericStorageContainerTemplateImpl.hpp"
+#include <iostream>
 
 using namespace tj;
+using namespace std;
 
 int
 main (int argc, char **argv, char **env)
 {
-  int* test = new int(320596); // initial test value
-  GenericStorageContainerTemplateImpl<int, Storage::dynamic_array> my_collection(test);
+  cout << "Generic Storage Template (with Iterator) Test" << endl
+       << "Copyright 2014 TJ <hacker@iam.tj>" << endl
+       << "Licensed on terms of the GNU General Public License version 3.0" << endl;
 
+  GSCTI<int, DataStructure_ArrayDynamic> my_collection_of_ints;
+
+  unsigned menu_choice;
+
+  do
+  {
+    int* test = nullptr;
+
+    cout << endl << "Menu" << endl
+         << "1. Add node" << endl
+         << "2. Remove node" << endl
+         << "3. List nodes using forward Iterator" << endl
+         << "4. List nodes using reverse Interator" << endl
+         << "0. Exit" << endl;
+
+    cin >> menu_choice;
+
+    switch (menu_choice)
+    {
+      case 0: // exit
+        break;
+      case 1: // Add node
+        test = new int(76543);
+        if (!my_collection_of_ints.append(*test))
+          cerr << "Error: insert failed" << endl;
+        break;
+      case 2: // Remove node
+        if (!my_collection_of_ints.remove())
+          cerr << "Error: remove failed" << endl;
+        break;
+      case 3: // List using forward Iterator
+        cout << "size = " << my_collection_of_ints.get_size() << endl;
+
+        /* the traditional style of iterator loop
+        for (GSCTI<int, DataStructure_ArrayDynamic>::_iterator end = my_collection_of_ints.end(),
+             i = my_collection_of_ints.begin();
+             i != end;
+             ++i)
+        {
+          cout << "Data = " << *i << endl;
+        }
+        */
+
+        /* the modern range-based for loop
+         * see http://en.cppreference.com/w/cpp/language/range-for
+         */
+        for (auto i : my_collection_of_ints) // XXX: C++11 'range for' automagically uses the iterator
+        {
+          cout << "Data = " << i << endl;
+        }
+       
+        break;
+      case 4: // List using reverse Iterator
+        break;
+    }
+
+  } while (menu_choice > 0);
 
   return 0;
 }