Board index » delphi » Iterate over variable member set?

Iterate over variable member set?

Hi,

I have:

type
  TSimulation = (Original, AntiThetic, MatchMoment); { plus more...}
  TSimulationSet = set of TSimulation;
var
  Sim : TSimulationSet;
  counter : TSimulation;
begin
  Sim := [Original, MatchMoment];
  for counter := Low(TSimulation) to High(TSimulation) do
  begin
    if not (counter in Sim) then
      continue; { only operate on the set as described by Sim !!}

    case counter of
      Original:  fill vector;
      AntiThetic: transform vector;
       {AntiThetic relies on calculations made by Original}
      MatchMoment:  transform vector (if exists)

    { perform calculation - the same for Original, AntiThetic etc..}

What would be a more efficient way to iterate over the set described
by "Sim" while still retaining the elegance (IMO this is rather
elegant)?

This would be somewhat in the spirit of:
  for counter := low(Sim) to High(Sim) {which does not work}
--
Stefan.Hoffmeis...@Uni-Passau.de
http://www.rz.uni-passau.de/~w4hoff01/
University of Passau, Bavaria, Germany

 

Re:Iterate over variable member set?


Quote
Stefan Hoffmeister wrote:

> Hi,

> I have:

> type
>   TSimulation = (Original, AntiThetic, MatchMoment); { plus more...}
>   TSimulationSet = set of TSimulation;
> var
>   Sim : TSimulationSet;
>   counter : TSimulation;
> begin
>   Sim := [Original, MatchMoment];
>   for counter := Low(TSimulation) to High(TSimulation) do
>   begin
>     if not (counter in Sim) then
>       continue; { only operate on the set as described by Sim !!}

>     case counter of
>       Original:  fill vector;
>       AntiThetic: transform vector;
>        {AntiThetic relies on calculations made by Original}
>       MatchMoment:  transform vector (if exists)

>     { perform calculation - the same for Original, AntiThetic etc..}

> What would be a more efficient way to iterate over the set described
> by "Sim" while still retaining the elegance (IMO this is rather
> elegant)?

> This would be somewhat in the spirit of:
>   for counter := low(Sim) to High(Sim) {which does not work}

Yoy could use this:
  for counter := LOW(counter) to HIGH(counter) do if counter in sim then
begin
    case ...
  end;

But, I don't think you can make your code much more elegant...

later,

--
|----------------------------------------------------------------------------|
|Need a custom component? Late on a project? Could use an
util?              |
|DOS Device driver? A VxD? NT drivers or services? Applications of any
kind? |
|Low rates, fast
delivery!                                                   |
|----------------------------------------------------------------------------|
Erik Sperling Johansen <e...@info-pro.no>

Other Threads