Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Create template dinamically

Create template dinamically 01 Oct 2007 16:00 #7257

Hello!

I would like to ask your help in a problem.
Is there any way to create template dinamically?

The situation is the following.
Let's suppose there is a protocoll and it's messages have a field like this:

type record math_expression
{ integer field1,
integer field2,
char operation // "+", "-", "*", "/"
}

type record of math_expression math_expression_list; (and this list is optional)


When a message is received we have to check this field (math_expression_list).
Because we tried to minimalise the number of the templates, math_expression_list
is a parameter of the receiving templates.

The problem is:
- in case we don't expect this field, omit should be passed to the template
- the number of the record is not fix
- and the most problematic part: even the order of field1 and field2 is fixed in
some cases it is irrelevant (when operation is "+" or "*")

During running before a message is received we know all these information but
how could be passed to the receiving template?
Of course there is an other option: accept all kind of field and check this list
after receive. But in this case in the log cannot be seen the expected value.

Thanks in advance,
Csaba
The administrator has disabled public write access.

Create template dinamically 04 Oct 2007 11:58 #7258

Hello Csaba,

Regarding your questions

If the math_expression_list is an optional field in your message and you would
like to pass omit as actual parameter to be used for this field, then you have
to add 'template to the definition of the formal parameter

template Type a_type (in template math_expression_list p_mel) := ...
Without the keyword template in the parameter definition you can only pass
values, but not omit.

Regarding the second question, 'number of the record', I assume you mean the
length of the math_expression_list. But what is the problem here, you can pass
math_expression_lists of any length as parameter. If you would like to restrict
the length of the math expression list in matching, you could use somethink like
'? length(2..3)' to express that you are expecting 2 or 3 math_expressions.

The third one is somehow tricky, if you are looking for specific values in the
math expressions and do not know the order, you could change the type of
math_expression to have a set of arguments and then the different orders would
be handled automatically in matching. But you would have to change your type
definitions. But you also use value lists to express the two different orders.
Instead of using { 3, 5, "+"} as template for a match expression you might use
({ 3, 5, "+"}. { 5, 3, "+"}). It should even be possible to write a template
computing function with a list of math_expressions as input and a corresponding
list as output and in the output each math expression would occur with the
original and the reversed order of paraemeters.

I hope this helps you further.

Best regards

Thomas

>
Original Message
>From: active_ttcn3 : mts stf133 ttcn version 3 - active members only
>[This email address is being protected from spambots. You need JavaScript enabled to view it.] On Behalf Of ext Csaba Bejan
>Sent: Monday, 01. October 2007 18:01
>To: This email address is being protected from spambots. You need JavaScript enabled to view it.
>Subject: Create template dinamically
>
>Hello!
>
>I would like to ask your help in a problem.
>Is there any way to create template dinamically?
>
>The situation is the following.
>Let's suppose there is a protocoll and it's messages have a field
>like this:
>
>type record math_expression
>{ integer field1,
> integer field2,
> char operation // "+", "-", "*", "/"
>}
>
>type record of math_expression math_expression_list; (and this list
>is optional)
>
>
>When a message is received we have to check this field
>(math_expression_list). Because we tried to minimalise the number of
>the templates, math_expression_list is a parameter of the receiving
>templates.
>
>The problem is:
>- in case we don't expect this field, omit should be passed to the
>template
>- the number of the record is not fix
>- and the most problematic part: even the order of field1 and
>field2 is fixed in some cases it is irrelevant (when operation is
>"+" or "*")
>
>During running before a message is received we know all these
>information but how could be passed to the receiving template?
>Of course there is an other option: accept all kind of field and
>check this list after receive. But in this case in the log cannot be
>seen the expected value.
>
>Thanks in advance,
>Csaba
>
The administrator has disabled public write access.
  • Page:
  • 1

FacebookTwitterGoogle BookmarksRedditNewsvineTechnoratiLinkedin