[fpc-pascal] Extending an enumeration
Mark Morgan Lloyd
markMLl.fpc-pascal at telemetry.co.uk
Fri Dec 28 14:40:53 CET 2012
Ludo Brands wrote:
> On 28/12/2012 12:59, Ludo Brands wrote:
>> On 28/12/2012 12:48, Mark Morgan Lloyd wrote:
>>> Ludo Brands wrote:
>>>> type
>>>> TAllServerCapabilitiesBase=(uscConnected,
>>>> uscCanIssueGUID,lscConnected, lscCanIssueGUID, lscIsFirebird);
>>>> TUpstreamServerCapabilitiesBase= uscConnected .. uscCanIssueGUID;
>>>> TLocalServerCapabilitiesBase= lscConnected..lscIsFirebird;
>>>>
>>>> TAllServerCapabiliets=set of TAllServerCapabilitiesBase;
>>>> TUpstreamServerCapabilities= set of TUpstreamServerCapabilitiesBase;
>>>> TLocalServerCapabilities= set of TLocalServerCapabilitiesBase;
>>>
>>> Thanks, but I was hoping for something the other way round i.e.:
>>>
>>> type TCommonServerCapabilitiesBase= (scConnected, scCanIssueGUID);
>>>
>>> TLocalServerCapabilitiesBase(TCommonServerCapabilitiesBase) +=
>>> (lscIsFirebird); // INVALID CODE, EXAMPLE ONLY.
>>>
>>> TLocalServerCapabilities= set of TLocalServerCapabilitiesBase;
>>>
>>> I'd be fairly happy with any solution that did the necessary
>>> type/range checking at runtime.
>>>
>> Enumerations have an ordinal value that starts with 0 by default.
>> "Combining" enumerations has to make sure the ordinal values are
>> different. As a result you can go from bigger to smaller but not the
>> other way around. In your case with 2 subranges you could do something
>> like:
>>
>> type
>> TAllServerCapabilitiesBase=(uscWhatever scConnected,
>> scCanIssueGUID, lscIsFirebird);
>> TUpstreamServerCapabilitiesBase= uscWhatever .. uscCanIssueGUID;
> Obviously that should read
> TUpstreamServerCapabilitiesBase= uscWhatever .. scCanIssueGUID;
>> TLocalServerCapabilitiesBase= scConnected..lscIsFirebird;
>>
>> Just make sure you put the common values in the middle.
OK, so if I'm reading that correctly you're putting all possible values
into the initial enumeration, declaring subranges of that, and finally
declaring sets from the subranges (which might occupy more bits than
strictly needed, since the size is determined by the initial enumeration).
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the fpc-pascal
mailing list