[Liblas-commits] hg-main-tree: start on some OCI schema stuff
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed Apr 20 12:07:33 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/806dbd76fd4d
changeset: 598:806dbd76fd4d
user: Howard Butler <hobu.inc at gmail.com>
date: Wed Apr 20 08:27:59 2011 -0500
description:
start on some OCI schema stuff
Subject: hg-main-tree: add operator < and > for sorting
details: http://hg.libpc.orghg-main-tree/rev/31501e5ca8db
changeset: 599:31501e5ca8db
user: Howard Butler <hobu.inc at gmail.com>
date: Wed Apr 20 09:42:15 2011 -0500
description:
add operator < and > for sorting
Subject: hg-main-tree: xml parsing for generating libpc::Dimension entries
details: http://hg.libpc.orghg-main-tree/rev/2c3eb32cb4ff
changeset: 600:2c3eb32cb4ff
user: Howard Butler <hobu.inc at gmail.com>
date: Wed Apr 20 11:07:00 2011 -0500
description:
xml parsing for generating libpc::Dimension entries
Subject: hg-main-tree: make sure to seek to end of file before reading data
details: http://hg.libpc.orghg-main-tree/rev/1f15fd317a8a
changeset: 601:1f15fd317a8a
user: Howard Butler <hobu.inc at gmail.com>
date: Wed Apr 20 11:07:20 2011 -0500
description:
make sure to seek to end of file before reading data
diffstat:
include/libpc/DimensionLayout.hpp | 9 +
include/libpc/drivers/oci/Common.hpp | 26 ++
include/libpc/drivers/oci/Schema.hpp | 42 +++-
src/drivers/las/Writer.cpp | 1 -
src/drivers/oci/Schema.cpp | 387 ++++++++++++++++++++++++++++++++++-
test/unit/OCITest.cpp | 4 +-
6 files changed, 456 insertions(+), 13 deletions(-)
diffs (truncated from 603 to 300 lines):
diff -r 8a9807af8582 -r 1f15fd317a8a include/libpc/DimensionLayout.hpp
--- a/include/libpc/DimensionLayout.hpp Mon Apr 18 21:27:51 2011 -0700
+++ b/include/libpc/DimensionLayout.hpp Wed Apr 20 11:07:20 2011 -0500
@@ -93,6 +93,15 @@
m_position = v;
}
+ inline bool operator < (DimensionLayout const& dim) const
+ {
+ return m_position < dim.m_position;
+ }
+ inline bool operator > (DimensionLayout const& dim) const
+ {
+ return m_position > dim.m_position;
+ }
+
private:
Dimension m_dimension;
std::size_t m_byteOffset;
diff -r 8a9807af8582 -r 1f15fd317a8a include/libpc/drivers/oci/Common.hpp
--- a/include/libpc/drivers/oci/Common.hpp Mon Apr 18 21:27:51 2011 -0700
+++ b/include/libpc/drivers/oci/Common.hpp Wed Apr 20 11:07:20 2011 -0500
@@ -85,6 +85,32 @@
{}
};
+class schema_validation_error : public libpc_error
+{
+public:
+ schema_validation_error(std::string const& msg)
+ : libpc_error(msg)
+ {}
+};
+
+class schema_parsing_error : public libpc_error
+{
+public:
+ schema_parsing_error(std::string const& msg)
+ : libpc_error(msg)
+ {}
+};
+
+class schema_generic_error : public libpc_error
+{
+public:
+ schema_generic_error(std::string const& msg)
+ : libpc_error(msg)
+ {}
+};
+
+
+
#ifdef LIBPC_COMPILER_MSVC
#define compare_no_case(a,b,n) _strnicmp( (a), (b), (n) )
diff -r 8a9807af8582 -r 1f15fd317a8a include/libpc/drivers/oci/Schema.hpp
--- a/include/libpc/drivers/oci/Schema.hpp Mon Apr 18 21:27:51 2011 -0700
+++ b/include/libpc/drivers/oci/Schema.hpp Wed Apr 20 11:07:20 2011 -0500
@@ -36,12 +36,17 @@
#define INCLUDED_DRIVERS_OCI_SCHEMA_HPP
#include <libpc/libpc.hpp>
+#include <libpc/Schema.hpp>
+#include <libpc/SchemaLayout.hpp>
+#include <libpc/Dimension.hpp>
+#include <libpc/DimensionLayout.hpp>
#include <libpc/drivers/oci/Common.hpp>
#include <libpc/drivers/oci/Reader.hpp>
#include <string>
#include <stdarg.h>
+#include <functional>
#include <libxml/parser.h>
#include <libxml/xmlschemas.h>
@@ -51,6 +56,10 @@
#include <libxml/xinclude.h>
#include <libxml/xmlIO.h>
+#include <boost/shared_ptr.hpp>
+#include <boost/concept_check.hpp>
+#include <boost/function.hpp>
+
namespace libpc { namespace drivers { namespace oci {
@@ -60,17 +69,44 @@
class LIBPC_DLL Schema
{
public:
- Schema(std::string xml, std::string xmlschema);
+ Schema(std::string const& xml, std::string const& xmlschema);
~Schema();
+
+protected:
+
+ void LoadSchema();
+ Dimension::DataType GetDimensionType(std::string const& interpretation);
+ Dimension::Field GetDimensionField(std::string const& name, position);
+
private:
Schema& operator=(const Schema&); // not implemented
Schema(const Schema&); // not implemented;
- xmlDocPtr m_doc;
- xmlDocPtr m_schema;
+ // We're going to put all of our libxml2 primatives into shared_ptrs
+ // that have custom deleters that clean up after themselves so we
+ // have a good chance at having clean exception-safe code
+
+ typedef boost::shared_ptr<void> DocPtr;
+ typedef boost::shared_ptr<void> SchemaParserCtxtPtr;
+ typedef boost::shared_ptr<void> SchemaPtr;
+ typedef boost::shared_ptr<void> SchemaValidCtxtPtr;
+
+ DocPtr m_doc;
+ DocPtr m_schema_doc;
+
+ SchemaParserCtxtPtr m_schema_parser_ctx;
+ SchemaPtr m_schema_ptr;
+ SchemaValidCtxtPtr m_schema_valid_ctx;
+
+ xmlParserOption m_doc_options;
+
+ void* m_global_context;
+ libpc::Schema m_schema;
+
+
};
diff -r 8a9807af8582 -r 1f15fd317a8a src/drivers/las/Writer.cpp
--- a/src/drivers/las/Writer.cpp Mon Apr 18 21:27:51 2011 -0700
+++ b/src/drivers/las/Writer.cpp Wed Apr 20 11:07:20 2011 -0500
@@ -143,7 +143,6 @@
std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
std::cout.precision(8);
- std::cout << "scale: " << dimX.getNumericScale() <<" " << dimY.getNumericScale() << " " << dimZ.getNumericScale() << std::endl;
boost::uint32_t cnt = static_cast<boost::uint32_t>(m_targetNumPointsToWrite);
m_lasHeader.SetPointRecordsCount(cnt);
diff -r 8a9807af8582 -r 1f15fd317a8a src/drivers/oci/Schema.cpp
--- a/src/drivers/oci/Schema.cpp Mon Apr 18 21:27:51 2011 -0700
+++ b/src/drivers/oci/Schema.cpp Wed Apr 20 11:07:20 2011 -0500
@@ -37,6 +37,46 @@
#include <libpc/Utils.hpp>
#include <sstream>
+#include <iostream>
+#include <list>
+#include <cstdlib>
+
+
+struct XMLDocDeleter
+{
+ template <typename T>
+ void operator()(T* ptr)
+ {
+ ::xmlFreeDoc(ptr);
+ }
+};
+
+struct SchemaParserCtxDeleter
+{
+ template <typename T>
+ void operator()(T* ptr)
+ {
+ ::xmlSchemaFreeParserCtxt(ptr);
+ }
+};
+
+struct SchemaDeleter
+{
+ template <typename T>
+ void operator()(T* ptr)
+ {
+ ::xmlSchemaFree(ptr);
+ }
+};
+
+struct SchemaValidCtxtDeleter
+{
+ template <typename T>
+ void operator()(T* ptr)
+ {
+ ::xmlSchemaFreeValidCtxt(ptr);
+ }
+};
@@ -49,10 +89,86 @@
std::ostringstream oss;
oss << "XML error: '" << error->message <<"' ";
+
+ if (error->str1)
+ oss << " extra info1: '" << error->str1 << "' ";
+ if (error->str2)
+ oss << " extra info2: '" << error->str2 << "' ";
+ if (error->str3)
+ oss << " extra info3: '" << error->str3 << "' ";
oss << "on line " << error->line;
+
+ if (error->ctxt)
+ {
+ xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) error->ctxt;
+ xmlParserInputPtr input = ctxt->input;
+
+ xmlParserPrintFileContext(input);
+ }
throw schema_error(oss.str());
}
+void OCISchemaParserStructuredErrorHandler
+ (void * userData, xmlErrorPtr error)
+{
+ std::ostringstream oss;
+
+ oss << "Schema parsing error: '" << error->message <<"' ";
+ oss << "on line " << error->line;
+ throw schema_parsing_error(oss.str());
+}
+
+void OCISchemaValidationStructuredErrorHandler
+ (void * userData, xmlErrorPtr error)
+{
+ std::ostringstream oss;
+
+ oss << "Schema validation error: '" << error->message <<"' ";
+ oss << "on line " << error->line;
+ throw schema_validation_error(oss.str());
+}
+
+void OCISchemaValidityError
+ (void * ctx, const char* message, ... )
+{
+
+ const int ERROR_MESSAGE_SIZE = 256;
+ char error[ERROR_MESSAGE_SIZE];
+ va_list arg_ptr;
+
+ va_start(arg_ptr, message);
+ vsnprintf(error, ERROR_MESSAGE_SIZE, message, arg_ptr);
+ va_end(arg_ptr);
+
+
+ std::ostringstream oss;
+
+ oss << "Schema valididy error: '" << error <<"' ";
+ throw schema_validation_error(oss.str());
+
+}
+
+void OCISchemaValidityDebug
+ (void * ctx, const char* message, ... )
+{
+
+ const int ERROR_MESSAGE_SIZE = 256;
+ char error[ERROR_MESSAGE_SIZE];
+ va_list arg_ptr;
+
+ va_start(arg_ptr, message);
+ vsnprintf(error, ERROR_MESSAGE_SIZE, message, arg_ptr);
+ va_end(arg_ptr);
+
+
+ std::ostringstream oss;
+
+ oss << "Schema validity debug: '" << error <<"' ";
+ std::cout << oss.str() << std::endl;
+
+}
+
+
void OCISchemaGenericErrorHandler
(void * ctx, const char* message, ... )
{
@@ -69,28 +185,65 @@
std::ostringstream oss;
oss << "Generic error: '" << error <<"' ";
- throw schema_error(oss.str());
+ throw schema_generic_error(oss.str());
}
-Schema::Schema(std::string xml, std::string xmlschema)
+// XML_PARSE_NONET No network access
+// http://xmlsoft.org/html/libxml-parser.html#xmlParserOption
+
+Schema::Schema(std::string const& xml, std::string const &xsd)
+: m_doc_options(XML_PARSE_NONET)
More information about the Liblas-commits
mailing list