[cig-commits] r8188 - in cs/spatialdata-0.1/trunk/libsrc: .
spatialdb
brad at geodynamics.org
brad at geodynamics.org
Sat Oct 27 11:58:38 PDT 2007
Author: brad
Date: 2007-10-27 11:58:38 -0700 (Sat, 27 Oct 2007)
New Revision: 8188
Added:
cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.cc
cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.hh
cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.icc
Modified:
cs/spatialdata-0.1/trunk/libsrc/Makefile.am
cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am
cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.hh
Log:
Added initial implementation of UniformDB object. Still need unit tests.
Modified: cs/spatialdata-0.1/trunk/libsrc/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/Makefile.am 2007-10-27 18:22:10 UTC (rev 8187)
+++ cs/spatialdata-0.1/trunk/libsrc/Makefile.am 2007-10-27 18:58:38 UTC (rev 8188)
@@ -34,6 +34,7 @@
spatialdb/SimpleDBQuery.cc \
spatialdb/SimpleIO.cc \
spatialdb/SimpleIOAscii.cc \
+ spatialdb/UniformDB.cc \
spatialdb/cspatialdb.cc
libspatialdata_la_LDFLAGS = $(AM_LDFLAGS)
Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am 2007-10-27 18:22:10 UTC (rev 8187)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am 2007-10-27 18:58:38 UTC (rev 8188)
@@ -27,7 +27,8 @@
cspatialdb.h \
SimpleDBQuery.hh \
SimpleDBTypes.hh \
- SimpleDBTypes.icc
+ SimpleDBTypes.icc \
+ UniformDB.hh
noinst_HEADERS =
Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.hh 2007-10-27 18:22:10 UTC (rev 8187)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.hh 2007-10-27 18:58:38 UTC (rev 8188)
@@ -44,7 +44,8 @@
SpatialDB(const char* label);
/// Default destructor.
- virtual ~SpatialDB(void);
+ virtual
+ ~SpatialDB(void);
/** Set label of spatial database.
*
@@ -59,10 +60,12 @@
const char* label(void) const;
/// Open the database and prepare for querying.
- virtual void open(void) = 0;
+ virtual
+ void open(void) = 0;
/// Close the database.
- virtual void close(void) = 0;
+ virtual
+ void close(void) = 0;
/** Set values to be returned by queries.
*
@@ -71,8 +74,9 @@
* @param names Names of values to be returned in queries
* @param numVals Number of values to be returned in queries
*/
- virtual void queryVals(const char** names,
- const int numVals) = 0;
+ virtual
+ void queryVals(const char** names,
+ const int numVals) = 0;
/** Query the database.
*
@@ -89,11 +93,12 @@
*
* @returns 0 on success, 1 on failure (i.e., could not interpolate)
*/
- virtual int query(double* vals,
- const int numVals,
- const double* coords,
- const int numDims,
- const spatialdata::geocoords::CoordSys* pCSQuery) = 0;
+ virtual
+ int query(double* vals,
+ const int numVals,
+ const double* coords,
+ const int numDims,
+ const spatialdata::geocoords::CoordSys* pCSQuery) = 0;
private :
// PRIVATE METHODS ////////////////////////////////////////////////////
Added: cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.cc 2007-10-27 18:22:10 UTC (rev 8187)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.cc 2007-10-27 18:58:38 UTC (rev 8188)
@@ -0,0 +1,129 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// <LicenseText>
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "SpatialDB.hh" // ISA SpatialDB object
+#include "UniformDB.hh" // Implementation of class methods
+
+#include <stdexcept> // USES std::runtime_error
+
+#include <sstream> // USES std::ostringsgream
+#include <assert.h> // USES assert()
+
+// ----------------------------------------------------------------------
+/// Default constructor
+spatialdata::spatialdb::UniformDB::UniformDB(void) :
+ _names(0),
+ _values(0),
+ _queryVals(0),
+ _numValues(0),
+ _querySize(0)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+/// Constructor with label
+spatialdata::spatialdb::UniformDB::UniformDB(const char* label) :
+ SpatialDB(label),
+ _names(0),
+ _values(0),
+ _queryVals(0),
+ _numValues(0),
+ _querySize(0)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+/// Default destructor
+spatialdata::spatialdb::UniformDB::~UniformDB(void)
+{ // destructor
+ delete[] _names; _names = 0;
+ delete[] _values; _values = 0;
+ delete[] _queryVals; _queryVals = 0;
+ _numValues = 0;
+ _querySize = 0;
+} // destructor
+
+// ----------------------------------------------------------------------
+// Set values to be returned by queries.
+void
+spatialdata::spatialdb::UniformDB::queryVals(const char** names,
+ const int numVals)
+{ // queryVals
+ if (0 == numVals) {
+ std::ostringstream msg;
+ msg
+ << "Number of values for query in spatial database " << label()
+ << "\n must be positive.\n";
+ throw std::runtime_error(msg.str());
+ } // if
+ assert(0 != names && 0 < numVals);
+
+ _querySize = numVals;
+ delete[] _queryVals; _queryVals = new int[numVals];
+ for (int iVal=0; iVal < numVals; ++iVal) {
+ int iName = 0;
+ while (iName < _numValues) {
+ if (0 == strcasecmp(names[iVal], _names[iName].c_str()))
+ break;
+ ++iName;
+ } // while
+ if (iName >= _numValues) {
+ std::ostringstream msg;
+ msg
+ << "Could not find value " << names[iVal] << " in spatial database\n"
+ << label() << ". Available values are:";
+ for (int iName=0; iName < _numValues; ++iName)
+ msg << "\n " << _names[iName];
+ msg << "\n";
+ throw std::runtime_error(msg.str());
+ } // if
+ _queryVals[iVal] = iName;
+ } // for
+} // queryVals
+
+// ----------------------------------------------------------------------
+// Query the database.
+int
+spatialdata::spatialdb::UniformDB::query(
+ double* vals,
+ const int numVals,
+ const double* coords,
+ const int numDims,
+ const spatialdata::geocoords::CoordSys* pCSQuery)
+{ // query
+ if (0 == _querySize) {
+ std::ostringstream msg;
+ msg
+ << "Values to be returned by spatial database " << label() << "\n"
+ << "have not been set. Please call queryVals() before query().\n";
+ throw std::runtime_error(msg.str());
+ } // if
+ else if (numVals != _querySize) {
+ std::ostringstream msg;
+ msg
+ << "Number of values to be returned by spatial database "
+ << label() << "\n"
+ << "(" << _querySize << ") does not match size of array provided ("
+ << numVals << ").\n";
+ throw std::runtime_error(msg.str());
+ } // if
+
+ for (int iVal=0; iVal < _querySize; ++iVal)
+ vals[iVal] = _values[_queryVals[iVal]];
+
+ return 0;
+} // query
+
+
+// End of file
Added: cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.hh 2007-10-27 18:22:10 UTC (rev 8187)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.hh 2007-10-27 18:58:38 UTC (rev 8188)
@@ -0,0 +1,110 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// <LicenseText>
+//
+// ----------------------------------------------------------------------
+//
+
+/** @file libsrc/spatialdb/UniformDB.hh
+ *
+ * @brief C++ manager for simple spatial database.
+ */
+
+#if !defined(spatialdata_spatialdb_uniformdb_hh)
+#define spatialdata_spatialdb_uniformdb_hh
+
+#include "SpatialDB.hh"
+
+#include <string> // USES std::string
+
+namespace spatialdata {
+ namespace spatialdb {
+ class SpatialDB; // ISA SpatialDB
+ class UniformDB;
+ class TestUniformDB; // unit testing
+ } // spatialdb
+} // spatialdata
+
+/// C++ manager for simple spatial database.
+class spatialdata::spatialdb::UniformDB : public SpatialDB
+{ // class UniformDB
+ friend class TestUniformDB; // unit testing
+
+ public :
+ // PUBLIC METHODS /////////////////////////////////////////////////////
+
+ /// Default constructor.
+ UniformDB(void);
+
+ /** Constructor with label.
+ *
+ * @param label Label of database
+ */
+ UniformDB(const char* label);
+
+ /// Default destructor.
+ ~UniformDB(void);
+
+ /// Open the database and prepare for querying.
+ void open(void);
+
+ /// Close the database.
+ void close(void);
+
+ /** Set values to be returned by queries.
+ *
+ * @pre Must call open() before queryVals()
+ *
+ * @param names Names of values to be returned in queries
+ * @param numVals Number of values to be returned in queries
+ */
+ void queryVals(const char** names,
+ const int numVals);
+
+ /** Query the database.
+ *
+ * @pre Must call open() before query()
+ *
+ * @param vals Array for computed values (output from query), vals
+ * must be allocated BEFORE calling query().
+ * @param numVals Number of values expected (size of pVals array)
+ * @param coords Coordinates of point for query
+ * @param numDims Number of dimensions for coordinates
+ * @param pCSQuery Coordinate system of coordinates
+ *
+ * @returns 0 on success, 1 on failure (i.e., could not interpolate
+ * so values set to 0)
+ */
+ int query(double* vals,
+ const int numVals,
+ const double* coords,
+ const int numDims,
+ const spatialdata::geocoords::CoordSys* pCSQuery);
+
+ private :
+ // PRIVATE METHODS ////////////////////////////////////////////////////
+
+ UniformDB(const UniformDB& data); ///< Not implemented
+ const UniformDB& operator=(const UniformDB& data); ///< Not implemented
+
+private :
+ // PRIVATE MEMBERS /////////////////////////////////////////////////////
+
+ std::string* _names; ///< Names of values in database
+ double* _values; ///< Values in database
+ int* _queryVals; ///< Indices of values to be returned in queries.
+ int _numValues; ///< Number of values in database
+ int _querySize; ///< Number of values requested to be returned in queries.
+}; // class UniformDB
+
+#include "UniformDB.icc"
+
+#endif // spatialdata_spatialdb_uniformdb_hh
+
+
+// End of file
Added: cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.icc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.icc 2007-10-27 18:22:10 UTC (rev 8187)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/UniformDB.icc 2007-10-27 18:58:38 UTC (rev 8188)
@@ -0,0 +1,28 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// <LicenseText>
+//
+// ----------------------------------------------------------------------
+//
+
+#if !defined(spatialdata_spatialdb_uniformdb_hh)
+#error "UniformDB.icc must only be included from UniformDB.hh"
+#endif
+
+// Open the database and prepare for querying.
+void
+spatialdata::spatialdb::UniformDB::open(void) {
+}
+
+// Close the database.
+void
+spatialdata::spatialdb::UniformDB::close(void) {
+}
+
+
+// End of file
More information about the cig-commits
mailing list