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

An ordered collection of points that can be managed as a single geometry

Esri::ArcGISRuntime::PercentClipStretchParameters

A percent clip stretch parameters object

Esri::ArcGISRuntime::Point

Represents a specific location, defined by x and y (and optionally z) coordinates, and a SpatialReference

Esri::ArcGISRuntime::Polygon

A geometry with an area shape defined by a collection of parts

Esri::ArcGISRuntime::Polyline

A linear shape defined by a collection of segments

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.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.