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.
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 | |
An appropriate list of 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 | |
An object that specifies an inherited domain that specifies the valid values for a Field | |
Indicates the specific units of measurement of an instance of LinearUnit, or linear measurement operation | |
An object that represents the sub layer metadata for a 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 multipart shape used to represent an area | |
A multipart shape used to represent a linear feature | |
Range of valid numbers or dates 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.