summaryrefslogtreecommitdiff
path: root/src/xact.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-10-27 04:00:59 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-10-27 04:00:59 -0400
commitddfd00afe17393f5b33a9288990a649e3cfcc0ab (patch)
treed9562fba018f0a80809894e939b4026b235f4e37 /src/xact.cc
parent5ddb0e9bfbf3432a1078adc550484e5b8a151f34 (diff)
downloadfork-ledger-ddfd00afe17393f5b33a9288990a649e3cfcc0ab.tar.gz
fork-ledger-ddfd00afe17393f5b33a9288990a649e3cfcc0ab.tar.bz2
fork-ledger-ddfd00afe17393f5b33a9288990a649e3cfcc0ab.zip
Made the id function available in post contexts
Diffstat (limited to 'src/xact.cc')
-rw-r--r--src/xact.cc54
1 files changed, 35 insertions, 19 deletions
diff --git a/src/xact.cc b/src/xact.cc
index 175a1467..13faedba 100644
--- a/src/xact.cc
+++ b/src/xact.cc
@@ -351,32 +351,48 @@ void xact_t::add_post(post_t * post)
xact_base_t::add_post(post);
}
-namespace {
- value_t get_magnitude(xact_t& xact) {
- balance_t halfbal;
- foreach (post_t * post, xact.posts)
- if (post->amount.sign() > 0)
+value_t xact_t::magnitude() const
+{
+ value_t halfbal = 0L;
+ foreach (const post_t * post, posts) {
+ if (post->amount.sign() > 0) {
+ if (post->cost)
+ halfbal += post->cost->number();
+ else
halfbal += post->amount.number();
- return halfbal;
+ }
}
+ return halfbal;
+}
- value_t get_idstring(xact_t& xact) {
- std::ostringstream buf;
- buf << *xact._date;
- buf << xact.payee;
+string xact_t::idstring() const
+{
+ std::ostringstream buf;
+ buf << *_date;
+ buf << payee;
+ magnitude().print(buf);
+ return buf.str();
+}
- get_magnitude(xact).print(buf);
+string xact_t::id() const
+{
+ SHA1 sha;
+ sha.Reset();
+ sha << idstring().c_str();
+ uint_least32_t message_digest[5];
+ sha.Result(message_digest);
+ return to_hex(message_digest, 5);
+}
- return string_value(buf.str());
+namespace {
+ value_t get_magnitude(xact_t& xact) {
+ return xact.magnitude();
+ }
+ value_t get_idstring(xact_t& xact) {
+ return string_value(xact.idstring());
}
value_t get_id(xact_t& xact) {
- SHA1 sha;
- sha.Reset();
- sha << get_idstring(xact).as_string().c_str();
-
- uint_least32_t message_digest[5];
- sha.Result(message_digest);
- return string_value(to_hex(message_digest));
+ return string_value(xact.id());
}
value_t get_code(xact_t& xact) {