Ejemplo n.º 1
0
void
TimeLog::load_entry(string const& p_entry_string, size_t p_line_number)
{
    if (p_entry_string.size() < expected_time_stamp_length(m_time_format, m_formatted_buf_len))
    {
        ostringstream oss;
        enable_exceptions(oss);
        oss << "Error parsing the time log at line "
            << p_line_number << '.';
        throw runtime_error(oss.str());
    }
    auto it = p_entry_string.begin() + expected_time_stamp_length(m_time_format, m_formatted_buf_len);
    assert (it > p_entry_string.begin());
    string const time_stamp(p_entry_string.begin(), it);
    auto const activity = trim(string(it, p_entry_string.end()));
    auto const activity_id = register_activity(activity);
    auto const time_point = time_stamp_to_point(time_stamp, m_time_format);
    Entry entry(activity_id, time_point);
    if (!m_entries.empty())
    {
        auto const last_time_point = m_entries.back().time_point;
        if (entry.time_point < last_time_point)
        {       
            ostringstream oss;
            enable_exceptions(oss);
            oss << "Time log entries out of order at line "
                << p_line_number << '.'; 
            throw runtime_error(oss.str());
        }
    }
    m_entries.push_back(entry);
    return;
}
Ejemplo n.º 2
0
void
TimeLog::load()
{
    if (!m_is_loaded)
    {
        clear_cache();
        if (file_exists_at(m_filepath))
        {
            ifstream infile(m_filepath.c_str());
            enable_exceptions(infile);
            string line;
            size_t line_number = 1;
            while (infile.peek() != EOF)
            {
                getline(infile, line);
                load_entry(line, line_number);
                ++line_number;
            }
            if (!m_entries.empty() && (m_entries.back().time_point > now()))
            {
                throw runtime_error
                (   "The final entry in the time log is future-dated. "
                    "Future dated entries are not supported."
                );
            }
        }
        m_is_loaded = true;
    }
    return;
}
Ejemplo n.º 3
0
void eh_test( F1 op)
{
    bool done = false;
    int count = 0;
    
    while (!done)
    {
        try
        {
            enable_exceptions(count);
            op();
            done = true;
        }
        catch(...)
        {
            ++count;
        }
        disable_exceptions();
    }
}