Opened 20 years ago
Last modified 17 years ago
#691 assigned enhancement
Add an "arrayType" member to psArray
| Reported by: | Owned by: | Paul Price | |
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | PSLib | Version: | unspecified |
| Severity: | minor | Keywords: | |
| Cc: |
Description
We make very extensive use of psArrays in the PS processing, but there's no way
for a routine to check that it's getting the right type of array. By using psArrays
we've given up on the option of compile-time checking, but we can include
a type in the psArray struct that at least allows a routine to assert that it's being
passed the right type. This has two virtues:
1/ It checks the types
2/ It allows the reader of the code to know what type's expected. You could
use a comment for this, but comments tend to get out of date.
I propose that we add a field "arrayType" to the psArray struct. This would be a
(void *) pointer, that could point to a (persistent) member of the type that should
be stored on the array. We should probably initialise this to NULL, but we could
add a new argument to psArrayAlloc.
Why would this help? Because (with the additions to the object APIs discussed
in PRs 689/690) the psArrayAdd code could check that the added element was of
the desired type:
if (!psTypeEqual(newElement, array->arrayType) { ... }
and a consumer of psArrays could say:
assert (pmIsSource(array->arrayType));
The new element isn't strictly neccessary for this last use, but the test would have
to special-case empty lists, and it would be unable to check their types.
Change History (2)
comment:1 by , 20 years ago
| Owner: | changed from to |
|---|
comment:2 by , 17 years ago
| Component: | IPP SDRS → PSLib |
|---|---|
| Priority: | high → low |
| Severity: | normal → minor |
| Status: | new → assigned |
| Type: | defect → enhancement |
I've changed the descriptors on this ticket to identify it as a low-priority feature request. I am not convinced that this is so useful of a feature; also note that a single array need not contain elements of a single type. the 'arrayType' would have to be optional, or have an allowed value of 'mixed'. I think the easiest way to implement the type would be to supply the free function pointer, which could be done with a function that accepts an instance of the type. it would be better to have the ability to assign the type without an example instance, but that would require some additional APIs.

I also thought of having an array type, but was of the opinion that the
provision of type checking (see bug 689) made this less of an issue. As it
stands currently, a function that uses a psArray can check each element as it is
used to see if the type matches what it expects.
Does the current functionality meet your requirements?