From dea2aed0b509734ec4e1cd163ac2a4f013000da2 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 11 Jun 2010 16:03:50 -0400 Subject: Untabified all source files --- src/py_post.cc | 78 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'src/py_post.cc') diff --git a/src/py_post.cc b/src/py_post.cc index e4a50980..930a46c9 100644 --- a/src/py_post.cc +++ b/src/py_post.cc @@ -48,7 +48,7 @@ namespace { return post.has_tag(tag_mask); } bool py_has_tag_2m(post_t& post, const mask_t& tag_mask, - const boost::optional& value_mask) { + const boost::optional& value_mask) { return post.has_tag(tag_mask, value_mask); } @@ -59,7 +59,7 @@ namespace { return post.get_tag(tag_mask); } boost::optional py_get_tag_2m(post_t& post, const mask_t& tag_mask, - const boost::optional& value_mask) { + const boost::optional& value_mask) { return post.get_tag(tag_mask, value_mask); } @@ -88,8 +88,8 @@ void export_post() class_< post_t::xdata_t > ("PostingXData") #if 1 .add_property("flags", - &supports_flags::flags, - &supports_flags::set_flags) + &supports_flags::flags, + &supports_flags::set_flags) .def("has_flags", &supports_flags::has_flags) .def("clear_flags", &supports_flags::clear_flags) .def("add_flags", &supports_flags::add_flags) @@ -97,34 +97,34 @@ void export_post() #endif .add_property("visited_value", - make_getter(&post_t::xdata_t::visited_value), - make_setter(&post_t::xdata_t::visited_value)) + make_getter(&post_t::xdata_t::visited_value), + make_setter(&post_t::xdata_t::visited_value)) .add_property("compound_value", - make_getter(&post_t::xdata_t::compound_value), - make_setter(&post_t::xdata_t::compound_value)) + make_getter(&post_t::xdata_t::compound_value), + make_setter(&post_t::xdata_t::compound_value)) .add_property("total", - make_getter(&post_t::xdata_t::total), - make_setter(&post_t::xdata_t::total)) + make_getter(&post_t::xdata_t::total), + make_setter(&post_t::xdata_t::total)) .add_property("count", - make_getter(&post_t::xdata_t::count), - make_setter(&post_t::xdata_t::count)) + make_getter(&post_t::xdata_t::count), + make_setter(&post_t::xdata_t::count)) .add_property("date", - make_getter(&post_t::xdata_t::date), - make_setter(&post_t::xdata_t::date)) + make_getter(&post_t::xdata_t::date), + make_setter(&post_t::xdata_t::date)) .add_property("datetime", - make_getter(&post_t::xdata_t::datetime), - make_setter(&post_t::xdata_t::datetime)) + make_getter(&post_t::xdata_t::datetime), + make_setter(&post_t::xdata_t::datetime)) .add_property("account", - make_getter(&post_t::xdata_t::account, - return_value_policy()), - make_setter(&post_t::xdata_t::account, - with_custodian_and_ward<1, 2>())) + make_getter(&post_t::xdata_t::account, + return_value_policy()), + make_setter(&post_t::xdata_t::account, + with_custodian_and_ward<1, 2>())) .add_property("sort_values", - make_getter(&post_t::xdata_t::sort_values), - make_setter(&post_t::xdata_t::sort_values)) + make_getter(&post_t::xdata_t::sort_values), + make_setter(&post_t::xdata_t::sort_values)) ; - scope().attr("POST_VIRTUAL") = POST_VIRTUAL; + scope().attr("POST_VIRTUAL") = POST_VIRTUAL; scope().attr("POST_MUST_BALANCE") = POST_MUST_BALANCE; scope().attr("POST_CALCULATED") = POST_CALCULATED; scope().attr("POST_COST_CALCULATED") = POST_COST_CALCULATED; @@ -133,24 +133,24 @@ void export_post() //.def(init()) .add_property("xact", - make_getter(&post_t::xact, - return_internal_reference<>()), - make_setter(&post_t::xact, - with_custodian_and_ward<1, 2>())) + make_getter(&post_t::xact, + return_internal_reference<>()), + make_setter(&post_t::xact, + with_custodian_and_ward<1, 2>())) .add_property("account", - make_getter(&post_t::account, - return_internal_reference<>()), - make_setter(&post_t::account, - with_custodian_and_ward<1, 2>())) + make_getter(&post_t::account, + return_internal_reference<>()), + make_setter(&post_t::account, + with_custodian_and_ward<1, 2>())) .add_property("amount", - make_getter(&post_t::amount), - make_setter(&post_t::amount)) + make_getter(&post_t::amount), + make_setter(&post_t::amount)) .add_property("cost", - make_getter(&post_t::cost), - make_setter(&post_t::cost)) + make_getter(&post_t::cost), + make_setter(&post_t::cost)) .add_property("assigned_amount", - make_getter(&post_t::assigned_amount), - make_setter(&post_t::assigned_amount)) + make_getter(&post_t::assigned_amount), + make_setter(&post_t::assigned_amount)) .def("has_tag", py_has_tag_1s) .def("has_tag", py_has_tag_1m) @@ -171,13 +171,13 @@ void export_post() .def("has_xdata", &post_t::has_xdata) .def("clear_xdata", &post_t::clear_xdata) .def("xdata", py_xdata, - return_internal_reference<>()) + return_internal_reference<>()) .def("add_to_value", &post_t::add_to_value) .def("set_reported_account", &post_t::set_reported_account) .def("reported_account", py_reported_account, - return_internal_reference<>()) + return_internal_reference<>()) ; } -- cgit v1.2.3 From 28c65cda512135bde36542351533941b019b6ee8 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 12 Jun 2010 14:55:18 -0400 Subject: Store metadata values as value_t instead of string --- src/csv.cc | 2 +- src/item.cc | 44 +++++++++++++++++++++++--------------------- src/item.h | 16 ++++++++-------- src/post.cc | 12 ++++++------ src/post.h | 6 +++--- src/py_item.cc | 8 ++++---- src/py_post.cc | 8 ++++---- src/xact.cc | 2 +- 8 files changed, 50 insertions(+), 48 deletions(-) (limited to 'src/py_post.cc') diff --git a/src/csv.cc b/src/csv.cc index 53a1ad98..dd5ca935 100644 --- a/src/csv.cc +++ b/src/csv.cc @@ -237,7 +237,7 @@ xact_t * csv_reader::read_xact(journal_t& journal, account_t * bucket) case FIELD_UNKNOWN: if (! names[n].empty() && ! field.empty()) - xact->set_tag(names[n], field); + xact->set_tag(names[n], string_value(field)); break; } n++; diff --git a/src/item.cc b/src/item.cc index 8a056e6c..1f42510c 100644 --- a/src/item.cc +++ b/src/item.cc @@ -66,14 +66,14 @@ bool item_t::has_tag(const mask_t& tag_mask, if (! value_mask) return true; else if (data.second.first) - return value_mask->match(*data.second.first); + return value_mask->match(data.second.first->to_string()); } } } return false; } -optional item_t::get_tag(const string& tag) const +optional item_t::get_tag(const string& tag) const { DEBUG("item.meta", "Getting item tag: " << tag); if (metadata) { @@ -87,24 +87,26 @@ optional item_t::get_tag(const string& tag) const return none; } -optional item_t::get_tag(const mask_t& tag_mask, - const optional& value_mask) const +optional item_t::get_tag(const mask_t& tag_mask, + const optional& value_mask) const { if (metadata) { foreach (const string_map::value_type& data, *metadata) { if (tag_mask.match(data.first) && (! value_mask || - (data.second.first && value_mask->match(*data.second.first)))) + (data.second.first && + value_mask->match(data.second.first->to_string())))) { return data.second.first; + } } } return none; } item_t::string_map::iterator -item_t::set_tag(const string& tag, - const optional& value, - const bool overwrite_existing) +item_t::set_tag(const string& tag, + const optional& value, + const bool overwrite_existing) { assert(! tag.empty()); @@ -112,10 +114,12 @@ item_t::set_tag(const string& tag, metadata = string_map(); DEBUG("item.meta", "Setting tag '" << tag << "' to value '" - << (value ? *value : string("")) << "'"); + << (value ? *value : string_value("")) << "'"); - optional data = value; - if (data && data->empty()) + optional data = value; + if (data && + (data->is_null() || + (data->is_string() && data->as_string().empty()))) data = none; string_map::iterator i = metadata->find(tag); @@ -165,8 +169,9 @@ void item_t::parse_tags(const char * p, bool overwrite_existing, q = std::strtok(NULL, " \t")) { const string::size_type len = std::strlen(q); if (! tag.empty()) { - string_map::iterator i = set_tag(tag, string(p + (q - buf.get())), - overwrite_existing); + string_map::iterator i = + set_tag(tag, string_value(string(p + (q - buf.get()))), + overwrite_existing); (*i).second.second = true; break; } @@ -263,13 +268,13 @@ namespace { value_t get_tag(call_scope_t& args) { item_t& item(find_scope(args)); - optional str; + optional val; if (args.size() == 1) { if (args[0].is_string()) - str = item.get_tag(args[0].as_string()); + val = item.get_tag(args[0].as_string()); else if (args[0].is_mask()) - str = item.get_tag(args[0].as_mask()); + val = item.get_tag(args[0].as_mask()); else throw_(std::runtime_error, _("Expected string or mask for argument 1, but received %1") @@ -277,7 +282,7 @@ namespace { } else if (args.size() == 2) { if (args[0].is_mask() && args[1].is_mask()) - str = item.get_tag(args[0].to_mask(), args[1].to_mask()); + val = item.get_tag(args[0].to_mask(), args[1].to_mask()); else throw_(std::runtime_error, _("Expected masks for arguments 1 and 2, but received %1 and %2") @@ -290,10 +295,7 @@ namespace { throw_(std::runtime_error, _("Too many arguments to function")); } - if (str) - return string_value(*str); - else - return NULL_VALUE; + return val ? *val : NULL_VALUE; } value_t get_pathname(item_t& item) { diff --git a/src/item.h b/src/item.h index 25130d6d..61438593 100644 --- a/src/item.h +++ b/src/item.h @@ -106,8 +106,8 @@ public: enum state_t { UNCLEARED = 0, CLEARED, PENDING }; - typedef std::pair, bool> tag_data_t; - typedef std::map string_map; + typedef std::pair, bool> tag_data_t; + typedef std::map string_map; state_t _state; optional _date; @@ -153,14 +153,14 @@ public: virtual bool has_tag(const mask_t& tag_mask, const optional& value_mask = none) const; - virtual optional get_tag(const string& tag) const; - virtual optional get_tag(const mask_t& tag_mask, - const optional& value_mask = none) const; + virtual optional get_tag(const string& tag) const; + virtual optional get_tag(const mask_t& tag_mask, + const optional& value_mask = none) const; virtual string_map::iterator - set_tag(const string& tag, - const optional& value = none, - const bool overwrite_existing = true); + set_tag(const string& tag, + const optional& value = none, + const bool overwrite_existing = true); virtual void parse_tags(const char * p, bool overwrite_existing = true, optional current_year = none); diff --git a/src/post.cc b/src/post.cc index 3ef76f7f..2a8abddc 100644 --- a/src/post.cc +++ b/src/post.cc @@ -59,19 +59,19 @@ bool post_t::has_tag(const mask_t& tag_mask, return false; } -optional post_t::get_tag(const string& tag) const +optional post_t::get_tag(const string& tag) const { - if (optional value = item_t::get_tag(tag)) + if (optional value = item_t::get_tag(tag)) return value; if (xact) return xact->get_tag(tag); return none; } -optional post_t::get_tag(const mask_t& tag_mask, - const optional& value_mask) const +optional post_t::get_tag(const mask_t& tag_mask, + const optional& value_mask) const { - if (optional value = item_t::get_tag(tag_mask, value_mask)) + if (optional value = item_t::get_tag(tag_mask, value_mask)) return value; if (xact) return xact->get_tag(tag_mask, value_mask); @@ -715,7 +715,7 @@ void to_xml(std::ostream& out, const post_t& post) } { push_xml z(out, "value"); - out << y.guard(*pair.second.first); + to_xml(out, *pair.second.first); } } else { push_xml z(out, "tag"); diff --git a/src/post.h b/src/post.h index a43e6cd9..aec81e89 100644 --- a/src/post.h +++ b/src/post.h @@ -103,9 +103,9 @@ public: virtual bool has_tag(const mask_t& tag_mask, const optional& value_mask = none) const; - virtual optional get_tag(const string& tag) const; - virtual optional get_tag(const mask_t& tag_mask, - const optional& value_mask = none) const; + virtual optional get_tag(const string& tag) const; + virtual optional get_tag(const mask_t& tag_mask, + const optional& value_mask = none) const; virtual date_t value_date() const; virtual date_t date() const; diff --git a/src/py_item.cc b/src/py_item.cc index 65d89119..0e95f24f 100644 --- a/src/py_item.cc +++ b/src/py_item.cc @@ -53,14 +53,14 @@ namespace { return item.has_tag(tag_mask, value_mask); } - boost::optional py_get_tag_1s(item_t& item, const string& tag) { + boost::optional py_get_tag_1s(item_t& item, const string& tag) { return item.get_tag(tag); } - boost::optional py_get_tag_1m(item_t& item, const mask_t& tag_mask) { + boost::optional py_get_tag_1m(item_t& item, const mask_t& tag_mask) { return item.get_tag(tag_mask); } - boost::optional py_get_tag_2m(item_t& item, const mask_t& tag_mask, - const boost::optional& value_mask) { + boost::optional py_get_tag_2m(item_t& item, const mask_t& tag_mask, + const boost::optional& value_mask) { return item.get_tag(tag_mask, value_mask); } diff --git a/src/py_post.cc b/src/py_post.cc index 930a46c9..537289b3 100644 --- a/src/py_post.cc +++ b/src/py_post.cc @@ -52,14 +52,14 @@ namespace { return post.has_tag(tag_mask, value_mask); } - boost::optional py_get_tag_1s(post_t& post, const string& tag) { + boost::optional py_get_tag_1s(post_t& post, const string& tag) { return post.get_tag(tag); } - boost::optional py_get_tag_1m(post_t& post, const mask_t& tag_mask) { + boost::optional py_get_tag_1m(post_t& post, const mask_t& tag_mask) { return post.get_tag(tag_mask); } - boost::optional py_get_tag_2m(post_t& post, const mask_t& tag_mask, - const boost::optional& value_mask) { + boost::optional py_get_tag_2m(post_t& post, const mask_t& tag_mask, + const boost::optional& value_mask) { return post.get_tag(tag_mask, value_mask); } diff --git a/src/xact.cc b/src/xact.cc index b4438b48..3b66598c 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -823,7 +823,7 @@ void to_xml(std::ostream& out, const xact_t& xact) } { push_xml w(out, "value"); - out << y.guard(*pair.second.first); + to_xml(out, *pair.second.first); } } else { push_xml z(out, "tag"); -- cgit v1.2.3