summaryrefslogtreecommitdiff
path: root/src/error.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-21 19:52:31 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-21 20:20:57 -0400
commit66c5cd44277863708fdc81a6418bc84215b0c269 (patch)
treef78fdbae25244af9260466e2ab01cc3e131491f2 /src/error.h
parenta577e8c48ebe3b540a6833e1d37025d53c8a42a7 (diff)
downloadfork-ledger-66c5cd44277863708fdc81a6418bc84215b0c269.tar.gz
fork-ledger-66c5cd44277863708fdc81a6418bc84215b0c269.tar.bz2
fork-ledger-66c5cd44277863708fdc81a6418bc84215b0c269.zip
Use a "format accumulator" for error strings
This makes it possible to internationalize strings while still using I/O streams. For example: std::cout << ACCUM(_("Hello to %1 and %2!") << "me" << "you") << std::endl;
Diffstat (limited to 'src/error.h')
-rw-r--r--src/error.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/error.h b/src/error.h
index 568e509a..2c0c4d09 100644
--- a/src/error.h
+++ b/src/error.h
@@ -46,8 +46,11 @@
#ifndef _ERROR_H
#define _ERROR_H
+#include "accum.h"
+
namespace ledger {
+extern straccstream _desc_accum;
extern std::ostringstream _desc_buffer;
template <typename T>
@@ -56,14 +59,20 @@ inline void throw_func(const string& message) {
throw T(message);
}
-#define throw_(cls, msg) \
- ((_desc_buffer << msg), throw_func<cls>(_desc_buffer.str()))
+#define throw_(cls, msg) \
+ ((_desc_buffer << ACCUM(_desc_accum << msg)), \
+ _desc_accum.clear(), \
+ throw_func<cls>(_desc_buffer.str()))
+extern straccstream _ctxt_accum;
extern std::ostringstream _ctxt_buffer;
#define add_error_context(msg) \
((long(_ctxt_buffer.tellp()) == 0) ? \
- (_ctxt_buffer << msg) : (_ctxt_buffer << std::endl << msg))
+ ((_ctxt_buffer << ACCUM(_ctxt_accum << msg)), \
+ _ctxt_accum.clear()) : \
+ ((_ctxt_buffer << std::endl << ACCUM(_ctxt_accum << msg)), \
+ _ctxt_accum.clear()))
string error_context();