Previous Table of Contents Next


9.1 Overview

    Unless explicitly stated otherwise, all IDL presented in Section 9.1, “Overview,? on page 9-1 through Section 9.3, “Usage in C++ Language,? on page 9-25 is part of the DynamicAny module.

   July 2002 Common Object Request Broker Architecture (CORBA), v3.0 9-1

   Any values can be dynamically interpreted (traversed) and constructed through DynAny objects. A DynAny object is associated with a data value, which corresponds to a copy of the value inserted into an any.

   A DynAny object may be viewed as an ordered collection of component DynAnys. For DynAnys representing a basic type, such as long, or a type without components, such as an empty exception, the ordered collection of components is empty. Each DynAny object maintains the notion of a current position into its collection of component DynAnys. The current position is identified by an index value that runs from 0 to n−1, where n is the number of components. The special index value −1 indicates a current position that points nowhere. For values that cannot have a current position (such as an empty exception), the index value is fixed at −1. If a DynAny is initialized with a value that has components, the index is initialized to 0. After creation of an uninitialized DynAny (that is, a DynAny that has no value but a TypeCode that permits components), the current position depends on the type of value represented by the DynAny. (The current position is set to 0 or −1, depending on whether the new DynAny gets default values for its components.)

   The iteration operations rewind, seek, and next can be used to change the current position and the current_component operation returns the component at the current position. The component_count operation returns the number of components of a DynAny. Collectively, these operations enable iteration over the components of a DynAny, for example, to (recursively) examine its contents.

   A constructed DynAny object is a DynAny object associated with a constructed type. There is a different interface, inheriting from the DynAny interface, associated with each kind of constructed type in IDL (fixed, enum, struct, sequence, union, array, exception, and valuetype).

   A constructed DynAny object exports operations that enable the creation of new DynAny objects, each of them associated with a component of the constructed data value.

   As an example, a DynStruct is associated with a struct value. This means that the DynStruct may be seen as owning an ordered collection of components, one for each structure member. The DynStruct object exports operations that enable the creation of new DynAny objects, each of them associated with a member of the struct.

   If a DynAny object has been obtained from another (constructed) DynAny object, such as a DynAny representing a structure member that was created from a DynStruct, the member DynAny is logically contained in the DynStruct.

   Destroying a top-level DynAny object (one that was not obtained as a component of another DynAny) also destroys any component DynAny objects obtained from it. Destroying a non-top level DynAny object does nothing. Invoking operations on a destroyed top-level DynAny or any of its descendants raises OBJECT_NOT_EXIST. Note that simply releasing all references to a DynAny object does not delete the DynAny or components; each DynAny created with one of the create operations or with the copy operation must be explicitly destroyed to avoid memory leaks.