Howto code a mapping in a mapping

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
Search

Post Reply
6 posts • Page 1 of 1
kdroog4pvss
Posts: 15
Joined: Wed Sep 22, 2010 10:17 am

Howto code a mapping in a mapping

Post by kdroog4pvss »

I was reviewing a part of PVSS script code and found the following

Code: Select all

main()
{
  mapping p;
  foo(p["xxx"]);
  DebugN(p);
}

foo(mapping& x )
{
  x["is"] = "impliciet";
}
I am wondering if this is a feature or working by accident?

Kind regards,
Kees

User avatar
mkoller
Posts: 741
Joined: Fri Sep 17, 2010 9:03 am

Re: Howto code a mapping in a mapping

Post by mkoller »

This is wrong code and does not work at all. It gives an error like:
PVSS00ui (0), 2011.06.20 10:30:04.602, IMPL, WARNING, 50, Default branch called, MappingVar, operator=, cannot assign variable of type TEXT_VAR

Where did you find this ?

kdroog4pvss
Posts: 15
Joined: Wed Sep 22, 2010 10:17 am

Re: Howto code a mapping in a mapping

Post by kdroog4pvss »

Hi Martin,

I didn't find it, it is actually used! (I mean it is currently used in our application i was reviewing.)

I am running PVSS 3.9 patched upto P88.

I only get the error message when i use the following code, which assigns a empty string to p["xxx"] instead of a mapping:

Code: Select all

main()
{
  mapping p;
 p["xxx"] = "";
  foo(p["xxx"]);
  DebugN(p);
}

foo(mapping& x )
{
  x["is"] = "impliciet";
}
(I have discussed the code with some folks here at Croon. We feel it is not the best way the code this. The problem solved this way is the adding of a new key with a value of the type mapping.
This can also be achieved by passing the adres of the mapping and the new key as parameters to foo().

But currently the code seems to work just fine. From your reaction i get the feeling it will not do so in the future releases of PVSS. That's why i posted this on the forum.)


regards,
Kees

User avatar
mkoller
Posts: 741
Joined: Fri Sep 17, 2010 9:03 am

Re: Howto code a mapping in a mapping

Post by mkoller »

Huh ?
Your original post did include a different script than the one currently shown above ... did you change it later on ?
My reply was based on your initial code:

main()
{
mapping p;
foo(p);
DebugN(p);
}

foo(mapping& x )
{
x = "impliciet";
}

foo tries to assign a string to the complete mapping, which is not possible, therefore the error.

Your (changed) code from above now works without error
Calling foo(p["xxx"]);
Indexing a mapping with a key which does not exist yet will produce a new entry in the mapping with that key
containing an empty mixed as its value.

kdroog4pvss
Posts: 15
Joined: Wed Sep 22, 2010 10:17 am

Re: Howto code a mapping in a mapping

Post by kdroog4pvss »

Hi Martin,
If you look at my first code snippet it call foo with p["xxx"]. Which does not yet exists, because "xxx" is not yet used.
My second post is first creating p["xxx"] by assigning an empty string. That gives me the same error as you mentioned in your first answer.

You confirm that my first code snippet actually works.
Does this also mean it is a valid way of programming? Is it working this way by design?

Kind regards,
Kees

Gertjan van Schijndel
Posts: 634
Joined: Mon Aug 02, 2010 10:37 am

Re: Howto code a mapping in a mapping

Post by Gertjan van Schijndel »

Martin,

Here is another example:

Code: Select all

main() 
{
  mapping x;
  dpGet("System1:ExampleDP_SumAlert.", x["text"]);
  DebugN(x);
}
Is this code correct and allowed?
And will this code still work in future versions of wincc oa?

Post Reply
6 posts • Page 1 of 1