Merge remote-tracking branch 'geppettodivacin/selections_with_at_buffer'
This commit is contained in:
commit
22ebb25b1b
|
@ -1,5 +1,7 @@
|
||||||
#include "normal.hh"
|
#include "normal.hh"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include "buffer.hh"
|
#include "buffer.hh"
|
||||||
#include "buffer_manager.hh"
|
#include "buffer_manager.hh"
|
||||||
#include "buffer_utils.hh"
|
#include "buffer_utils.hh"
|
||||||
|
@ -1774,11 +1776,17 @@ SelectionList read_selections_from_register(char reg, Context& context)
|
||||||
if (content.size() < 2)
|
if (content.size() < 2)
|
||||||
throw runtime_error(format("register '{}' does not contain a selections desc", reg));
|
throw runtime_error(format("register '{}' does not contain a selections desc", reg));
|
||||||
|
|
||||||
|
// Use the last two values for timestamp and main_index to allow the buffer
|
||||||
|
// name to have @ symbols
|
||||||
struct error : runtime_error { error(size_t) : runtime_error{"expected <buffer>@<timestamp>@main_index"} {} };
|
struct error : runtime_error { error(size_t) : runtime_error{"expected <buffer>@<timestamp>@main_index"} {} };
|
||||||
const auto desc = content[0] | split<StringView>('@') | static_gather<error, 3>();
|
auto end_content = content[0] | reverse() | split('@') | transform([] (auto bounds) {
|
||||||
Buffer& buffer = BufferManager::instance().get_buffer(desc[0]);
|
return StringView{bounds.second.base(), bounds.first.base()};
|
||||||
const size_t timestamp = str_to_int(desc[1]);
|
}) | static_gather<error, 2, false>();
|
||||||
size_t main = str_to_int(desc[2]);
|
|
||||||
|
const size_t main = str_to_int(end_content[0]);
|
||||||
|
const size_t timestamp = str_to_int(end_content[1]);
|
||||||
|
const auto buffer_name = StringView{ content[0].begin (), end_content[1].begin () - 1 };
|
||||||
|
Buffer& buffer = BufferManager::instance().get_buffer(buffer_name);
|
||||||
|
|
||||||
return selection_list_from_strings(buffer, ColumnType::Byte, content | skip(1), timestamp, main);
|
return selection_list_from_strings(buffer, ColumnType::Byte, content | skip(1), timestamp, main);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,12 @@ struct ReverseView
|
||||||
{
|
{
|
||||||
decltype(auto) begin() { return m_range.rbegin(); }
|
decltype(auto) begin() { return m_range.rbegin(); }
|
||||||
decltype(auto) end() { return m_range.rend(); }
|
decltype(auto) end() { return m_range.rend(); }
|
||||||
|
decltype(auto) rbegin() { return m_range.begin(); }
|
||||||
|
decltype(auto) rend() { return m_range.end(); }
|
||||||
|
decltype(auto) begin() const { return m_range.rbegin(); }
|
||||||
|
decltype(auto) end() const { return m_range.rend(); }
|
||||||
|
decltype(auto) rbegin() const { return m_range.begin(); }
|
||||||
|
decltype(auto) rend() const { return m_range.end(); }
|
||||||
|
|
||||||
Range m_range;
|
Range m_range;
|
||||||
};
|
};
|
||||||
|
@ -73,6 +79,24 @@ inline auto skip(size_t count)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Range>
|
||||||
|
struct DropView
|
||||||
|
{
|
||||||
|
auto begin() const { return std::begin(m_range); }
|
||||||
|
auto end() const { return std::end(m_range) - m_drop_count; }
|
||||||
|
|
||||||
|
Range m_range;
|
||||||
|
size_t m_drop_count;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline auto drop(size_t count)
|
||||||
|
{
|
||||||
|
return make_view_factory([count](auto&& range) {
|
||||||
|
using Range = decltype(range);
|
||||||
|
return DropView<decay_range<Range>>{std::forward<Range>(range), count};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Range, typename Filter>
|
template<typename Range, typename Filter>
|
||||||
struct FilterView
|
struct FilterView
|
||||||
{
|
{
|
||||||
|
@ -477,15 +501,15 @@ auto elements(bool exact_size = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ExceptionType, size_t... Indexes>
|
template<typename ExceptionType, size_t... Indexes>
|
||||||
auto static_gather_impl(std::index_sequence<Indexes...>)
|
auto static_gather_impl(std::index_sequence<Indexes...>, bool exact_size)
|
||||||
{
|
{
|
||||||
return elements<ExceptionType, Indexes...>(true);
|
return elements<ExceptionType, Indexes...>(exact_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ExceptionType, size_t size>
|
template<typename ExceptionType, size_t size, bool exact_size=true>
|
||||||
auto static_gather()
|
auto static_gather()
|
||||||
{
|
{
|
||||||
return static_gather_impl<ExceptionType>(std::make_index_sequence<size>());
|
return static_gather_impl<ExceptionType>(std::make_index_sequence<size>(), exact_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user