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


C++ ArrayData::emplace_back方法代码示例

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


在下文中一共展示了ArrayData::emplace_back方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: HandleRequest

bool ActionsHandler::HandleRequest(
    AsioTlsStream& stream,
    const ApiUser::Ptr& user,
    boost::beast::http::request<boost::beast::http::string_body>& request,
    const Url::Ptr& url,
    boost::beast::http::response<boost::beast::http::string_body>& response,
    const Dictionary::Ptr& params,
    boost::asio::yield_context& yc,
    HttpServerConnection& server
)
{
    namespace http = boost::beast::http;

    if (url->GetPath().size() != 3)
        return false;

    if (request.method() != http::verb::post)
        return false;

    String actionName = url->GetPath()[2];

    ApiAction::Ptr action = ApiAction::GetByName(actionName);

    if (!action) {
        HttpUtility::SendJsonError(response, params, 404, "Action '" + actionName + "' does not exist.");
        return true;
    }

    QueryDescription qd;

    const std::vector<String>& types = action->GetTypes();
    std::vector<Value> objs;

    String permission = "actions/" + actionName;

    if (!types.empty()) {
        qd.Types = std::set<String>(types.begin(), types.end());
        qd.Permission = permission;

        try {
            objs = FilterUtility::GetFilterTargets(qd, params, user);
        } catch (const std::exception& ex) {
            HttpUtility::SendJsonError(response, params, 404,
                "No objects found.",
                DiagnosticInformation(ex));
            return true;
        }
    } else {
        FilterUtility::CheckPermission(user, permission);
        objs.emplace_back(nullptr);
    }

    ArrayData results;

    Log(LogNotice, "ApiActionHandler")
        << "Running action " << actionName;

    bool verbose = false;

    if (params)
        verbose = HttpUtility::GetLastParameter(params, "verbose");

    for (const ConfigObject::Ptr& obj : objs) {
        try {
            results.emplace_back(action->Invoke(obj, params));
        } catch (const std::exception& ex) {
            Dictionary::Ptr fail = new Dictionary({
                { "code", 500 },
                { "status", "Action execution failed: '" + DiagnosticInformation(ex, false) + "'." }
            });

            /* Exception for actions. Normally we would handle this inside SendJsonError(). */
            if (verbose)
                fail->Set("diagnostic_information", DiagnosticInformation(ex));

            results.emplace_back(std::move(fail));
        }
    }

    int statusCode = 500;

    for (const Dictionary::Ptr& res : results) {
        if (res->Contains("code") && res->Get("code") == 200) {
            statusCode = 200;
            break;
        }
    }

    response.result(statusCode);

    Dictionary::Ptr result = new Dictionary({
        { "results", new Array(std::move(results)) }
    });

    HttpUtility::SendJsonBody(response, params, result);

    return true;
}
开发者ID:Icinga,项目名称:icinga2,代码行数:98,代码来源:actionshandler.cpp

示例2: make_pair

std::pair<Dictionary::Ptr, Dictionary::Ptr> ApiListener::GetStatus()
{
    Dictionary::Ptr perfdata = new Dictionary();

    /* cluster stats */

    double allEndpoints = 0;
    Array::Ptr allNotConnectedEndpoints = new Array();
    Array::Ptr allConnectedEndpoints = new Array();

    Zone::Ptr my_zone = Zone::GetLocalZone();

    Dictionary::Ptr connectedZones = new Dictionary();

    for (const Zone::Ptr& zone : ConfigType::GetObjectsByType<Zone>()) {
        /* only check endpoints in a) the same zone b) our parent zone c) immediate child zones */
        if (my_zone != zone && my_zone != zone->GetParent() && zone != my_zone->GetParent()) {
            Log(LogDebug, "ApiListener")
                << "Not checking connection to Zone '" << zone->GetName() << "' because it's not in the same zone, a parent or a child zone.";
            continue;
        }

        bool zoneConnected = false;
        int countZoneEndpoints = 0;
        double zoneLag = 0;

        ArrayData zoneEndpoints;

        for (const Endpoint::Ptr& endpoint : zone->GetEndpoints()) {
            zoneEndpoints.emplace_back(endpoint->GetName());

            if (endpoint->GetName() == GetIdentity())
                continue;

            double eplag = CalculateZoneLag(endpoint);

            if (eplag > 0 && eplag > zoneLag)
                zoneLag = eplag;

            allEndpoints++;
            countZoneEndpoints++;

            if (!endpoint->GetConnected()) {
                allNotConnectedEndpoints->Add(endpoint->GetName());
            } else {
                allConnectedEndpoints->Add(endpoint->GetName());
                zoneConnected = true;
            }
        }

        /* if there's only one endpoint inside the zone, we're not connected - that's us, fake it */
        if (zone->GetEndpoints().size() == 1 && countZoneEndpoints == 0)
            zoneConnected = true;

        String parentZoneName;
        Zone::Ptr parentZone = zone->GetParent();
        if (parentZone)
            parentZoneName = parentZone->GetName();

        Dictionary::Ptr zoneStats = new Dictionary({
            { "connected", zoneConnected },
            { "client_log_lag", zoneLag },
            { "endpoints", new Array(std::move(zoneEndpoints)) },
            { "parent_zone", parentZoneName }
        });

        connectedZones->Set(zone->GetName(), zoneStats);
    }

    /* connection stats */
    size_t jsonRpcClients = GetAnonymousClients().size();
    size_t httpClients = GetHttpClients().size();
    size_t workQueueItems = JsonRpcConnection::GetWorkQueueLength();
    size_t workQueueCount = JsonRpcConnection::GetWorkQueueCount();
    size_t syncQueueItems = m_SyncQueue.GetLength();
    size_t relayQueueItems = m_RelayQueue.GetLength();
    double workQueueItemRate = JsonRpcConnection::GetWorkQueueRate();
    double syncQueueItemRate = m_SyncQueue.GetTaskCount(60) / 60.0;
    double relayQueueItemRate = m_RelayQueue.GetTaskCount(60) / 60.0;

    Dictionary::Ptr status = new Dictionary({
        { "identity", GetIdentity() },
        { "num_endpoints", allEndpoints },
        { "num_conn_endpoints", allConnectedEndpoints->GetLength() },
        { "num_not_conn_endpoints", allNotConnectedEndpoints->GetLength() },
        { "conn_endpoints", allConnectedEndpoints },
        { "not_conn_endpoints", allNotConnectedEndpoints },

        { "zones", connectedZones },

        { "json_rpc", new Dictionary({
            { "clients", jsonRpcClients },
            { "work_queue_items", workQueueItems },
            { "work_queue_count", workQueueCount },
            { "sync_queue_items", syncQueueItems },
            { "relay_queue_items", relayQueueItems },
            { "work_queue_item_rate", workQueueItemRate },
            { "sync_queue_item_rate", syncQueueItemRate },
            { "relay_queue_item_rate", relayQueueItemRate }
        }) },
//.........这里部分代码省略.........
开发者ID:gunnarbeutner,项目名称:icinga2,代码行数:101,代码来源:apilistener.cpp


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