本文整理汇总了C++中Filters::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ Filters::insert方法的具体用法?C++ Filters::insert怎么用?C++ Filters::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filters
的用法示例。
在下文中一共展示了Filters::insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: a
/*
This method builds prefix tree based on the list of filter strings. Every node of the tree
contains subcategory name and, optionally, logging level - if node matches complete filter
string. For example, given following filters:
a (error)
a.b.c (trace)
a.b.x (trace)
aa (error)
aa.b (warn)
The code builds following prefix tree:
|
|- a (error) -- b - c (trace)
| |
| `-- x (trace)
|
`- aa (error) - b (warn)
*/
spark::LogHandler::LogHandler(LogLevel level, const Filters &filters) :
level_(level) {
for (auto it = filters.begin(); it != filters.end(); ++it) {
const char* const category = it->first;
const LogLevel level = it->second;
std::vector<FilterData> *filters = &filters_; // Root nodes
size_t pos = 0;
for (size_t i = 0;; ++i) {
if (category[i] && category[i] != '.') { // Category name separator
continue;
}
const size_t size = i - pos;
if (!size) {
break; // Invalid category name
}
const char* const name = category + pos;
// Use binary search to find existent node or position for new node
bool found = false;
auto it = std::lower_bound(filters->begin(), filters->end(), std::make_pair(name, size),
[&found](const FilterData &filter, const std::pair<const char*, size_t> &value) {
const int cmp = std::strncmp(filter.name, value.first, std::min(filter.size, value.second));
if (cmp == 0) {
if (filter.size == value.second) {
found = true;
}
return filter.size < value.second;
}
return cmp < 0;
});
if (!found) {
it = filters->insert(it, FilterData(name, size)); // Add node
}
if (!category[i]) {
it->level = level;
break;
}
filters = &it->filters;
pos = i + 1;
}
}
}