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


C++ RlistLen函数代码示例

本文整理汇总了C++中RlistLen函数的典型用法代码示例。如果您正苦于以下问题:C++ RlistLen函数的具体用法?C++ RlistLen怎么用?C++ RlistLen使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_filter

static void test_filter(void)
{
    Rlist *list = NULL;
    for (int i = 0; i < 10; i++)
    {
        char *item = StringFromLong(i);
        RlistAppend(&list, item, RVAL_TYPE_SCALAR);
    }

    assert_int_equal(10, RlistLen(list));
    int mod_by = 0;
    RlistFilter(&list, is_even, &mod_by, free);
    assert_int_equal(5, RlistLen(list));

    int i = 0;
    for (Rlist *rp = list; rp; rp = rp->next)
    {
        int k = StringToLong(rp->val.item);
        assert_int_equal(i, k);

        i += 2;
    }

    RlistDestroy(list);
}
开发者ID:cduclos,项目名称:core,代码行数:25,代码来源:rlist_test.c

示例2: MethodsParseTreeCheck

static bool MethodsParseTreeCheck(const Promise *pp, Seq *errors)
{
    bool success = true;

    for (size_t i = 0; i < SeqLength(pp->conlist); i++)
    {
        const Constraint *cp = SeqAt(pp->conlist, i);

        // ensure: if call and callee are resolved, then they have matching arity
        if (StringSafeEqual(cp->lval, "usebundle"))
        {
            if (cp->rval.type == RVAL_TYPE_FNCALL)
            {
                const FnCall *call = (const FnCall *)cp->rval.item;
                const Bundle *callee = PolicyGetBundle(PolicyFromPromise(pp), NULL, "agent", call->name);
                if (!callee)
                {
                    callee = PolicyGetBundle(PolicyFromPromise(pp), NULL, "common", call->name);
                }

                if (callee)
                {
                    if (RlistLen(call->args) != RlistLen(callee->args))
                    {
                        SeqAppend(errors, PolicyErrorNew(POLICY_ELEMENT_TYPE_CONSTRAINT, cp,
                                                         POLICY_ERROR_METHODS_BUNDLE_ARITY,
                                                         call->name, RlistLen(callee->args), RlistLen(call->args)));
                        success = false;
                    }
                }
            }
        }
    }
    return success;
}
开发者ID:jooooooon,项目名称:core,代码行数:35,代码来源:mod_methods.c

示例3: test_filter

static void test_filter(void)
{
    Rlist *list = NULL;
    for (int i = 0; i < 10; i++)
    {
        void *item = xmemdup(&i, sizeof(int));
        RlistAppendAlien(&list, item);
    }

    assert_int_equal(10, RlistLen(list));
    int mod_by = 0;
    RlistFilter(&list, is_even, &mod_by, free);
    assert_int_equal(5, RlistLen(list));

    int i = 0;
    for (Rlist *rp = list; rp; rp = rp->next)
    {
        int *k = rp->item;
        assert_int_equal(i, *k);

        free(k);
        rp->item = NULL;

        i += 2;
    }

    RlistDestroy(list);
}
开发者ID:lpefferkorn,项目名称:core,代码行数:28,代码来源:rlist_test.c

示例4: xmalloc

PromiseIterator *PromiseIteratorNew(EvalContext *ctx, const Promise *pp, const Rlist *lists, const Rlist *containers)
{
    PromiseIterator *iter = xmalloc(sizeof(PromiseIterator));

    iter->vars = SeqNew(RlistLen(lists), DeleteAssoc);
    iter->var_states = SeqNew(RlistLen(lists), NULL);
    iter->has_null_list = false;

    for (const Rlist *rp = lists; rp != NULL; rp = rp->next)
    {
        VarRef *ref = VarRefParseFromBundle(RlistScalarValue(rp), PromiseGetBundle(pp));

        DataType dtype = CF_DATA_TYPE_NONE;
        const void *value = EvalContextVariableGet(ctx, ref, &dtype);
        if (!value)
        {
            Log(LOG_LEVEL_ERR, "Couldn't locate variable '%s' apparently in '%s'", RlistScalarValue(rp), PromiseGetBundle(pp)->name);
            VarRefDestroy(ref);
            continue;
        }

        VarRefDestroy(ref);

        CfAssoc *new_var = NewAssoc(RlistScalarValue(rp), (Rval) { (void *)value, DataTypeToRvalType(dtype) }, dtype);
        iter->has_null_list |= !AppendIterationVariable(iter, new_var);
    }

    for (const Rlist *rp = containers; rp; rp = rp->next)
    {
        VarRef *ref = VarRefParseFromBundle(RlistScalarValue(rp), PromiseGetBundle(pp));

        DataType dtype = CF_DATA_TYPE_NONE;
        const JsonElement *value = EvalContextVariableGet(ctx, ref, &dtype);
        if (!value)
        {
            Log(LOG_LEVEL_ERR, "Couldn't locate variable '%s' apparently in '%s'", RlistScalarValue(rp), PromiseGetBundle(pp)->name);
            VarRefDestroy(ref);
            continue;
        }

        VarRefDestroy(ref);

        assert(dtype == CF_DATA_TYPE_CONTAINER);

        /* Mimics NewAssoc() but bypassing extra copying of ->rval: */
        CfAssoc *new_var = xmalloc(sizeof(CfAssoc));
        new_var->lval = xstrdup(RlistScalarValue(rp));
        new_var->rval = (Rval) { ContainerToRlist(value), RVAL_TYPE_LIST };
        new_var->dtype = CF_DATA_TYPE_STRING_LIST;

        iter->has_null_list |= !AppendIterationVariable(iter, new_var);
    }

    // We now have a control list of list-variables, with internal state in state_ptr
    return iter;
}
开发者ID:Kegeruneku,项目名称:core,代码行数:56,代码来源:iteration.c

