341 |
s=segment(-3,7) |
s=segment(-3,7) |
342 |
print s.left_limit, s.right_limit |
print s.left_limit, s.right_limit |
343 |
|
|
344 |
|
Unions |
345 |
|
- Union types are mapped to classes with two attributes, |
346 |
|
first being the descriminant _d, the second the associated |
347 |
|
value _v |
348 |
|
- for each branch, there is an additional attribute, |
349 |
|
which can only be accessed if the branch has been set, |
350 |
|
there are three possibilities: |
351 |
|
|
352 |
|
- if the discriminant was explicitly listed in a case |
353 |
|
statement, the value is of the branch associated |
354 |
|
with the case |
355 |
|
- if the discriminant is not explicitly listed and |
356 |
|
there is a default case label, the value is of the |
357 |
|
branch associated with the case label |
358 |
|
- if the discriminant is not listed, and there is no |
359 |
|
default, the value is None |
360 |
|
|
361 |
|
- constructor of the class expects the discriminator and |
362 |
|
the value as arguments |
363 |
|
- alternatively, the union can also be constructed by |
364 |
|
passing a keyword argument, with the field name of the |
365 |
|
union as the key, if more than one discriminator is |
366 |
|
associated with a field, the discriminator must be |
367 |
|
set explicitly |
368 |
|
|
369 |
|
Example: |
370 |
|
|
371 |
|
union MyUnion switch(long) |
372 |
|
{ |
373 |
|
case 1: string s; |
374 |
|
default: long x; |
375 |
|
}; |
376 |
|
|
377 |
|
can be accessed as |
378 |
|
|
379 |
|
u = MyUnion(17, 42) |
380 |
|
print u.x |
381 |
|
u = MyUnion(s = 'string') |
382 |
|
print u._d, u._v |
383 |
|
|
384 |
Exceptions |
Exceptions |
385 |
- when error detected, exception is raised using standard Python |
- when error detected, exception is raised using standard Python |
386 |
exception mechanism, which consists of deriving from |
exception mechanism, which consists of deriving from |
726 |
- ch. 2 introduced several new kinds of collections that |
- ch. 2 introduced several new kinds of collections that |
727 |
extend the IDL sequence |
extend the IDL sequence |
728 |
- the following shows the Python interfaces/classes that this |
- the following shows the Python interfaces/classes that this |
|
binding defines for each of the collection interfaces |
|
729 |
|
binding defines for each of the collection interfaces |