Example #1
0
void history_t::get_string_representation(wcstring &result, const wcstring &separator)
{
    scoped_lock locker(lock);
    
    bool first = true;
    
    /* Append new items */
    for (std::vector<history_item_t>::const_reverse_iterator iter=new_items.rbegin(); iter < new_items.rend(); ++iter) {
        if (! first)
            result.append(separator);
        result.append(iter->str());
        first = false;
    }
    
    /* Append old items */
    load_old_if_needed();
    for (std::deque<size_t>::const_reverse_iterator iter = old_item_offsets.rbegin(); iter != old_item_offsets.rend(); ++iter) {        
        size_t offset = *iter;
        const history_item_t item = history_t::decode_item(mmap_start + offset, mmap_length - offset);
        if (! first)
            result.append(separator);
        result.append(item.str());
        first = false;
    }
}
Example #2
0
history_item_t history_t::item_at_index(size_t idx) {
    scoped_lock locker(lock);
    
    /* 0 is considered an invalid index */
    assert(idx > 0);
    idx--;
    
    /* idx=0 corresponds to last item in new_items */
    size_t new_item_count = new_items.size();
    if (idx < new_item_count) {
        return new_items.at(new_item_count - idx - 1);
    }
    
    /* Now look in our old items */
    idx -= new_item_count;
    load_old_if_needed();
    size_t old_item_count = old_item_offsets.size();
    if (idx < old_item_count) {
        /* idx=0 corresponds to last item in old_item_offsets */
        size_t offset = old_item_offsets.at(old_item_count - idx - 1);
        return history_t::decode_item(mmap_start + offset, mmap_length - offset);
    }
    
    /* Index past the valid range, so return an empty history item */
    return history_item_t(wcstring(), 0);
}
Example #3
0
bool history_t::is_empty(void)
{
    bool result = false;
    scoped_lock locker(lock);
    if (new_items.empty())
    {
        load_old_if_needed();
        result = old_item_offsets.empty();
    }
    return result;
}