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 class | Downcast helper function |
---|---|
Esri::ArcGISRuntime::Domain | Esri::ArcGISRuntime::domain_cast |
Esri::ArcGISRuntime::Geometry | Esri::ArcGISRuntime::geometry_cast |
Esri::ArcGISRuntime::IdInfo | Esri::ArcGISRuntime::idinfo_cast |
Esri::ArcGISRuntime::StretchParameters | Esri::ArcGISRuntime::stretch_parameters_cast |
Esri::ArcGISRuntime::Unit | Esri::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 asPoint
).dci
is the variable to receive the derived class instance.helper_function_name
is the name of the helper functions (such asgeometry_cast
).BaseClassName
is the name of the base class (such asGeometry
).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.
Indicates the units of measurement of an instance of AngularUnit, or an angular measurement operation | |
Indicates the units of measurement of an instance of AreaUnit, or area measurement operation | |
A domain which specifies an explicit set of valid values for a field | |
Represents a rectangular area, defined by a minimum and maximum x-coordinate and a minimum and maximum y-coordinate, and a spatial reference | |
Information about the feature service metadata for an ArcGIS Feature Service | |
A histogram equalization stretch parameters object | |
A domain which applies to domains on subtypes | |
Indicates the specific units of measurement of an instance of LinearUnit, or linear measurement operation | |
Information about the map service metadata for an ArcGIS Map Service | |
A minimum/maximum stretch parameters object | |
An ordered collection of points that can be managed as a single geometry | |
A percent clip stretch parameters object | |
Represents a specific location, defined by x and y (and optionally z) coordinates, and a SpatialReference | |
A geometry with an area shape defined by a collection of parts | |
A linear shape defined by a collection of segments | |
A domain which specifies a range of valid values for a field | |
A standard deviation stretch parameters object | |
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.