示例#1
0
    void DecoratorTime::load(int version, const char* agentType, const properties_t& properties)
    {
        super::load(version, agentType, properties);

        for (propertie_const_iterator_t it = properties.begin(); it != properties.end(); ++it)
        {
			const property_t& p = (*it);
			behaviac::string p_name(p.name);
			behaviac::string p_value(p.value);

			if (p_name == "Time")
			{
				if (StringUtils::IsValidString(p.value))
				{
					size_t pParenthesis = p_value.find_first_of('(');

					if (pParenthesis == (size_t)-1)
					{
						behaviac::string typeName;
						this->m_time_var = Condition::LoadRight(p.value, typeName);
					}
					else
					{
						this->m_time_m = Action::LoadMethod(p.value);
					}
				}
			}
        }
    }
示例#2
0
void RexxInstructionTrace::execute(
    RexxActivation      *context,      /* current activation context        */
    RexxExpressionStack *stack)        /* evaluation stack                  */
/******************************************************************************/
/* Function:  Execute a REXX TRACE instruction                                */
/******************************************************************************/
{
    RexxObject  *result;                 /* expression result                 */
    RexxString  *value;                  /* string version of expression      */

    context->traceInstruction(this);     /* trace if necessary                */
    // is this a debug skip request (the setting value is zero in that case)
    if ((traceSetting&TRACE_SETTING_MASK) == 0)
    {
                                         /* turn on the skip mode             */
        context->debugSkip(this->debugskip, (traceSetting&DEBUG_NOTRACE) != 0);
    }
    /* non-dynamic form?                 */
    else if (this->expression == OREF_NULL)
    {
        if (!context->inDebug())           /* not in debug mode?                */
        {
                                           /* just change the setting           */
            context->setTrace(traceSetting, traceFlags);
        }
        else
        {
            context->pauseInstruction();     /* do debug pause if necessary       */
        }
    }
    else                               /* need to evaluate an expression    */
    {
        /* get the expression value          */
        result = this->expression->evaluate(context, stack);
        ProtectedObject p_result(result);
        value = REQUEST_STRING(result);    /* force to string form              */
        ProtectedObject p_value(value);
        context->traceResult(result);      /* trace if necessary                */
        if (!context->inDebug())           /* not in debug mode?                */
        {
                                           /* now change the setting            */
            context->setTrace(value);
        }
        else
        {
            context->pauseInstruction();     /* do debug pause if necessary       */
        }
    }
}
示例#3
0
    bool Effector::EffectorConfig::load(const properties_t& properties)
    {
        bool loaded = ActionConfig::load(properties);

        for (propertie_const_iterator_t p = properties.begin(); p != properties.end(); ++p)
        {
            behaviac::string p_value(p->value);
            behaviac::string p_name(p->name);

            if (p_name == "Phase")
            {
                if (p_value == "Success")
                {
                    this->m_phase = E_SUCCESS;

                }
                else if (p_value == "Failure")
                {
                    this->m_phase = E_FAILURE;

                }
                else if (p_value == "Both")
                {
                    this->m_phase = E_BOTH;

                }
                else
                {
                    BEHAVIAC_ASSERT(false);
                }

                break;
            }
        }

        return loaded;
    }
