idvaluemap: complete_id_if method for conditional id completion

This commit is contained in:
Maxime Coste 2012-01-19 20:52:08 +00:00
parent 2824bd9a46
commit ce6b4c2cc4

View File

@ -63,14 +63,19 @@ public:
}
}
template<std::string (*id_to_string)(const _Id&)>
CandidateList complete_id(const std::string& prefix,
size_t cursor_pos)
template<std::string (*id_to_string)(const _Id&),
typename _Condition>
CandidateList complete_id_if(const std::string& prefix,
size_t cursor_pos,
_Condition condition)
{
std::string real_prefix = prefix.substr(0, cursor_pos);
CandidateList result;
for (auto& value : m_content)
{
if (not condition(value))
continue;
std::string id_str = id_to_string(value.first);
if (id_str.substr(0, real_prefix.length()) == real_prefix)
result.push_back(std::move(id_str));
@ -78,6 +83,14 @@ public:
return result;
}
template<std::string (*id_to_string)(const _Id&)>
CandidateList complete_id(const std::string& prefix,
size_t cursor_pos)
{
return complete_id_if<id_to_string>(
prefix, cursor_pos, [](const value_type&) { return true; });
}
iterator begin() { return m_content.begin(); }
iterator end() { return m_content.end(); }
const_iterator begin() const { return m_content.begin(); }