From e92bcf411d2e9a55969303ba3893a017152d7c18 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 1 May 2007 04:36:49 +0000 Subject: Started using boost::optional. --- src/session.h | 70 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 37 deletions(-) (limited to 'src/session.h') diff --git a/src/session.h b/src/session.h index a1fd304b..1a28e6ee 100644 --- a/src/session.h +++ b/src/session.h @@ -10,10 +10,10 @@ namespace ledger { class session_t : public xml::xpath_t::scope_t { public: - string init_file; - string data_file; - string cache_file; - string price_db; + path data_file; + optional init_file; + optional cache_file; + optional price_db; string register_format; string wide_register_format; @@ -42,8 +42,8 @@ class session_t : public xml::xpath_t::scope_t bool ansi_codes; bool ansi_invert; - std::list journals; - std::list parsers; + ptr_list journals; + ptr_list parsers; session_t(xml::xpath_t::scope_t * _parent = NULL) : xml::xpath_t::scope_t(_parent), @@ -96,16 +96,6 @@ class session_t : public xml::xpath_t::scope_t virtual ~session_t() { TRACE_DTOR(session_t); - - for (std::list::iterator i = journals.begin(); - i != journals.end(); - i++) - delete *i; - - for (std::list::iterator i = parsers.begin(); - i != parsers.end(); - i++) - delete *i; } journal_t * new_journal() { @@ -114,19 +104,26 @@ class session_t : public xml::xpath_t::scope_t return journal; } void close_journal(journal_t * journal) { - journals.remove(journal); - delete journal; + for (ptr_list::iterator i = journals.begin(); + i != journals.end(); + i++) + if (&*i == journal) { + journals.erase(i); + return; + } + assert(false); + checked_delete(journal); } - unsigned int read_journal(std::istream& in, - journal_t * journal, - account_t * master = NULL, - const string * original_file = NULL); + unsigned int read_journal(std::istream& in, + journal_t * journal, + account_t * master = NULL, + const optional& original = optional()); - unsigned int read_journal(const string& path, - journal_t * journal, - account_t * master = NULL, - const string * original_file = NULL); + unsigned int read_journal(const path& path, + journal_t * journal, + account_t * master = NULL, + const optional& original = optional()); void read_init(); @@ -135,17 +132,16 @@ class session_t : public xml::xpath_t::scope_t void register_parser(parser_t * parser) { parsers.push_back(parser); } - bool unregister_parser(parser_t * parser) { - std::list::iterator i; - for (i = parsers.begin(); i != parsers.end(); i++) - if (*i == parser) - break; - if (i == parsers.end()) - return false; - - parsers.erase(i); - - return true; + void unregister_parser(parser_t * parser) { + for (ptr_list::iterator i = parsers.begin(); + i != parsers.end(); + i++) + if (&*i == parser) { + parsers.erase(i); + return; + } + assert(false); + checked_delete(parser); } // -- cgit v1.2.3