[Debian-astro-commits] [gyoto] 25/221: Factory: allow constructing an object from in-memory XML data.
Thibaut Jean-Claude Paumard
thibaut at moszumanska.debian.org
Fri May 22 20:52:30 UTC 2015
This is an automated email from the git hooks/post-receive script.
thibaut pushed a commit to branch master
in repository gyoto.
commit 5f99e28e9df677b5097233e6a924777623750c72
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date: Fri Oct 10 16:35:38 2014 +0200
Factory: allow constructing an object from in-memory XML data.
---
include/GyotoFactory.h | 7 +++++++
lib/Factory.C | 22 +++++++++++++++++++---
yorick/gyoto.i | 9 +++++++++
3 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/include/GyotoFactory.h b/include/GyotoFactory.h
index 4012716..7da351e 100644
--- a/include/GyotoFactory.h
+++ b/include/GyotoFactory.h
@@ -159,6 +159,13 @@ class Gyoto::Factory
public:
/// Constructor for reading a file
+ /**
+ * If filename starts with "<?xml", it is interpreted as XML data
+ * and parsed directly (with no file access). It is possible to
+ * parse a file that actually starts with those unlikely characters
+ * by escaping the first with '\'. If filename starts with '\', this
+ * single character is always stripped.
+ */
Factory(char * filename);
/// Constructor for saving (or printing) a Scenery
diff --git a/lib/Factory.C b/lib/Factory.C
index 148b689..6b5af59 100644
--- a/lib/Factory.C
+++ b/lib/Factory.C
@@ -39,6 +39,7 @@
#include <xercesc/framework/StdOutFormatTarget.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp>
#include <xercesc/framework/MemBufFormatTarget.hpp>
+#include <xercesc/framework/MemBufInputSource.hpp>
using namespace Gyoto;
using namespace xercesc;
@@ -183,11 +184,11 @@ void DOMErrorReporter::resetErrors()
//// Now for the public API
-Factory::Factory(char * filename)
+Factory::Factory(char * data)
: reporter_(NULL), gg_el_(NULL), obj_el_(NULL), ph_el_(NULL),
scenery_(NULL), gg_(NULL), screen_(NULL), obj_(NULL), photon_(NULL),
spectro_(NULL),
- filename_(filename)
+ filename_("")
{
// Initialize Xerces XML parser
@@ -201,7 +202,22 @@ Factory::Factory(char * filename)
parser_->setErrorHandler(errReporter);
// Parse file
- parser_->parse(filename);
+ // If data start with "<?xml", this is an xml buffer.
+ size_t len=strlen(data);
+ if (len < 5 || data[0]!='<' || data[1] != '?'
+ || data[2]!='x' || data[3]!='m' || data[4]!='l') {
+ // we are dealing with a file name
+ if (data[0]=='\\') ++data; // allow escaping
+ filename_=data;
+ parser_->parse(data);
+ } else {
+ filename_="Gyoto XML data (in memory)";
+ xercesc::MemBufInputSource
+ xml_buf(reinterpret_cast<const XMLByte *>(data),
+ len,
+ filename_.c_str());
+ parser_->parse(xml_buf);
+ }
doc_ = parser_ -> getDocument();
root_ = doc_ -> getDocumentElement();
diff --git a/yorick/gyoto.i b/yorick/gyoto.i
index 39c2593..3c3a800 100644
--- a/yorick/gyoto.i
+++ b/yorick/gyoto.i
@@ -137,6 +137,15 @@ local gyoto;
class constructor:
gg = gyoto.Metric("KerrBL");
+ Finally, it is possible to instanciate an object using a buffer
+ containing XML data:
+ #include "pathfun.i"
+ gg = gyoto.KerrBL();
+ xmldata = pathform(print(gg), delim="\n");
+ gg2 =gyoto.Metric(xmldata).
+ This should be equivalent to gg2 == gg.clone(), see COPYING
+ vs. CLONIG below.
+
GYOTO OBJECTS BEHAVE LIKE FUNCTIONS
-----------------------------------
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-astro/packages/gyoto.git
More information about the Debian-astro-commits
mailing list