« Server migration | Main | ZNeK has a new homepage / WOEditor »

"Interesting" Example Code

From an AudioCore code sample:
static void	BuildDeviceMenu(AudioDeviceList *devlist, NSPopUpButton *menu, AudioDeviceID initSel)
{
   [menu removeAllItems];
   
   AudioDeviceList::DeviceList &thelist = devlist->GetList();
   int index = 0;
   for (AudioDeviceList::DeviceList::iterator i = thelist.begin(); i != thelist.end(); ++i, ++index) {
      while([menu itemWithTitle:[NSString stringWithCString: (*i).mName]] != nil) {
         strcat((*i).mName, " ");
      }
      
      if([menu itemWithTitle:[NSString stringWithCString: (*i).mName]] == nil) {
         [menu insertItemWithTitle: [NSString stringWithCString: (*i).mName] atIndex:index];
         
         if (initSel == (*i).mID)
            [menu selectItemAtIndex: index];
      }
   }
}
Also notice the clever use of if there to ensure nothing can go wrong.

About

This page contains a single entry from the blog posted on August 23, 2005 12:56 AM.

The previous post in this blog was Server migration.

The next post in this blog is ZNeK has a new homepage / WOEditor.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 4.25