Proposed date-time patch [ Refs #2475 ]

Here's a proposed patch for ticket #2475. https://svn.boost.org/trac/boost/ticket/2475 Anyone love it? Hate it? Index: ../../../boost/date_time/tz_db_base.hpp =================================================================== --- ../../../boost/date_time/tz_db_base.hpp (revision 71667) +++ ../../../boost/date_time/tz_db_base.hpp (working copy) @@ -166,22 +166,26 @@ //! Constructs an empty database tz_db_base() {} + //! Process csv data stream, may throw exceptions + /*! May throw bad_field_count exceptions */ + void load_from_stream(std::ifstream &ifs) + { + std::string buff; + while( std::getline(ifs, buff)) + parse_string(buff); + } + //! Process csv data file, may throw exceptions /*! May throw data_not_accessible, or bad_field_count exceptions */ void load_from_file(const std::string& pathspec) { - string_type in_str; - std::string buff; - std::ifstream ifs(pathspec.c_str()); - if(!ifs){ + if(!ifs) boost::throw_exception(data_not_accessible(pathspec)); - } + + std::string buff; std::getline(ifs, buff); // first line is column headings - - while( std::getline(ifs, buff)) { - parse_string(buff); - } + load_from_stream(ifs); } //! returns true if record successfully added to map -- Marshall

AMDG On 05/02/2011 03:31 PM, Marshall Clow wrote:
Here's a proposed patch for ticket #2475. https://svn.boost.org/trac/boost/ticket/2475 Anyone love it? Hate it?
Index: ../../../boost/date_time/tz_db_base.hpp =================================================================== --- ../../../boost/date_time/tz_db_base.hpp (revision 71667) +++ ../../../boost/date_time/tz_db_base.hpp (working copy) @@ -166,22 +166,26 @@ //! Constructs an empty database tz_db_base() {}
+ //! Process csv data stream, may throw exceptions + /*! May throw bad_field_count exceptions */ + void load_from_stream(std::ifstream &ifs)
Should't this be std::istream?
+ { + std::string buff; + while( std::getline(ifs, buff)) + parse_string(buff); + } + //! Process csv data file, may throw exceptions /*! May throw data_not_accessible, or bad_field_count exceptions */ void load_from_file(const std::string& pathspec) { - string_type in_str; - std::string buff; - std::ifstream ifs(pathspec.c_str()); - if(!ifs){ + if(!ifs) boost::throw_exception(data_not_accessible(pathspec)); - } + + std::string buff; std::getline(ifs, buff); // first line is column headings - - while( std::getline(ifs, buff)) { - parse_string(buff); - } + load_from_stream(ifs); }
//! returns true if record successfully added to map
Any particular reason you changed the brace style? In Christ, Steven Watanabe

On May 2, 2011, at 5:10 PM, Steven Watanabe wrote:
On 05/02/2011 03:31 PM, Marshall Clow wrote:
Here's a proposed patch for ticket #2475. https://svn.boost.org/trac/boost/ticket/2475 Anyone love it? Hate it?
Index: ../../../boost/date_time/tz_db_base.hpp =================================================================== --- ../../../boost/date_time/tz_db_base.hpp (revision 71667) +++ ../../../boost/date_time/tz_db_base.hpp (working copy) @@ -166,22 +166,26 @@ //! Constructs an empty database tz_db_base() {}
+ //! Process csv data stream, may throw exceptions + /*! May throw bad_field_count exceptions */ + void load_from_stream(std::ifstream &ifs)
Should't this be std::istream?
D'oh! Of course it should - thanks.
Any particular reason you changed the brace style?
I just removed unnecessary braces - force of habit. I can put them back if people object. -- Marshall Marshall Clow Idio Software <mailto:mclow.lists@gmail.com> A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait). -- Yu Suzuki
participants (2)
-
Marshall Clow
-
Steven Watanabe