当前位置: 首页>>代码示例>>C++>>正文


C++ Filters::end方法代码示例

本文整理汇总了C++中Filters::end方法的典型用法代码示例。如果您正苦于以下问题:C++ Filters::end方法的具体用法?C++ Filters::end怎么用?C++ Filters::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Filters的用法示例。


在下文中一共展示了Filters::end方法的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;
        }
    }
}
开发者ID:MagicSmokeFireworks,项目名称:magic-smoke-firmware,代码行数:61,代码来源:spark_wiring_logging.cpp


注:本文中的Filters::end方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。