Revision: 44635
          http://brlcad.svn.sourceforge.net/brlcad/?rev=44635&view=rev
Author:   davidloman
Date:     2011-05-19 19:11:45 +0000 (Thu, 19 May 2011)

Log Message:
-----------
Implement a path stepper that can step thru FS directories and .g files with 
the same path.  Needs cleanup and generalizing, but it works.

Modified Paths:
--------------
    geomcore/trunk/include/FileDataSource.h
    geomcore/trunk/src/GS/FileDataSource.cxx
    geomcore/trunk/tests/func/GE/CMakeLists.txt
    geomcore/trunk/tests/func/GE/GeometryEngineTest.cxx

Modified: geomcore/trunk/include/FileDataSource.h
===================================================================
--- geomcore/trunk/include/FileDataSource.h     2011-05-19 17:37:41 UTC (rev 
44634)
+++ geomcore/trunk/include/FileDataSource.h     2011-05-19 19:11:45 UTC (rev 
44635)
@@ -32,6 +32,8 @@
 #include <string>
 #include <list>
 
+#define PATH_DELIM "/"
+
 class FileDataSource : public IDataSource
 {
 public:
@@ -68,9 +70,15 @@
 
         static void buildFullPath(std::string* out, std::string* base, 
std::string* path);
         static void cleanString(std::string* out);
+
+        static int walkPath(std::string path);
+       static int pathToStringStack(std::string path, std::list<std::string>* 
stringStack);
 private:
        std::string repoPath;
        std::list<std::string> locks;
+
+        static int walkPathFS(const std::list<std::string>* strStack, const 
unsigned int stackPos);
+        static int walkPathG(const std::list<std::string>* strStack, const 
unsigned int stackPos);
 };
 
 #endif /* __FILEDATASOURCE_H__ */

Modified: geomcore/trunk/src/GS/FileDataSource.cxx
===================================================================
--- geomcore/trunk/src/GS/FileDataSource.cxx    2011-05-19 17:37:41 UTC (rev 
44634)
+++ geomcore/trunk/src/GS/FileDataSource.cxx    2011-05-19 19:11:45 UTC (rev 
44635)
@@ -22,6 +22,8 @@
  */
 
 #include "FileDataSource.h"
+#include "db.h"
+#include "raytrace.h"
 #include <sys/stat.h>
 #include <stdio.h>
 #include <string.h>
@@ -151,6 +153,146 @@
     }
 }
 
