funny use of static_cast

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

funny use of static_cast

Jim Newton
I found the following curious usage. Does anyone think it is wrong. The code is taking and Element and casting it to Chord* before checking its element type. I would think the static_cast<chord*> and the if ( ... chord-.tupe() != Element::Type::CHORD) continue should be reversed? Am I confused?
void Score::createPlayEvents()
      {
      int etrack = nstaves() * VOICES;
      for (int track = 0; track < etrack; ++track) {
            int mn=0;
            for (Measure* m = firstMeasure(); m; mn++, m = m->nextMeasure()) {
                  // skip linked staves, except primary
                  if (!m->score()->staff(track / VOICES)->primaryStaff())
                        continue;
                  const Segment::Type st = Segment::Type::ChordRest;
                  for (Segment* seg = m->first(st); seg; seg = seg->next(st)) {
                        Chord* chord = static_cast<Chord*>(seg->element(track)); // curious line order
                        if (chord == 0 || chord->type() != Element::Type::CHORD)  // curious line order
                              continue;
                        createPlayEvents(chord);
                        }
                  }
            }
      }