Lab 8: object list_t

Objectives

To rework the C-style (singly-linked) list_t library in Objective-C.

Assignment

  1. Use the singly-linked list you developed in C, create both interface list.h and implementation list.m files for the list in Objective-C.
  2. You code should be such that the following main.m file works unaltered:
    #import <Foundation/Foundation.h>
    
    #import <stdio.h>
    #import <string.h>
    #import <list.h>
    
    #define NAME_LEN 16
    
    // data_t interface and implementation go here
    
    //---- program section ----
    
    int main(int argc, const char *argv[])
    {
            NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
            NSString *str;
    
            int     num;
            char    nam[NAME_LEN];
            list_t *list = [(list_t *)[list_t alloc] init];
            data_t *data = nil;
    
      NSLog(@"main start");
    
      while(scanf("%s %d",nam,&num) == 2) {
        fprintf(stderr,"%s %d\n",nam,num);
      //str = [[NSString alloc] initWithCString: nam]; // deprecated, do not use
        str = [[NSString alloc] initWithUTF8String: nam];
        // cast sender to proper class type eliminates warning about amgiguous init
        [list add: [(data_t *)[data_t alloc] init: str: num]];
      }
    
      [list reset];
    
      NSLog(@"printing list");
      while(![list end]) {
        [[list data] print: stderr];
        [list next];
      }
    
      [list reset];
    
      NSLog(@"popping list");
      [[[list pop] print: stderr] release];
    
      NSLog(@"printing list");
      while(![list end]) {
        [[list data] print: stderr];
        [list next];
      }
    
      NSLog(@"deleting list");
      [list reset];
      while(![list end]) [[list pop] release];
    
      NSLog(@"printing list");
      while(![list end]) {
        [[list data] print: stderr];
        [list next];
      }
    
      NSLog(@"deleting list again");
      [list reset];
      while(![list end]) [[list pop] release];
    
      NSLog(@"printing list again");
      while(![list end]) {
        [[list data] print: stderr];
        [list next];
      }
    
      [pool drain];
    
      return 0;
    }
    	
  3. Sample input (a file):
    Mike    1234
    Bill    3212
    Sarah   1321
    John    1021
    Carol   3223
    Debbie  4231
    Gary    9321
    Ann     1231
    Dale    7231
    Lynn    8133
    Patty   9999
    	
  4. Running the program:
    	./main < listdata.txt
    	
  5. Sample output (note that the timestamps will differ):
    2013-01-16 16:12:17.050 main[61387:903] main start
    Mike 1234
    Bill 3212
    Sarah 1321
    John 1021
    Carol 3223
    Debbie 4231
    Gary 9321
    Ann 1231
    Dale 7231
    Lynn 8133
    Patty 9999
    2013-01-16 16:12:17.052 main[61387:903] printing list
    Mike 1234
    Bill 3212
    Sarah 1321
    John 1021
    Carol 3223
    Debbie 4231
    Gary 9321
    Ann 1231
    Dale 7231
    Lynn 8133
    Patty 9999
    2013-01-16 16:12:17.053 main[61387:903] popping list
    Mike 1234
    2013-01-16 16:12:17.053 main[61387:903] printing list
    Bill 3212
    Sarah 1321
    John 1021
    Carol 3223
    Debbie 4231
    Gary 9321
    Ann 1231
    Dale 7231
    Lynn 8133
    Patty 9999
    2013-01-16 16:12:17.053 main[61387:903] deleting list
    2013-01-16 16:12:17.054 main[61387:903] printing list
    2013-01-16 16:12:17.054 main[61387:903] deleting list again
    2013-01-16 16:12:17.055 main[61387:903] printing list again
    	

Turn in

Turn in all of your code, in one tar.gz archive of your lab08/ directory, including:
  1. A README file containing
    1. Course id--section no
    2. Name
    3. Lab description
    4. Brief solution description (e.g., program design, description of algorithm, etc., however appropriate).
    5. Lessons learned, identified interesting features of your program
    6. Any special usage instructions
  2. Makefile
  3. source code (.h headers and .c source)
  4. object code (do a make clean before tar)

How to hand in

See submit notes.