home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / MiscKit / Headers / misckit / MiscListIteration.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-23  |  1.9 KB  |  62 lines

  1. //
  2. //    MiscListIteration.h -- macros to iterate through List and HashTable objects
  3. //        Originally written by Drew Davidson
  4. //        Copyright (c) 1994 by Drew Davidson.
  5. //        Modified by Don Yacktman for inclusion into the MiscKit.
  6. //                Version 1.0.  All rights reserved.
  7. //        This notice may not be removed from this source code.
  8. //
  9. //    This object is included in the MiscKit by permission from the author
  10. //    and its use is governed by the MiscKit license, found in the file
  11. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  12. //    for a list of all applicable permissions and restrictions.
  13. //    
  14.  
  15.  
  16. // iterate over the elements in a List
  17. #define MISCforAllListObjectsTo(s,_i,toIndex) { \
  18. id _list = s; \
  19. int _slot=0; \
  20. id _i; \
  21. while( (_slot < toIndex) && ((_i = [_list objectAt:_slot++]) != nil) ) \
  22.  
  23. #define MISCforAllListObjectsFrom(s,_i,fromIndex) { \
  24. id _list = s; \
  25. int _slot=fromIndex; \
  26. id _i; \
  27. while( (_i = [_list objectAt:_slot++]) != nil ) \
  28.  
  29. #define MISCforAllListObjects(s,_i) { \
  30. id _list = s; \
  31. int _slot=0; \
  32. id _i; \
  33. while( (_i = [_list objectAt:_slot++]) != nil ) \
  34.  
  35. #define MISCforAllListObjectsBackwards(s,_i) {  \
  36. id _i; \
  37. id _list = s; \
  38. int _slot=[_list count]; \
  39. while( (_i = [_list objectAt:--_slot]) != nil ) \
  40.  
  41.  
  42. // to be used inside a MISCforAllListObjects()
  43. #define MISCRemoveCurrentObjectFromList(s) [s removeObjectAt:--_slot];
  44. #define MISCDecrementCurrentSlot (--_slot)
  45. #define MISCCurrentSlot                (_slot-1)
  46. #define MISCCurrentSlotBackwards    (_slot+1)
  47. #define MISCFirstSlot                    (0)
  48.  
  49.  
  50. // iterate over the elements in a HashTable
  51. // params: hashtable, key (returned), object (returned)
  52. #define MISCforAllHashTableObjects(s,_i, _key) {  \
  53. id _table = s; \
  54. NXHashState _state = [_table initState]; \
  55. id _i; \
  56. void * _key; \
  57. while([_table nextState: &_state key: (void *)&_key value: (void *)&_i])
  58.  
  59.  
  60. // This goes at the end of any of the above iteration constructs.
  61. #define MISCendFor }
  62.