summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2007-05-11 07:25:15 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 03:38:46 -0400
commit76a2e60e3911c01fc0c0521714debfb4fb5d6faf (patch)
tree3ae733572ff34c6325f136a04a0752351bf56767
parentbc3b0b5577bd08e131e2c0884b30d364e6d3b38a (diff)
downloadfork-ledger-76a2e60e3911c01fc0c0521714debfb4fb5d6faf.tar.gz
fork-ledger-76a2e60e3911c01fc0c0521714debfb4fb5d6faf.tar.bz2
fork-ledger-76a2e60e3911c01fc0c0521714debfb4fb5d6faf.zip
Added builder.h
-rw-r--r--Makefile.am10
-rw-r--r--gdtoa/Makefile.am8
-rw-r--r--src/TODO3
-rw-r--r--src/builder.h83
4 files changed, 97 insertions, 7 deletions
diff --git a/Makefile.am b/Makefile.am
index d6ff433c..aede2083 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,14 +1,14 @@
SUBDIRS = gdtoa
BUILT_SOURCES =
CLEANFILES =
-
+EXTRA_DIST = LICENSE docs tests contrib scripts setup.py \
+ verify.sh run_verify.sh valgrind.sh \
+ src/TODO src/gnucash.cc
ESC_srcdir=`echo "$(srcdir)" | sed 's/\//\\\\\//g'`
ESC_builddir=`echo "$(top_builddir)" | sed 's/\//\\\\\//g'`
ESC_distdir=`echo "$(distdir)" | sed 's/\//\\\\\//g'`
-EXTRA_DIST = docs tests
-
#(cd $(distdir)/docs; zip -r doxygen-html.zip html; rm -fr html)
dist-hook:
rm -fr `find $(distdir) -name .svn`
@@ -105,9 +105,10 @@ libpyledger_la_SOURCES = \
pkginclude_HEADERS = \
src/amount.h \
- src/balpair.h \
src/balance.h \
+ src/balpair.h \
src/binary.h \
+ src/builder.h \
src/commodity.h \
src/context.h \
src/csv.h \
@@ -138,6 +139,7 @@ pkginclude_HEADERS = \
src/textual.h \
src/times.h \
src/transform.h \
+ src/tuples.hpp \
src/utils.h \
src/value.h \
src/xml.h \
diff --git a/gdtoa/Makefile.am b/gdtoa/Makefile.am
index 232bc721..13fee34b 100644
--- a/gdtoa/Makefile.am
+++ b/gdtoa/Makefile.am
@@ -8,12 +8,14 @@ libgdtoa_la_SOURCES = \
misc.c smisc.c strtoIQ.c strtoId.c strtoIdd.c strtoIf.c strtoIg.c \
strtoIx.c strtoIxL.c strtod.c strtodI.c strtodg.c strtof.c strtopQ.c \
strtopd.c strtopdd.c strtopf.c strtopx.c strtopxL.c strtorQ.c \
- strtord.c strtordd.c strtorf.c strtorx.c strtorxL.c sum.c ulp.c
+ strtord.c strtordd.c strtorf.c strtorx.c strtorxL.c sum.c ulp.c \
+ strtodnrp.c
EXTRA_libgdtoa_la_SOURCES = arithchk.c qnan.c
BUILT_SOURCES = arith.h gd_qnan.h
-CLEANFILES = arith.h gd_qnan.h arithchk qnan
+CLEANFILES = arith.h gd_qnan.h arithchk qnan
+EXTRA_DIST = LICENSE
arith.h: arithchk.c
$(CC) $(CFLAGS) -o $(top_builddir)/arithchk $< || \
@@ -26,4 +28,4 @@ gd_qnan.h: qnan.c arith.h
$(top_builddir)/qnan > $(top_builddir)/$@
rm -f $(top_builddir)/qnan
-pkginclude_HEADERS = gdtoa.h gdtoaimp.h arith.h gd_qnan.h
+pkginclude_HEADERS = gdtoa.h gdtoaimp.h
diff --git a/src/TODO b/src/TODO
index 3ea808d5..610da153 100644
--- a/src/TODO
+++ b/src/TODO
@@ -6,3 +6,6 @@
that the memory is held by an auto_ptr until the constructor is
done; otherwise, an exception raised from within the constructor
will not call the destructor to free the memory.
+
+- Using mmap for the binary reader; or determine if the performance is
+ even worth the maintenance headaches of that code altogether.
diff --git a/src/builder.h b/src/builder.h
new file mode 100644
index 00000000..00adf483
--- /dev/null
+++ b/src/builder.h
@@ -0,0 +1,83 @@
+#ifndef _BUILDER_H
+#define _BUILDER_H
+
+#include "xml.h"
+
+namespace ledger {
+
+/**
+ * @class builder_t
+ *
+ * @brief Represents an interface for building a data hierarchy.
+ *
+ * This interface is much like .NET's XmlWriter facility. It
+ * abstracts the kind of hierarchy we're building, instead focusing
+ * only on the relationships.
+ */
+class builder_t
+{
+ virtual void pushAttribute(const string& name,
+ const string& value) = 0;
+ virtual void pushAttribute(const nameid_t name_id,
+ const string& value) = 0;
+
+ virtual void beginNode(const string& name) = 0;
+ virtual void beginNode(const nameid_t name_id) = 0;
+
+ virtual void appendText(const string& text) = 0;
+
+ virtual node_t * endNode(const optional<string>& name =
+ optional<string>()) = 0;
+ virtual node_t * endNode(const nameid_t name_id) = 0;
+};
+
+/**
+ * @class xml_builder_t
+ *
+ * @brief Build a generic node_t hierarchy.
+ *
+ * This builder can be used to parse ordinary XML into a document
+ * object structure which can then be traversed in memory.
+ */
+class xml_builder_t : public builder_t
+{
+};
+
+/**
+ * @class journal_builder_t
+ *
+ * @brief This custom builder creates an XML-mirrored Ledger journal.
+ *
+ * Rather than simply creating a node_t hierarchy, as xml_builder_t
+ * does, this code creates the associated journal elements referred to
+ * by those nodes, and then refers to those elements via minimalist
+ * "shadow nodes".
+ *
+ * Thus, after building a <transaction> element, the element itself
+ * will have no children, but instead will point to a transaction_t
+ * object. If later an XPath expression desires to traverse the
+ * <transaction> element, all of the appropriate child nodes will be
+ * constructed on the fly, as if they'd been created in the first
+ * place by a regular xml_builder_t.
+ */
+class journal_builder_t : public xml_builder_t
+{
+};
+
+/**
+ * @class xml_writer_t
+ *
+ * @brief Create textual XML on the given output stream.
+ *
+ * This builder, rather than manipulating data structures in memory,
+ * simply streams its contents on the fly to the given output stream.
+ * It uses only enough memory to remember the currently push
+ * attributes and text.
+ */
+class xml_writer_t : public builder_t
+{
+};
+
+} // namespace ledger
+
+#endif // _BUILDER_H