示例5: test_length

static void test_length(void **state)
{
    Rlist *list = NULL;

    assert_int_equal(RlistLen(list), 0);

    PrependRScalar(&list, "stuff", CF_SCALAR);
    assert_int_equal(RlistLen(list), 1);

    PrependRScalar(&list, "more-stuff", CF_SCALAR);
    assert_int_equal(RlistLen(list), 2);

    DeleteRlist(list);
}
开发者ID:xrg,项目名称:cfengine-core,代码行数:14,代码来源:rlist_test.c

示例6: test_length

static void test_length(void)
{
    Rlist *list = NULL;

    assert_int_equal(RlistLen(list), 0);

    RlistPrependScalar(&list, "stuff");
    assert_int_equal(RlistLen(list), 1);

    RlistPrependScalar(&list, "more-stuff");
    assert_int_equal(RlistLen(list), 2);

    RlistDestroy(list);
}
开发者ID:lpefferkorn,项目名称:core,代码行数:14,代码来源:rlist_test.c

示例7: test_length

static void test_length(void)
{
    Rlist *list = NULL;

    assert_int_equal(RlistLen(list), 0);

    RlistPrepend(&list, "stuff", RVAL_TYPE_SCALAR);
    assert_int_equal(RlistLen(list), 1);

    RlistPrepend(&list, "more-stuff", RVAL_TYPE_SCALAR);
    assert_int_equal(RlistLen(list), 2);

    RlistDestroy(list);
}
开发者ID:cduclos,项目名称:core,代码行数:14,代码来源:rlist_test.c

示例8: KeepPromiseBundles

static void KeepPromiseBundles(EvalContext *ctx, const Policy *policy)
{
    /* Dial up the generic promise expansion with a callback */

    CleanReportBookFilterSet();

    for (size_t i = 0; i < SeqLength(policy->bundles); i++)
    {
        Bundle *bp = SeqAt(policy->bundles, i);
        bool server_bundle = strcmp(bp->type, CF_AGENTTYPES[AGENT_TYPE_SERVER]) == 0;
        bool common_bundle = strcmp(bp->type, CF_AGENTTYPES[AGENT_TYPE_COMMON]) == 0;

        if (server_bundle || common_bundle)
        {
            if (RlistLen(bp->args) > 0)
            {
                Log(LOG_LEVEL_WARNING,
                    "Cannot implicitly evaluate bundle '%s %s', as this bundle takes arguments.",
                    bp->type, bp->name);
                continue;
            }
        }

        if (server_bundle)
        {
            EvaluateBundle(ctx, bp, SERVER_TYPESEQUENCE);
        }

        else if (common_bundle)
        {
            EvaluateBundle(ctx, bp, COMMON_TYPESEQUENCE);
        }
    }
}
开发者ID:kacf,项目名称:core,代码行数:34,代码来源:server_transform.c

示例9: JsonArrayCreate

static JsonElement *RlistToJson(Rlist *list)
{
    JsonElement *array = JsonArrayCreate(RlistLen(list));

    for (Rlist *rp = list; rp; rp = rp->next)
    {
        switch (rp->val.type)
        {
        case RVAL_TYPE_SCALAR:
            JsonArrayAppendString(array, RlistScalarValue(rp));
            break;

        case RVAL_TYPE_LIST:
            JsonArrayAppendArray(array, RlistToJson(RlistRlistValue(rp)));
            break;

        case RVAL_TYPE_FNCALL:
            JsonArrayAppendObject(array, FnCallToJson(RlistFnCallValue(rp)));
            break;

        default:
            assert(false && "Unsupported item type in rlist");
            break;
        }
    }

    return array;
}
开发者ID:bahamat,项目名称:cfengine-core,代码行数:28,代码来源:rlist.c

