home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 9.ddi / TVSRC.ZIP / TFILECOL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.4 KB  |  80 lines

  1. /*------------------------------------------------------------*/
  2. /* filename -       tfilecol.cpp                              */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                  TFileCollection member functions          */
  6. /*------------------------------------------------------------*/
  7.  
  8. /*------------------------------------------------------------*/
  9. /*                                                            */
  10. /*    Turbo Vision -  Version 1.0                             */
  11. /*                                                            */
  12. /*                                                            */
  13. /*    Copyright (c) 1991 by Borland International             */
  14. /*    All Rights Reserved.                                    */
  15. /*                                                            */
  16. /*------------------------------------------------------------*/
  17.  
  18.  
  19. #define Uses_TFileCollection
  20. #define Uses_TSearchRec
  21. #include <tv.h>
  22.  
  23. #if !defined( __STRING_H )
  24. #include <String.h>
  25. #endif  // __STRING_H
  26.  
  27. #if !defined( __DOS_H )
  28. #include <DOS.h>
  29. #endif  // __DOS_H
  30.  
  31. inline const char *getName( void *k )
  32. {
  33.     return ((TSearchRec *)k)->name;
  34. }
  35.  
  36. inline int attr( void *k )
  37. {
  38.     return ((TSearchRec *)k)->attr;
  39. }
  40.  
  41. int TFileCollection::compare(void *key1, void *key2)
  42. {
  43.     if( strcmp( getName( key1 ), getName( key2 ) ) == 0 )
  44.         return 0;
  45.  
  46.     if( strcmp( getName( key1 ), ".." ) == 0 )
  47.         return 1;
  48.     if( strcmp( getName( key2 ), ".." ) == 0 )
  49.         return -1;
  50.  
  51.     if( (attr( key1 ) & FA_DIREC) != 0 && (attr( key2 ) & FA_DIREC) == 0 )
  52.         return 1;
  53.     if( (attr( key2 ) & FA_DIREC) != 0 && (attr( key1 ) & FA_DIREC) == 0 )
  54.         return -1;
  55.  
  56.     return strcmp( getName( key1 ), getName( key2 ) );
  57. }
  58.  
  59. TStreamable *TFileCollection::build()
  60. {
  61.     return new TFileCollection( streamableInit );
  62. }
  63.  
  64. void TFileCollection::writeItem( void *obj, opstream& os )
  65. {
  66.     TSearchRec *item = (TSearchRec *)obj;
  67.     os << item->attr << item->time << item->size;
  68.     os.writeString( item->name );
  69. }
  70.  
  71. void *TFileCollection::readItem( ipstream& is )
  72. {
  73.     TSearchRec *item = new TSearchRec;
  74.     is >> item->attr >> item->time >> item->size;
  75.     is.readString( item->name, sizeof(item->name) );
  76.     return item;
  77. }
  78.  
  79.  
  80.