diff options
author | John Wiegley <johnw@newartisans.com> | 2005-02-15 10:28:48 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 02:41:02 -0400 |
commit | 16e449dc05cfa278559c1f111bfcec899d46afdc (patch) | |
tree | 951b7e1192d8139dfcb385cec0801ec8e2354d00 | |
parent | bb444b740ff2f83ae509cef0a8604ef73c495d90 (diff) | |
download | fork-ledger-16e449dc05cfa278559c1f111bfcec899d46afdc.tar.gz fork-ledger-16e449dc05cfa278559c1f111bfcec899d46afdc.tar.bz2 fork-ledger-16e449dc05cfa278559c1f111bfcec899d46afdc.zip |
Added pystream_handler_wrap class, which wraps an item_handler taking
a std::ostream so that it can take a PyObject* instead. Relies on
pyfstream.h, which allows Python file objects to be treating as I/O
streams.
-rw-r--r-- | format.h | 39 |
1 files changed, 38 insertions, 1 deletions
@@ -7,7 +7,8 @@ namespace ledger { -std::string truncated(const std::string& str, unsigned int width); +std::string truncated(const std::string& str, unsigned int width, + const int style = 2); std::string partial_account_name(const account_t& account, const unsigned int start_depth); @@ -198,4 +199,40 @@ class format_equity : public item_handler<account_t> } // namespace ledger +#ifdef USE_BOOST_PYTHON + +#include "pyfstream.h" + +template <typename T, typename U, typename V = int, typename W = int> +struct pystream_handler_wrap : public ledger::item_handler<U> +{ + PyFileObject * file; + pyofstream * output; + + T handler; + + pystream_handler_wrap(PyObject * file_) + : file((PyFileObject *)file_), output(new pyofstream(file)), + handler(*output) {} + pystream_handler_wrap(PyObject * file_, const V& arg) + : file((PyFileObject *)file_), output(new pyofstream(file)), + handler(*output, arg) {} + pystream_handler_wrap(PyObject * file_, const V& arg1, const W& arg2) + : file((PyFileObject *)file_), output(new pyofstream(file)), + handler(*output, arg1, arg2) {} + + virtual ~pystream_handler_wrap() { + delete output; + } + + virtual void flush() { + handler.flush(); + } + virtual void operator()(U& item) { + handler.operator()(item); + } +}; + +#endif // USE_BOOST_PYTHON + #endif // _REPORT_H |