summaryrefslogtreecommitdiff
path: root/format.h
diff options
context:
space:
mode:
Diffstat (limited to 'format.h')
-rw-r--r--format.h88
1 files changed, 51 insertions, 37 deletions
diff --git a/format.h b/format.h
index 778ec53f..405da2e1 100644
--- a/format.h
+++ b/format.h
@@ -7,16 +7,16 @@
namespace ledger {
-std::string truncated(const std::string& str, unsigned int width,
+string truncated(const string& str, unsigned int width,
const int style = 2);
-std::string partial_account_name(const account_t& account,
+string partial_account_name(const account_t& account,
const unsigned int start_depth);
#define ELEMENT_ALIGN_LEFT 0x01
#define ELEMENT_HIGHLIGHT 0x02
-struct element_t
+struct element_t : public noncopyable
{
enum kind_t {
STRING,
@@ -50,7 +50,7 @@ struct element_t
kind_t type;
unsigned char flags;
- std::string chars;
+ string chars;
unsigned char min_width;
unsigned char max_width;
value_expr val_expr;
@@ -59,18 +59,18 @@ struct element_t
element_t() : type(STRING), flags(false),
min_width(0), max_width(0), next(NULL) {
- DEBUG_PRINT("ledger.memory.ctors", "ctor element_t");
+ TRACE_CTOR(element_t, "");
}
~element_t() {
- DEBUG_PRINT("ledger.memory.dtors", "dtor element_t");
- if (next) delete next; // recursive, but not too deep
+ TRACE_DTOR(element_t);
+ if (next) checked_delete(next); // recursive, but not too deep
}
};
-struct format_t
+struct format_t : public noncopyable
{
- std::string format_string;
+ string format_string;
element_t * elements;
enum elision_style_t {
@@ -87,27 +87,27 @@ struct format_t
static bool ansi_invert;
format_t() : elements(NULL) {
- DEBUG_PRINT("ledger.memory.ctors", "ctor format_t");
+ TRACE_CTOR(format_t, "");
}
- format_t(const std::string& _format) : elements(NULL) {
- DEBUG_PRINT("ledger.memory.ctors", "ctor format_t");
+ format_t(const string& _format) : elements(NULL) {
+ TRACE_CTOR(format_t, "const string&");
reset(_format);
}
~format_t() {
- DEBUG_PRINT("ledger.memory.dtors", "dtor format_t");
- if (elements) delete elements;
+ TRACE_DTOR(format_t);
+ if (elements) checked_delete(elements);
}
- void reset(const std::string& _format) {
+ void reset(const string& _format) {
if (elements)
- delete elements;
+ checked_delete(elements);
elements = parse_elements(_format);
format_string = _format;
}
- static element_t * parse_elements(const std::string& fmt);
+ static element_t * parse_elements(const string& fmt);
- static std::string truncate(const std::string& str, unsigned int width,
+ static string truncate(const string& str, unsigned int width,
const bool is_account = false);
void format(std::ostream& out, const details_t& details) const;
@@ -115,16 +115,19 @@ struct format_t
class format_transactions : public item_handler<transaction_t>
{
- protected:
+protected:
std::ostream& output_stream;
format_t first_line_format;
format_t next_lines_format;
entry_t * last_entry;
transaction_t * last_xact;
- public:
+public:
format_transactions(std::ostream& _output_stream,
- const std::string& format);
+ const string& format);
+ ~format_transactions() throw() {
+ TRACE_DTOR(format_transactions);
+ }
virtual void flush() {
output_stream.flush();
@@ -135,8 +138,13 @@ class format_transactions : public item_handler<transaction_t>
class format_entries : public format_transactions
{
public:
- format_entries(std::ostream& output_stream, const std::string& format)
- : format_transactions(output_stream, format) {}
+ format_entries(std::ostream& output_stream, const string& format)
+ : format_transactions(output_stream, format) {
+ TRACE_CTOR(format_entries, "std::ostream&, const string&");
+ }
+ ~format_entries() throw() {
+ TRACE_DTOR(format_entries);
+ }
virtual void format_last_entry();
@@ -151,21 +159,21 @@ class format_entries : public format_transactions
};
void print_entry(std::ostream& out, const entry_base_t& entry,
- const std::string& prefix = "");
+ const string& prefix = "");
bool disp_subaccounts_p(const account_t& account,
- const item_predicate<account_t>& disp_pred,
+ const optional<item_predicate<account_t> >& disp_pred,
const account_t *& to_show);
inline bool disp_subaccounts_p(const account_t& account) {
const account_t * temp;
- return disp_subaccounts_p(account, item_predicate<account_t>(NULL), temp);
+ return disp_subaccounts_p(account, none, temp);
}
bool display_account(const account_t& account,
- const item_predicate<account_t>& disp_pred);
+ const optional<item_predicate<account_t> >& disp_pred);
-class format_account : public item_handler<account_t>
+class format_accounts : public item_handler<account_t>
{
std::ostream& output_stream;
@@ -174,11 +182,16 @@ class format_account : public item_handler<account_t>
public:
format_t format;
- format_account(std::ostream& _output_stream,
- const std::string& _format,
- const std::string& display_predicate = NULL)
+ format_accounts(std::ostream& _output_stream,
+ const string& _format,
+ const string& display_predicate = NULL)
: output_stream(_output_stream), disp_pred(display_predicate),
- format(_format) {}
+ format(_format) {
+ TRACE_CTOR(format_accounts, "std::ostream&, const string&, const string&");
+ }
+ ~format_accounts() throw() {
+ TRACE_DTOR(format_accounts);
+ }
virtual void flush() {
output_stream.flush();
@@ -198,17 +211,18 @@ class format_equity : public item_handler<account_t>
mutable value_t total;
public:
- format_equity(std::ostream& _output_stream,
- const std::string& _format,
- const std::string& display_predicate);
+ format_equity(std::ostream& _output_stream,
+ const string& _format,
+ const string& display_predicate);
virtual void flush();
virtual void operator()(account_t& account);
};
-class format_error : public error {
+class format_error : public error
+{
public:
- format_error(const std::string& reason, error_context * ctxt = NULL) throw()
+ format_error(const string& reason, error_context * ctxt = NULL) throw()
: error(reason, ctxt) {}
virtual ~format_error() throw() {}
};