home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20cpp.zip / src / TFileCollection.cpp < prev    next >
C/C++ Source or Header  |  1998-01-19  |  1KB  |  66 lines

  1. /*
  2.  * TFileCollection.cc
  3.  *
  4.  * Turbo Vision - Version 2.0
  5.  *
  6.  * Copyright (c) 1994 by Borland International
  7.  * All Rights Reserved.
  8.  *
  9.  * Modified by Sergio Sigala <ssigala@globalnet.it>
  10.  */
  11.  
  12. #define Uses_TFileCollection
  13. #define Uses_TSearchRec
  14. #include <tvision/tv.h>
  15.  
  16. #include <string.h>
  17.  
  18. inline const char *getName( void *k )
  19. {
  20.     return ((TSearchRec *)k)->name;
  21. }
  22.  
  23. inline int attr( void *k )
  24. {
  25.     return ((TSearchRec *)k)->attr;
  26. }
  27.  
  28. int TFileCollection::compare(void *key1, void *key2)
  29. {
  30.     if( strcmp( getName( key1 ), getName( key2 ) ) == 0 )
  31.         return 0;
  32.  
  33.     if( strcmp( getName( key1 ), ".." ) == 0 )
  34.         return 1;
  35.     if( strcmp( getName( key2 ), ".." ) == 0 )
  36.         return -1;
  37.  
  38.     if( (attr( key1 ) & FA_DIREC) != 0 && (attr( key2 ) & FA_DIREC) == 0 )
  39.         return 1;
  40.     if( (attr( key2 ) & FA_DIREC) != 0 && (attr( key1 ) & FA_DIREC) == 0 )
  41.         return -1;
  42.  
  43.     return strcmp( getName( key1 ), getName( key2 ) );
  44. }
  45.  
  46.  
  47. TStreamable *TFileCollection::build()
  48. {
  49.     return new TFileCollection( streamableInit );
  50. }
  51.  
  52. void TFileCollection::writeItem( void *obj, opstream& os )
  53. {
  54.     TSearchRec *item = (TSearchRec *)obj;
  55.     os << item->attr << item->time << item->size;
  56.     os.writeString( item->name );
  57. }
  58.  
  59. void *TFileCollection::readItem( ipstream& is )
  60. {
  61.     TSearchRec *item = new TSearchRec;
  62.     is >> item->attr >> item->time >> item->size;
  63.     is.readString( item->name, sizeof(item->name) );
  64.     return item;
  65. }
  66.