Revert "Remove mysql and oracle resources for anna-ericsson project"
[anna.git] / example / dbos / workdir / filesystem / Directory.cpp
diff --git a/example/dbos/workdir/filesystem/Directory.cpp b/example/dbos/workdir/filesystem/Directory.cpp
new file mode 100644 (file)
index 0000000..e22c859
--- /dev/null
@@ -0,0 +1,69 @@
+// ANNA - Anna is Not Nothingness Anymore                                                         //
+//                                                                                                //
+// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
+//                                                                                                //
+// See project site at http://redmine.teslayout.com/projects/anna-suite                           //
+// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
+
+
+#include <iostream>
+
+#include "Directory.hpp"
+#include "File.hpp"
+
+using namespace std;
+using namespace anna;
+using namespace workdir;
+
+void filesystem::Directory::print (const int level) const
+   throw ()
+{
+   filesystem::Directory::const_child_iterator ii;
+   filesystem::Directory::const_child_iterator maxii = child_end ();
+   const filesystem::Directory* auxd;
+   const filesystem::File* auxf; 
+   int row = 0;
+   bool hasDirectories = false;
+
+   for (int space = 0; space < level; space ++)
+      cout << "   ";
+
+   cout << getName () << "/ (" << child_size () << "): " << endl;
+   
+   /* 
+    * Recorre todas las dependencias y visualiza primero todos los ficheros
+    */
+   for (ii = child_begin (); ii != maxii; ii ++) {
+      auxf = filesystem::File::down_cast (filesystem::Directory::child (ii));
+      
+      if (auxf == NULL) {
+         hasDirectories = true;
+         continue;
+      }
+      
+      if (row == 0) {
+         for (int space = 0; space < level +  1; space ++)
+            cout << "   ";
+      }
+      
+      auxf->print (level + 1);
+      
+      if (++ row == 5) {
+         cout << endl;
+         row = 0;
+      }
+   }
+
+   if (row > 0)
+      cout << endl;
+   
+   /* 
+    * Trata los directorios recursivamente
+    */
+   for (ii = child_begin (); hasDirectories == true && ii != maxii; ii ++) {
+      auxd = filesystem::Directory::down_cast (filesystem::Directory::child (ii));
+      
+      if (auxd != NULL)
+         auxd->print (level + 1);
+   }      
+}