summaryrefslogtreecommitdiff
path: root/format.h
blob: 298715cbac579846ceee8b6eab3843f2efecaf24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef _FORMAT_H
#define _FORMAT_H

#include "ledger.h"
#include "balance.h"
#include "constraint.h"
#include "expr.h"

namespace ledger {

std::string truncated(const std::string& str, unsigned int width);
std::string maximal_account_name(const item_t * item, const item_t * parent);

struct format_t
{
  std::string	format_string;
  node_t *	value_style;
  node_t *	total_style;

  format_t() {
    value_style = NULL;
    total_style = NULL;
  }

  ~format_t() {
    if (value_style) delete value_style;
    if (total_style) delete total_style;
  }

#if 1
  balance_t compute_value(const item_t * item) const {
    if (value_style)
      return value_style->compute(item);
    else
      return balance_t();
  }

  balance_t compute_total(const item_t * item) const {
    if (total_style)
      return total_style->compute(item);
    else
      return balance_t();
  }
#else
  balance_t compute_value(const item_t * item,
			  const constraints_t& constraints) const {
    if (value_style)
      return value_style->compute(item, constraints.begin(), constraints.end());
    else
      return balance_t();
  }

  balance_t compute_total(const item_t * item,
			  const constraints_t& constraints) const {
    if (total_style)
      return total_style->compute(item, constraints.begin(), constraints.end());
    else
      return balance_t();
  }
#endif

  std::string report_line(const item_t * item,
			  const item_t * displayed_parent = NULL) const;
};

} // namespace ledger

#endif // _REPORT_H