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_item.cc | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'src/py_item.cc') diff --git a/src/py_item.cc b/src/py_item.cc index edebd532..65d89119 100644 --- a/src/py_item.cc +++ b/src/py_item.cc @@ -49,7 +49,7 @@ namespace { return item.has_tag(tag_mask); } bool py_has_tag_2m(item_t& item, const mask_t& tag_mask, - const boost::optional& value_mask) { + const boost::optional& value_mask) { return item.has_tag(tag_mask, value_mask); } @@ -60,15 +60,15 @@ namespace { 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) { + const boost::optional& value_mask) { return item.get_tag(tag_mask, value_mask); } } // unnamed namespace -#define EXC_TRANSLATOR(type) \ - void exc_translate_ ## type(const type& err) { \ - PyErr_SetString(PyExc_ArithmeticError, err.what()); \ +#define EXC_TRANSLATOR(type) \ + void exc_translate_ ## type(const type& err) { \ + PyErr_SetString(PyExc_ArithmeticError, err.what()); \ } //EXC_TRANSLATOR(item_error) @@ -77,25 +77,25 @@ void export_item() { class_< position_t > ("Position") .add_property("pathname", - make_getter(&position_t::pathname), - make_setter(&position_t::pathname)) + make_getter(&position_t::pathname), + make_setter(&position_t::pathname)) .add_property("beg_pos", - make_getter(&position_t::beg_pos), - make_setter(&position_t::beg_pos)) + make_getter(&position_t::beg_pos), + make_setter(&position_t::beg_pos)) .add_property("beg_line", - make_getter(&position_t::beg_line), - make_setter(&position_t::beg_line)) + make_getter(&position_t::beg_line), + make_setter(&position_t::beg_line)) .add_property("end_pos", - make_getter(&position_t::end_pos), - make_setter(&position_t::end_pos)) + make_getter(&position_t::end_pos), + make_setter(&position_t::end_pos)) .add_property("end_line", - make_getter(&position_t::end_line), - make_setter(&position_t::end_line)) + make_getter(&position_t::end_line), + make_setter(&position_t::end_line)) ; - scope().attr("ITEM_NORMAL") = ITEM_NORMAL; + scope().attr("ITEM_NORMAL") = ITEM_NORMAL; scope().attr("ITEM_GENERATED") = ITEM_GENERATED; - scope().attr("ITEM_TEMP") = ITEM_TEMP; + scope().attr("ITEM_TEMP") = ITEM_TEMP; enum_< item_t::state_t > ("State") .value("Uncleared", item_t::UNCLEARED) @@ -110,7 +110,7 @@ void export_item() #endif #if 1 .add_property("flags", &supports_flags<>::flags, - &supports_flags<>::set_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) @@ -118,14 +118,14 @@ void export_item() #endif .add_property("note", - make_getter(&item_t::note), - make_setter(&item_t::note)) + make_getter(&item_t::note), + make_setter(&item_t::note)) .add_property("pos", - make_getter(&item_t::pos), - make_setter(&item_t::pos)) + make_getter(&item_t::pos), + make_setter(&item_t::pos)) .add_property("metadata", - make_getter(&item_t::metadata), - make_setter(&item_t::metadata)) + make_getter(&item_t::metadata), + make_setter(&item_t::metadata)) .def("copy_details", &item_t::copy_details) @@ -148,12 +148,12 @@ void export_item() .def("append_note", &item_t::append_note) .add_static_property("use_effective_date", - make_getter(&item_t::use_effective_date), - make_setter(&item_t::use_effective_date)) + make_getter(&item_t::use_effective_date), + make_setter(&item_t::use_effective_date)) .add_property("date", &item_t::date, make_setter(&item_t::_date)) .add_property("effective_date", &item_t::effective_date, - make_setter(&item_t::_date_eff)) + make_setter(&item_t::_date_eff)) .add_property("state", &item_t::state, &item_t::set_state) -- 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_item.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