+
+int
+FileDataSource::walkPath(std::string path)
+{
+  std::list<std::string> pathArr;
+  FileDataSource::pathToStringStack(path, &pathArr);
+
+  return FileDataSource::walkPathFS(&pathArr, 0);
+}
+
+int
+FileDataSource::walkPathFS(const std::list<std::string>* strStack, const 
unsigned int stackPos)
+{
+  std::string pathSoFar = "";
+  std::string pathStep = "";
+  int step = stackPos;
+  int ford = 0;
+  std::list<std::string>::const_iterator it = strStack->begin();
+
+  /* fast forward */
+  for (int i = 0; i < stackPos; ++i)
+    {
+      pathStep = (std::string) *it;
+      pathSoFar += pathStep;
+      ++it;
+    }
+
+  for (; it != strStack->end(); ++it)
+    {
+      pathStep = (std::string)*it;
+      pathSoFar += pathStep;
+      ford = FileDataSource::existsFileOrDir(pathSoFar.c_str());
+
+      std::cout << "step: "<<pathStep<<" cumulative: "<<pathSoFar << " ford:" 
<< ford << std::endl;
+
+      if (ford == 2) {
+          ++step;
+          /* Goto walkPathG */
+          return walkPathG(strStack, step);
+      } else if (ford == 1) {
+          ++step;
+          pathSoFar += "/";
+          continue;
+      } else if (ford == 0) {
+          return step * -1; /* Failed */
+      } else {
+          return step * -1; /* Failed */
+      }
+    }
+}
+
+int
+FileDataSource::walkPathG(const std::list<std::string>* strStack, const 
unsigned int stackPos)
+{
+  std::string pathSoFar = "";
+  std::string pathStep = "";
+  std::list<std::string>::const_iterator it = strStack->begin();
+  struct db_i *dbip;
+  struct directory *dp;
+  struct db_full_path dfp;
+  int dbStep = 0;
+  int exists = 0;
+
+  /* fast forward */
+  for (int i = 0; i < stackPos; ++i)
+    {
+      pathStep = (std::string) *it;
+      pathSoFar += pathStep;
+      ++it;
+
+      if (i != (stackPos-1))
+        pathSoFar += "/";
+    }
+
+  /* Open DB file */
+  if ((dbip = db_open(pathSoFar.c_str(), "r")) == DBI_NULL) {
+      perror(pathSoFar.c_str());
+      bu_exit(1, "Unable to open geometry file (%s)\n", pathSoFar.c_str());
+  }
+  if (db_dirbuild(dbip)) {
+      bu_exit(1, "ERROR: db_dirbuild failed\n");
+  }
+
+  /* Assuming we are at TOPs here. */
+  pathSoFar = "";
+
+  for (; it != strStack->end(); ++it)
+    {
+      pathStep = (std::string) *it;
+      pathSoFar += pathStep;
+
+      std::cout << "G step: " << pathStep << " cumulative: " << pathSoFar
+          << " dbStep:" << dbStep << std::endl;
+
+      db_full_path_init(&dfp);
+      exists = db_string_to_path(&dfp, dbip, pathSoFar.c_str());
+      db_free_full_path(&dfp);
+
+      if (exists != 0) {
+          /* failed */
+          break;
+      }
+
+      pathSoFar += "/";
+      ++dbStep;
+    }
+
+  db_close(dbip);
+  return dbStep + stackPos;
+}
+
+int
+FileDataSource::pathToStringStack(std::string path, std::list<std::string>* 
stringStack)
+{
+  std::string sub = "";
+  size_t endPos = 0;
+  int cnt = 0;
+
+  do {
+      endPos = path.find_first_of(PATH_DELIM);
+      if (endPos == std::string::npos){
+          if (path.length() <=0)
+              break;
+          else
+              endPos = path.length();
+      }
+      sub = path.substr(0, endPos);
+      std::cout << sub << std::endl;
+      if (sub.length() > 0) {
+        stringStack->push_back(sub);
+        ++cnt;
+      }
+      path = path.erase(0, endPos+1);
+
+  } while (endPos != std::string::npos);
+
+  return cnt;
+}
+
+
 /*
  * Local Variables:
  * tab-width: 8

Modified: geomcore/trunk/tests/func/GE/CMakeLists.txt
===================================================================
--- geomcore/trunk/tests/func/GE/CMakeLists.txt 2011-05-19 17:37:41 UTC (rev 
44634)
+++ geomcore/trunk/tests/func/GE/CMakeLists.txt 2011-05-19 19:11:45 UTC (rev 
44635)
@@ -7,6 +7,7 @@
 
 SET( geTest_LIBS
        ${BRLCAD_LIBRARIES}
+       libgeomserv
 )
 
 add_executable(geTest GeometryEngineTest.cxx)

Modified: geomcore/trunk/tests/func/GE/GeometryEngineTest.cxx
===================================================================
--- geomcore/trunk/tests/func/GE/GeometryEngineTest.cxx 2011-05-19 17:37:41 UTC 
(rev 44634)
+++ geomcore/trunk/tests/func/GE/GeometryEngineTest.cxx 2011-05-19 19:11:45 UTC 
(rev 44635)
@@ -24,9 +24,11 @@
 
 #include <bu.h>
 #include <raytrace.h>
+#include <list>
+#include "FileDataSource.h"
 
 struct node_data {
-  struct char* path;
+  char* path;
   struct bu_external extList;
 };
 
@@ -47,11 +49,23 @@
 leaf_fn_call(struct db_tree_state *tsp, const struct db_full_path *pathp,
     struct rt_db_internal *ip, genptr_t)
 {
-
+  int i = 0;
   char *name = db_path_to_string(pathp);
-  std::cout << "leaf: '" << name << "'" << std::endl;
+  std::cout << "leaf: '"; // << name << "'" << std::endl;
 
+  for (i = 0; i < pathp->fp_len; ++i)
+    if (pathp->fp_names[i])
+      std::cout << "/" << pathp->fp_names[i]->d_namep;
+    else
+      std::cout << "/" << "**NULL**";
 
+  std::cout << "\tMAX i = " << i << std::endl;
+
+  bu_external* ext = 
(bu_external*)bu_calloc(sizeof(bu_external),1,"bu_external calloc");
+  int rVal = db_get_external(ext, pathp->fp_names[i], tsp->ts_dbip);
+
+
+
   return (union tree *)NULL;
 }
 
@@ -67,6 +81,15 @@
   const char* gName = argv[1];
   std::cout << "Using: '" << gName << "' ." << std::endl;
 
+  std::string testName(gName);
+  int ret = FileDataSource::walkPath(testName);
+
+  std::cout << "\nDone, got: " << ret << "\n" << std::endl;
+
+
+  return 0;
+
+
   std::list<node_data> dataList;
   struct db_i* dbip = DBI_NULL;
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to