Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Type constraints cs348 unit7

Get Embed Code
1 Language

Showing Revision 1 created 04/13/2013 by Cogi-Admin.

  1. Here is some new Syntax which I want you to understand because I've used in the

  2. agent refinement. There is a constraint called a type constraint which allows
  3. you to refine the type of a field to one of it's subtypes. The syntax is keep
  4. type and then the field name property equals my property name. Let's have a
  5. look at an example. Here is a shortened version of our signal map and packet
  6. agent. In the signal map we the direction field, which we also have in the
  7. agent. They are linked with a constraint. So if we have an ingress agent we
  8. also have an ingress signal map. In the ingress signal map, we have a port. Now
  9. down here, we have a method. It is defined as empty in the agent. And in the
  10. ingress packet agent, it's refined and it accesses this port. So we say, if the
  11. error port of the signal map is 1, we have an error. This access should work,
  12. because the signal map is of the same type as the packet agent. If we load this
  13. code. You get a log file like this. It's basically telling you, you're trying
  14. to access a field of signal map, which only exists in one of its sub-types. And
  15. it asks you to do type conversion, or casting, using the, is a or as a
  16. operators. Now, we have many ports, so we don't want to do this. This is why we
  17. will use the type constraint. So, I will basically replace this constraint with
  18. a type constraint. So I remove this read only as well. Now, in order to use
  19. type constraints, the fields you are talking about need to be constant fields.
  20. Constant means they cannot be changed after the initial randomization and
  21. allocation. So once you've created this field and set it's value it cannot
  22. change during the run time. So if we now save this and run. We can see that the
  23. code loads and we can now access sub type specific fields without having to do
  24. type casting.