Any::operator

Overview Extracts data from an Any.
Original class CORBA::Any


Intended Usage

This operator is used for type-safe extraction of a data value from an Any. If the C++ type of the data being extracted matches the TypeCode in the Any, the operator's parameter is updated with the Any's value. For simple types, the Any's value is copied to the parameter passed to the extraction operator. Non-primitive types are extracted by pointer; if the extraction is successful, the pointer passed to the extraction operator is modified to point to the Any's value. The Any retains owernship of the value and the caller must not delete it, and should not use the value after the Any is destroyed or given a new value. (For this reason, avoid using Any extraction operators to extract values into <type>_var variables.)

The to_boolean, to_char, and to_octet helper types are used to distinguish between the IDL types boolean, char, and octet, since these IDL types are mapped to the same C++ type. To extract a boolean, octet, or char from an Any, construct a helper object (by passing the data to be inserted to the helper's constructor), then use the helper object with the corresponding Any extraction operator.

The to_string helper type is used to extract a bounded or unbounded string from an Any, since both IDL types are mapped to char* in C++. (Unbounded strings are signified by constructing the from_string helper with a bound of zero.) Unbounded strings can also be extracted from an Any without the use of the from_string helper type.

In addition to the extraction operators defined in the Any class, corresponding to the basic IDL data types, the emitters generate global extraction operators for all types defined in IDL. This allows any type that can be defined in IDL to be extracted from an Any in a type-safe manner.

To extract an array from an Any, the <array-name>_forany helper type (defined in the emitted C++ bindings) should be used. In the C++ bindings, an array within a function argument list decays into a pointer to the first element, thus Any-extraction operators cannot be overloaded to distinguish between arrays of different sizes. Instead, Any-extraction operators are provided for each distinct <array-name>_forany type. To extract an array from an Any, create an appropriate <array-name>_forany object, initializing it from the array to be extraction , then use the global operator>> (the Any extraction operator) defined for that <array-name>_forany type.

After extracting a bounded string or an array from an Any, applications are responsible for checking the Any's TypeCode (using the Any::type() method) to insure they do not overstep the bounds of the array or string when using the extracted value.

The to_object helper type is used to extract an object reference from an Any as a generic CORBA::Object type. The Any extraction operator corresponding to the to_object helper type widens its contained object reference to CORBA::Object (if it contains one). No duplication of the object reference is performed by the to_object extraction operator.

Syntax

  CORBA::Boolean operator>>= (CORBA::Short& data) const;
  CORBA::Boolean operator>>= (CORBA::UShort& data) const;
  CORBA::Boolean operator>>= (CORBA::Long& data) const;
  CORBA::Boolean operator>>= (CORBA::ULong& data) const;
  CORBA::Boolean operator>>= (CORBA::Float& data) const;
  CORBA::Boolean operator>>= (CORBA::Double& data) const;
  CORBA::Boolean operator>>= (CORBA::Any& data) const;
  CORBA::Boolean operator>>= (char*& data) const;
  CORBA::Boolean operator>>= (WChar*& data) const;
  CORBA::Boolean operator>>= (CORBA::Any::to_boolean data) const;
  CORBA::Boolean operator>>= (CORBA::Any::to_char data) const;
  CORBA::Boolean operator>>= (CORBA::Any::to_octet data) const;
  CORBA::Boolean operator>>= (CORBA::Any::to_object data) const;
  CORBA::Boolean operator>>= (CORBA::Any::to_string data) const;

Parameters

data
The data whose value is to be extracted from the Any.

Return Value

CORBA::Boolean
A non-zero result indicates successful extraction and that the Any actually contained the type of data requested. A zero return value indicates that the Any's TypeCode does not match the C++ type of the operator's parameter and that nothing was extracted. For primitive types, a zero return value indicates that the parameter has not been modified. For non-primitive types, a zero return value indicates that the pointer passed to the operator has been set to NULL.

Example

See example in Any::operator<<.


Related reference
CORBA module



Searchable topic ID:   rcor_modan3
Last updated: Jun 21, 2007 8:07:48 PM CDT    WebSphere Business Integration Server Foundation, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.wasee.doc/info/ee/corba/ref/rcor_modan3.html

Library | Support | Terms of Use | Feedback