Use descriptive enums for method parameters
[GenericStorageContainerTemplate.git] / GenericStorageContainerTest.cpp
index 45c9822..0ffc321 100644 (file)
@@ -1,3 +1,4 @@
+#include "DataStructures.hpp"
 #include "GenericStorageContainerTemplateImpl.hpp"
 #include <iostream>
 
@@ -11,13 +12,14 @@ main (int argc, char **argv, char **env)
        << "Copyright 2014 TJ <hacker@iam.tj>" << endl
        << "Licensed on terms of the GNU General Public License version 3.0" << endl;
 
-  int* test = new int(320596); // initial test value
-  GSCTI<int, StorageClass_DynamicArray> my_collection_of_ints(*test);
+  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
@@ -33,16 +35,34 @@ main (int argc, char **argv, char **env)
         break;
       case 1: // Add node
         test = new int(76543);
-        my_collection_of_ints.add_node(test);
+        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();
-        for (int i : my_collection_of_ints) // XXX: C++11 'range for' automagically uses the 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 << "Node = " << i << endl;
+          cout << "Data = " << i << endl;
         }
+       
         break;
       case 4: // List using reverse Iterator
         break;