示例#4
0
bool AttachAction::ActionConfig::load(const properties_t& properties)
{
    string propertyName = "";
    string comparatorName = "";

    for (propertie_const_iterator_t it = properties.begin(); it != properties.end(); ++it)
    {
        property_t p = *it;
        behaviac::string p_name(p.name);
        behaviac::string p_value(p.value);

        if (p_name == "Mode")
        {
            if (StringUtils::StrEqual(p.value, "Condition"))
            {
                this->m_mode = TM_Condition;
            }
            else if (StringUtils::StrEqual(p.value, "Success"))
            {
                this->m_mode = TM_Success;
            }
            else if (StringUtils::StrEqual(p.value, "Failure"))
            {
                this->m_mode = TM_Failure;
            }
            else if (StringUtils::StrEqual(p.value, "End"))
            {
                this->m_mode = TM_End;
            }
        }
        else if (p_name == "Opl")
        {
            if (StringUtils::IsValidString(p.value))
            {
                size_t pParenthesis = p_value.find_first_of('(');

                if (pParenthesis == (size_t)-1)
                {
                    this->m_opl = Condition::LoadRight(p.value, this->m_typeName);
                }
                else
                {
                    this->m_opl_m = Action::LoadMethod(p.value);

                    if (this->m_opl_m)
                    {
                        this->m_opl_m->GetReturnTypeName(this->m_typeName);
                    }
                }
            }
        }
        else if (p_name == "Opr1")
        {
            if (StringUtils::IsValidString(p.value))
            {
                size_t pParenthesis = p_value.find_first_of('(');

                if (pParenthesis == (size_t)-1)
                {
                    this->m_opr1 = Condition::LoadRight(p.value, this->m_typeName);
                }
                else
                {
                    this->m_opr1_m = Action::LoadMethod(p.value);

                    if (this->m_opr1_m)
                    {
                        this->m_opr1_m->GetReturnTypeName(this->m_typeName);
                    }
                }
            }
        }
        else if (p_name == "Operator")
        {
            comparatorName = p_value;

            if (p_value == "Invalid")
            {
                this->m_operator = E_INVALID;
            }
            else if (p_value == "Assign")
            {
                this->m_operator = E_ASSIGN;
            }
            else if (p_value == "Add")
            {
                this->m_operator = E_ADD;
            }
            else if (p_value == "Sub")
            {
                this->m_operator = E_SUB;
            }
            else if (p_value == "Mul")
            {
                this->m_operator = E_MUL;
            }
            else if (p_value == "Div")
            {
                this->m_operator = E_DIV;
            }
            else if (p_value == "Equal")
            {
                this->m_operator = E_EQUAL;
            }
            else if (p_value == "NotEqual")
            {
                this->m_operator = E_NOTEQUAL;
            }
            else if (p_value == "Greater")
            {
                this->m_operator = E_GREATER;
            }
            else if (p_value == "Less")
            {
                this->m_operator = E_LESS;
            }
            else if (p_value == "GreaterEqual")
            {
                this->m_operator = E_GREATEREQUAL;
            }
            else if (p_value == "LessEqual")
            {
                this->m_operator = E_LESSEQUAL;
            }
        }
        else if (p_name == "Opr2")
        {
            if (StringUtils::IsValidString(p.value))
            {
                size_t pParenthesis = p_value.find_first_of('(');

                if (pParenthesis == (size_t)-1)
                {
                    this->m_opr2 = Condition::LoadRight(p.value, this->m_typeName);
                }
                else
                {
                    this->m_opr2_m = Action::LoadMethod(p.value);

                    if (this->m_opr2_m)
                    {
                        this->m_opr2_m->GetReturnTypeName(this->m_typeName);
                    }
                }
            }
        }
        else
        {
            //BEHAVIAC_ASSERT(0, "unrecognised property %s", p.name);
        }
    }

    // compare
    if (this->m_operator >= E_EQUAL && this->m_operator <= E_LESSEQUAL)
    {
        if (comparatorName.length() > 0 && (this->m_opl != NULL || this->m_opl_m != NULL) &&
                (this->m_opr2 != NULL || this->m_opr2_m != NULL))
        {
            this->m_comparator = Condition::Create(this->m_typeName.c_str(), comparatorName.c_str(), this->m_opl, this->m_opl_m, this->m_opr2, this->m_opr2_m);
        }
    }

    return this->m_opl != NULL;
}
示例#5
0
void test_basic(char *filename)
{
    int i;
    brtr_t b;
    struct brtr_node *n;
    off_t root, id, ary;

    if (filename != NULL)
        unlink(filename);

    i = brtr_open(&b, filename);

    do_test("Open index", i > 0);

    root = brtr_get_root(&b);
    root = brtr_set_s(&b, root, "key1", "value1", 0);
    root = brtr_set_s(&b, root, "key2", "value2", 0);
    root = brtr_set_s(&b, root, "key3", "value3", 0);
    root = brtr_set_s(&b, root, "key2", "value4", 0);
    brtr_set_root(&b, root);

    if (verbose) {
        brtr_tree_to_json(&b, root, 0, stdout);
        printf("\n");
    }

    do_test("Count all 1", brtr_count(&b, root) == 3);

    root = brtr_set_s(&b, root, "email", "*****@*****.**", 0);
    brtr_set_root(&b, root);

    do_test("Count all 2", brtr_count(&b, root) == 4);

    id = brtr_get_s(&b, root, "email");
    n = brtr_node(&b, id);

    do_test("Search value 1", n && strcmp(p_value(n), "*****@*****.**") == 0);

    id = brtr_get_s(&b, root, "non-existing-key");
    n = brtr_node(&b, id);
    do_test("Search (unsuccessfully) value 1", n == NULL);

    id = brtr_get_s(&b, root, "key3");
    n = brtr_node(&b, id);
    do_test("Search value 2", n && strcmp(p_value(n), "value3") == 0);

    do_test("fsck 1", brtr_fsck(&b, brtr_get_root(&b), 0) == 0);

    root = brtr_delete_s(&b, root, "key3");
    brtr_set_root(&b, root);

    id = brtr_get_s(&b, root, "key3");
    n = brtr_node(&b, id);
    do_test("Search after delete 1", n == NULL);

    do_test("fsck 2", brtr_fsck(&b, brtr_get_root(&b), 0) == 0);

    root = brtr_set_s(&b, root, "email", "*****@*****.**", 0);
    brtr_set_root(&b, root);

    id = brtr_get_s(&b, root, "email");
    n = brtr_node(&b, id);
    do_test("Search after update 1", n && strcmp(p_value(n), "*****@*****.**") == 0);
    do_test("Search after update 2", n && strcmp(p_value(n), "*****@*****.**") != 0);

    do_test("fsck 3", brtr_fsck(&b, brtr_get_root(&b), 0) == 0);

    root = brtr_get_root(&b);

    if (verbose) {
        brtr_tree_to_json(&b, root, 0, stdout);
        printf("\n");
    }

    char *v = "*****@*****.**";
    off_t o;
    id = brtr_get_by_value(&b, root, v, strlen(v), &o);
    n = brtr_node(&b, id);
    do_test("brtr_get_by_value 1.1", n && strcmp(p_value(n), v) == 0);
    do_test("brtr_get_by_value 1.2", n && strcmp(p_key(n), "email") == 0);

    off_t id2 = brtr_get_n(&b, root, o);
    do_test("brtr_get_by_value 1.3", id == id2);

    if (verbose)
        printf("Arrays\n");

    ary = 0;
    i = 0;

#if 0
    ary = brtr_set(&b, ary, brtr_autokey(&b, tmp), "a new", -1, 0);
    ary = brtr_set(&b, ary, brtr_autokey(&b, tmp), "set", -1, 0);
    ary = brtr_set(&b, ary, brtr_autokey(&b, tmp), "of", -1, 0);
    ary = brtr_set(&b, ary, brtr_autokey(&b, tmp), "keys", -1, 0);
    ary = brtr_set(&b, ary, brtr_autokey(&b, tmp), "added", -1, 0);
    ary = brtr_set(&b, ary, brtr_autokey(&b, tmp), "to", -1, 0);
    ary = brtr_set(&b, ary, brtr_autokey(&b, tmp), "the", -1, 0);
    ary = brtr_set(&b, ary, brtr_autokey(&b, tmp), "end", -1, 0);
#endif

    ary = brtr_append_s(&b, ary, "a new", 0);
    ary = brtr_append_s(&b, ary, "set", 0);
    ary = brtr_append_s(&b, ary, "of", 0);
    ary = brtr_append_s(&b, ary, "keys", 0);
    ary = brtr_append_s(&b, ary, "added", 0);
    ary = brtr_append_s(&b, ary, "to", 0);
    ary = brtr_append_s(&b, ary, "the", 0);
    ary = brtr_append_s(&b, ary, "end", 0);

    id = brtr_get_n(&b, ary, 0);
    n = brtr_node(&b, id);
    do_test("brtr_get_n 0", n &&
        strcmp(p_value(n), "a new") == 0);

    id = brtr_get_n(&b, ary, 3);
    n = brtr_node(&b, id);
    do_test("brtr_get_n 1", n != NULL);

    id = brtr_get_n(&b, ary, 7);
    n = brtr_node(&b, id);
    do_test("brtr_get_n 2", n &&
        strcmp(p_value(n), "end") == 0);

    id = brtr_get_n(&b, ary, 3);
    n = brtr_node(&b, id);
    do_test("brtr_get_n 3", n &&
        strcmp(p_value(n), "keys") == 0);

    if (verbose) {
        brtr_tree_to_json(&b, ary, 0, stdout);
        printf("\n");
    }

    ary = brtr_set_n(&b, ary, 0, "the_very_first", strlen("the_very_first"), 0);

    id = brtr_get_n(&b, ary, 0);
    n = brtr_node(&b, id);
    do_test("brtr_get_n & brtr_set_n 1", n &&
        strcmp(p_value(n), "the_very_first") == 0);

    id = brtr_get_n(&b, ary, 4);
    n = brtr_node(&b, id);
    do_test("brtr_get_n 4", n &&
        strcmp(p_value(n), "added") == 0);

    id = brtr_get_n(&b, ary, 2);
    n = brtr_node(&b, id);
    do_test("brtr_get_n 5", n &&
        strcmp(p_value(n), "of") == 0);

    if (verbose) {
        brtr_tree_to_json(&b, ary, 0, stdout);
        printf("\n");
    }

    root = brtr_set(&b, root, "array", strlen("array"), &ary, sizeof(ary), BRTR_FLAG_STREE|BRTR_FLAG_ARRAY);
    brtr_set_root(&b, root);

    brtr_close(&b);
}