Skip To Content ArcGIS for Developers Sign In Dashboard

Downcast helper functions

When you create a new derived class object from a base class object, the base class object must contain an object of the same derived class. Otherwise, the new derived class object will not be valid. Be careful to use the correct constructor and input type to ensure the constructed object is valid. You can use these helper functions for this. Each function performs type-safe downcasting, accepting a base class object and returning a new derived class object. The new object will be empty if the base class object does not contain the derived class or is empty. Use the isValid function on the new object to check its validity.

Here are the base classes whose derived classes can use the corresponding helper functions.

Base classDowncast helper function
Esri::ArcGISRuntime::DomainEsri::ArcGISRuntime::domain_cast
Esri::ArcGISRuntime::GeometryEsri::ArcGISRuntime::geometry_cast
Esri::ArcGISRuntime::IdInfoEsri::ArcGISRuntime::idinfo_cast
Esri::ArcGISRuntime::StretchParametersEsri::ArcGISRuntime::stretch_parameters_cast
Esri::ArcGISRuntime::UnitEsri::ArcGISRuntime::unit_cast

Every helper function follows the same signature pattern.

DerivedClassName dci = helper_function_name<BaseClassName>(bci);

Where:

  • DerivedClassName is the name of the derived class (such as Point).
  • dci is the variable to receive the derived class instance.
  • helper_function_name is the name of the helper functions (such as geometry_cast).
  • BaseClassName is the name of the base class (such as Geometry).
  • bci is the variable containing the base class instance.

For example, casting StretchParameters-derived class to StretchParameters is always valid.

MinMaxStretchParameters minMaxStretchParameters(minValues, maxValues);
StretchParameters stretchParameters = stretch_parameters_cast<StretchParameters>(minMaxStretchParameters);
QASSERT(stretchParameters.isValid());

But casting from StretchParameters to StretchParameters-derived class is valid only if stretchParametersType is the same type as target type.

StretchParameters stretchParameters = stretchRenderer->stretchParameters();
MinMaxStretchParameters minMaxStretchParameters = stretch_parameters_cast<MinMaxStretchParameters>(stretchParameters);
QASSERT(minMaxStretchParameters.isValid());

StretchParameters invalidStretchParameters = invalidStretchRenderer->stretchParameters();
MinMaxStretchParameters invalidMinMaxStretchParameters = stretch_parameters_cast<MinMaxStretchParameters>(invalidStretchParameters);
QASSERT(!invalidMinMaxStretchParameters.isValid());

The following classes can be used with the downcast helper functions.

Esri::ArcGISRuntime::AngularUnit

Indicates the units of measurement of an instance of AngularUnit, or an angular measurement operation

Esri::ArcGISRuntime::AreaUnit

Indicates the units of measurement of an instance of AreaUnit, or area measurement operation

Esri::ArcGISRuntime::CodedValueDomain

A domain which specifies an explicit set of valid values for a field

Esri::ArcGISRuntime::Envelope

Represents a rectangular area, defined by a minimum and maximum x-coordinate and a minimum and maximum y-coordinate, and a spatial reference

Esri::ArcGISRuntime::FeatureServiceLayerIdInfo

Information about the feature service metadata for an ArcGIS Feature Service

Esri::ArcGISRuntime::HistogramEqualizationStretchParameters

A histogram equalization stretch parameters object

Esri::ArcGISRuntime::InheritedDomain

A domain which applies to domains on subtypes

Esri::ArcGISRuntime::LinearUnit

Indicates the specific units of measurement of an instance of LinearUnit, or linear measurement operation

Esri::ArcGISRuntime::MapServiceLayerIdInfo

Information about the map service metadata for an ArcGIS Map Service

Esri::ArcGISRuntime::MinMaxStretchParameters

A minimum/maximum stretch parameters object

Esri::ArcGISRuntime::Multipoint

A set of point locations treated as a single geometry

Esri::ArcGISRuntime::PercentClipStretchParameters

A percent clip stretch parameters object

Esri::ArcGISRuntime::Point

Represents a specific location, defined by an x,y coordinate pair, and a SpatialReference

Esri::ArcGISRuntime::Polygon

A geometry with an areal shape defined by a collection of parts, and a spatial reference

Esri::ArcGISRuntime::Polyline

A linear shape defined by a collection of parts, and a spatial reference

Esri::ArcGISRuntime::RangeDomain

A domain which specifies a range of valid values for a field

Esri::ArcGISRuntime::StandardDeviationStretchParameters

A standard deviation stretch parameters object

Esri::ArcGISRuntime::StretchParameters

Base class for various Stretch parameters

Note: The constructors for these classes may be marked as explicit in future versions. In the meantime, you should follow the recommended pattern of using the downcast helper function for casting from the base class, then using isValid function on the derived class to ensure the object is valid.


Feedback on this topic?