示例10: test_expand_list_nested

static void test_expand_list_nested(void **state)
{
    EvalContext *ctx = *state;
    {
        VarRef *lval = VarRefParse("default:bundle.i");
        EvalContextVariablePut(ctx, lval, "one", CF_DATA_TYPE_STRING, NULL);
        VarRefDestroy(lval);
    }
    {
        VarRef *lval = VarRefParse("default:bundle.inner[one]");
        Rlist *list = NULL;
        RlistAppendScalar(&list, "foo");
        EvalContextVariablePut(ctx, lval, list, CF_DATA_TYPE_STRING_LIST, NULL);
        RlistDestroy(list);
        VarRefDestroy(lval);
    }

    Rlist *outer = NULL;
    RlistAppendScalar(&outer, "@{inner[$(i)]}");

    Rlist *expanded = ExpandList(ctx, "default", "bundle", outer, true);

    assert_int_equal(1, RlistLen(expanded));
    assert_string_equal("foo", RlistScalarValue(expanded));

    RlistDestroy(outer);
    RlistDestroy(expanded);
}
开发者ID:GregorioDiStefano,项目名称:core,代码行数:28,代码来源:expand_test.c

示例11: test_filter_everything

static void test_filter_everything(void)
{
    Rlist *list = NULL;
    for (int i = 1; i < 10; i += 2)
    {
        void *item = xmemdup(&i, sizeof(int));
        RlistAppendAlien(&list, item);
    }

    assert_int_equal(5, RlistLen(list));
    int mod_by = 0;
    RlistFilter(&list, is_even, &mod_by, free);
    assert_int_equal(0, RlistLen(list));

    assert_true(list == NULL);
}
开发者ID:lpefferkorn,项目名称:core,代码行数:16,代码来源:rlist_test.c

示例12: ScopePushThis

void ScopePushThis()
{
    static const char RVAL_TYPE_STACK = 'k';

    Scope *op = ScopeGet(NULL, "this");
    if (!op)
    {
        return;
    }

    int frame_index = RlistLen(CF_STCK);
    char name[CF_MAXVARSIZE];
    snprintf(name, CF_MAXVARSIZE, "this_%d", frame_index + 1);
    free(op->scope);
    free(op->ns);
    op->scope = xstrdup(name);

    Rlist *rp = xmalloc(sizeof(Rlist));

    rp->next = CF_STCK;
    rp->item = op;
    rp->type = RVAL_TYPE_STACK;
    CF_STCK = rp;

    ScopeNew(NULL, "this");
}
开发者ID:patuchov,项目名称:core,代码行数:26,代码来源:scope.c

示例13: ScopePopThis

void ScopePopThis()
{
    if (RlistLen(CF_STCK) > 0)
    {
        Scope *current_this = ScopeGet(NULL, "this");
        if (current_this)
        {

            ScopeDelete(current_this);
        }

        Rlist *rp = CF_STCK;
        CF_STCK = CF_STCK->next;

        Scope *new_this = rp->item;
        free(new_this->scope);
        new_this->scope = xstrdup("this");
        new_this->ns = xstrdup("default");

        free(rp);
    }
    else
    {
        ProgrammingError("Attempt to pop from empty stack");
    }
}
开发者ID:patuchov,项目名称:core,代码行数:26,代码来源:scope.c

示例14: ScopePushThis

void ScopePushThis()
{
    Scope *op;
    char name[CF_MAXVARSIZE];

    op = ScopeGet("this");

    if (op == NULL)
    {
        return;
    }

    int frame_index = RlistLen(CF_STCK) - 1;
    {
        Rlist *rp = xmalloc(sizeof(Rlist));

        rp->next = CF_STCK;
        rp->item = op;
        rp->type = CF_STACK;
        CF_STCK = rp;
    }
    snprintf(name, CF_MAXVARSIZE, "this_%d", frame_index);
    free(op->scope);
    op->scope = xstrdup(name);
}
开发者ID:jooooooon,项目名称:core,代码行数:25,代码来源:scope.c

示例15: test_filter_everything

static void test_filter_everything(void)
{
    Rlist *list = NULL;
    for (int i = 1; i < 10; i += 2)
    {
        char *item = StringFromLong(i);
        RlistAppend(&list, item, RVAL_TYPE_SCALAR);
    }

    assert_int_equal(5, RlistLen(list));
    int mod_by = 0;
    RlistFilter(&list, is_even, &mod_by, free);
    assert_int_equal(0, RlistLen(list));

    assert_true(list == NULL);
}
开发者ID:cduclos,项目名称:core,代码行数:16,代码来源:rlist_test.c


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