Previous Table of Contents Next


3.9.2 Boxed Value Type


   (15) <value_box_dcl> ::= “valuetype? <identifier> <type_spec>

   It is often convenient to define a value type with no inheritance or operations and with a single state member. A shorthand IDL notation is used to simplify the use of value types for this kind of simple containment, referred to as a “value box.?

   Since a value box of a valuetype adds no additional properties to a valuetype, it is an error to box valuetypes.

   Value box is particularly useful for strings and sequences. Basically one does not have to create what is in effect an additional namespace that will contain only one name.

   An example is the following IDL:

   module Example {interface Foo {

   ... /* anything */ }; valuetype FooSeq sequence<Foo>; interface Bar {

   void doIt (in FooSeq seq1);};};

   The above IDL provides similar functionality to writing the following IDL. However the type identities (repository ID’s) would be different.

   module Example {interface Foo {

   ... /* anything */};valuetype FooSeq {

   public sequence<Foo> data;};interface Bar {

   void doIt (in FooSeq seq);};};

   The former is easier to manipulate after it is mapped to a concrete programming language.

   Any IDL type may be used to declare a value box except for a valuetype.

   The declaration of a boxed value type does not open a new scope.Thus a construction such as:

   valuetype FooSeq sequence <FooSeq>;

   is not legal IDL. The identifier being declared as a boxed value type cannot be used subsequent to its initial use and prior to the completion of the boxed value declaration.