home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / djgpp / src / libgplus.5 / libgplus / etc / lf / entry.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-25  |  1.9 KB  |  71 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2.  
  3. /* Manipulate directory entries of a particular file class. */
  4. #ifndef entry_h
  5. #define entry_h 1
  6. #include <std.h>
  7. #include <new.h>
  8. #include "screen.h"
  9.  
  10. /* Defined in sort.cc. */
  11. void sort (char **base_ptr, int total_elems);
  12.  
  13. class Entry_Handler
  14. {
  15.   
  16. private:
  17.   /* Initial number of file entries per class. */
  18.   static const int    default_entries;  
  19.  
  20.                int    max_entry_length; /* Size of largest filename. */
  21.                int    total_entries;    /* Total number of filenames. */
  22.                int    entries;          /* Current number of filenames. */
  23.                char **buf;              /* Buffer containing filenames for this file class. */
  24.   
  25. public:
  26.                       Entry_Handler (void);                     /* Initialize a new file class. */
  27.   int                 entry_number (void);                      /* Current number of entries. */
  28.   void                add_entry (char *entry_name, int length); /* Add an entry to the class. */
  29.   void                sort_entries (void);                      /* Sort entries by filename. */
  30.   void                print_entries (char *class_name);         /* Print file entries. */
  31. };
  32.  
  33. /* See comments in the .cc file for the following inline functions */
  34.  
  35. #ifdef __OPTIMIZE__
  36. inline 
  37. Entry_Handler::Entry_Handler (void)
  38. {
  39.   entries = max_entry_length = 0;
  40.   total_entries = default_entries;
  41.   buf = new char *[default_entries];
  42. }
  43.  
  44. inline int 
  45. Entry_Handler::entry_number (void)
  46. {
  47.   return entries;
  48. }
  49.  
  50. inline void 
  51. Entry_Handler::add_entry (char *entry_name, int length)
  52. {
  53.   if (entries >= total_entries)
  54. #ifdef _G_OLD_PLACEMENT
  55.     buf = new {buf, total_entries *= 2} char *;
  56. #else
  57.     buf = new (buf, total_entries *= 2) char *;
  58. #endif
  59.   max_entry_length >?= length;
  60.   buf[entries++] = strcpy (new char[length + 1], entry_name);
  61. }
  62.  
  63. inline void 
  64. Entry_Handler::sort_entries (void)
  65. {
  66.   sort (buf, entries);
  67. }
  68.  
  69. #endif // __OPTIMIZE__
  70. #endif
  71.