Revision: 44694
http://brlcad.svn.sourceforge.net/brlcad/?rev=44694&view=rev
Author: davidloman
Date: 2011-05-25 19:34:16 +0000 (Wed, 25 May 2011)
Log Message:
-----------
Implement contains() and getExtObj().
Modified Paths:
--------------
geomcore/trunk/include/BrlcadDb.h
geomcore/trunk/src/GS/BrlcadDb.cxx
Modified: geomcore/trunk/include/BrlcadDb.h
===================================================================
--- geomcore/trunk/include/BrlcadDb.h 2011-05-25 19:27:41 UTC (rev 44693)
+++ geomcore/trunk/include/BrlcadDb.h 2011-05-25 19:34:16 UTC (rev 44694)
@@ -24,6 +24,8 @@
#ifndef __BRLCADDB_H__
#define __BRLCADDB_H__
+#include "ExtObject.h"
+
#include <string>
#include <list>
@@ -58,6 +60,19 @@
*/
const int list(const std::string path, std::list<std::string>* list);
+
+ /**
+ * Verifies whether this DB contains the specified name.
+ * This should be used to check names only.
+ * To check a valid path, use isValidPath();
+ */
+ bool contains (const std::string name);
+
+ /**
+ * Builds an ExtObject if 'name' exists in this database
+ */
+ ExtObject* getExtObj(const std::string name);
+
private:
std::string path;
struct db_i* dbip;
@@ -89,10 +104,23 @@
/**
* Performs the actual list lookup. To be used internally only.
- * NOTE: Does not call open() or close(). See list() that.
+ * NOTE: Does not call open() or close(). See list().
*/
const int _list(const std::string path, std::list<std::string>* list);
+ /**
+ * Performs the actual name lookup. To be used internally only.
+ * NOTE: Does not call open() or close(). See list().
+ */
+ bool _contains(const std::string name);
+
+ /**
+ * Performs the actual name lookup. To be used internally only.
+ * NOTE: Does not call open() or close(). See list().
+ */
+ ExtObject* _getExtObj(const std::string name);
+
+
};
#endif /* __BRLCADDB_H__ */
Modified: geomcore/trunk/src/GS/BrlcadDb.cxx
===================================================================
--- geomcore/trunk/src/GS/BrlcadDb.cxx 2011-05-25 19:27:41 UTC (rev 44693)
+++ geomcore/trunk/src/GS/BrlcadDb.cxx 2011-05-25 19:34:16 UTC (rev 44694)
@@ -84,7 +84,6 @@
this->close();
return retVal;
}
-
const bool
BrlcadDb::_isValidPath(const std::string path) {
/* Assume that 'path' is formatted to be a BRLCAD DB path */
@@ -121,13 +120,12 @@
const int
BrlcadDb::list(const std::string path, std::list<std::string>* list)
{
- if (this->open() == false) return G_PATH_NOT_VALID;
+ if (this->open() == false) return FS_PATH_NOT_VALID;
const int retVal = this->_list(path, list);
this->close();
return retVal;
}
-
const int
BrlcadDb::_list(const std::string path, std::list<std::string>* items)
{
@@ -225,6 +223,51 @@
return node_count;
}
+bool
+BrlcadDb::contains (const std::string name)
+{
+ if (this->open() == false) return false;
+ bool retVal = this->_contains(name);
+ this->close();
+ return retVal;
+}
+bool
+BrlcadDb::_contains (const std::string name)
+{
+ return (db_lookup(this->dbip, name.c_str(), 0) != RT_DIR_NULL);
+}
+
+
+ExtObject*
+BrlcadDb::getExtObj(const std::string name)
+{
+ if (this->open() == false) return NULL;
+
+ ExtObject* retVal = this->_getExtObj(name);
+ this->close();
+ return retVal;
+}
+ExtObject*
+BrlcadDb::_getExtObj(const std::string name)
+{
+ directory* dirp = db_lookup(this->dbip, name.c_str(),0);
+
+ if (dirp == RT_DIR_NULL)
+ return NULL;
+
+ bu_external* extp =
(bu_external*)bu_calloc(sizeof(bu_external),1,"GetExternal bu_external calloc");
+
+ int rVal = db_get_external(extp, dirp, this->dbip);
+ if (rVal < 0) {
+ bu_free(extp, "BrlcadDb::_getExtObj(): Freeing bu_external due to
error.");
+ return NULL;
+ }
+
+ return new ExtObject(name, ext);
+}
+
+
+
// Local Variables:
// tab-width: 8
// mode: C++
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery,
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now.
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits