home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / ISC366.ZIP / SERIAL / BUFF.H < prev    next >
C/C++ Source or Header  |  1993-09-01  |  6KB  |  117 lines

  1. #ifndef  __BUFF_H
  2. #define  __BUFF_H
  3.  
  4. #include "public.h"
  5.  
  6.  
  7. // █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
  8. // █Written by: RAM MACHNESS                                                   █
  9. // █Started on: 24-11-1991                                                     █
  10. // ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  11.  
  12.  
  13. enum BUFF_OP {BUFF_FAILURE= 0,
  14.               BUFF_UNDERFLOW,
  15.               BUFF_OVERFLOW,
  16.               BUFF_OK_START_POINT,
  17.               BUFF_EMPTY,
  18.               BUFF_FULL,
  19.               BUFF_SINGLE_ITEM,
  20.               BUFF_READY };
  21.  
  22. class BUFF
  23. {
  24. private:
  25.     BYTE* buff;                 //the array of items.
  26.     BOOLEAN    self_allocated;  //was the array allocated by any constructor.
  27.     INDEX      head;            //head of the buffer pointing first item.
  28.     unsigned   current_length;  //current number of items on array.
  29.     unsigned   buff_len;        //max number of items may be in buff.
  30.     unsigned   alloc_len;       //max number of bytes allocated to the array.
  31.  
  32. public:
  33.        BUFF();                                  // default constructor
  34.        BUFF(const unsigned length);             // regular constructor
  35.        BUFF(const BUFF&    source_buff);        // copy constructor
  36.  
  37.        //╔═════════════════════════════════════════════╗
  38.        //║blocking constructor- based on other buff.   ║
  39.        //║this constructor creates   "virtual" buffer  ║
  40.        //║zero represents first item                   ║
  41.        //║defult is last item                          ║
  42.        //╚═════════════════════════════════════════════╝
  43.        BUFF(const BUFF&    source_buff,
  44.             const INDEX    block_start= 0,
  45.             const INDEX    block_len= 0xFF);
  46.  
  47.        ~BUFF();                                 // destructor
  48.  
  49.  
  50.        // ╔═════════════════════════════════════╗
  51.        // ║function to copy one buff to another ║
  52.        // ╚═════════════════════════════════════╝
  53.        void     operator=  (const BUFF& source_buff);
  54.  
  55.        // ╔════════════════════════════════════════════════════════════════╗
  56.        // ║function returning the current length of the buffer.            ║
  57.        // ║Pay attention- function may be used recoursively(by interrupts) ║
  58.        // ╚════════════════════════════════════════════════════════════════╝
  59.        unsigned len    (void) const;
  60.  
  61.        // ╔═════════════════════════════════════════════════════════════════╗
  62.        // ║function to insert a byte to the buff.                           ║
  63.        // ║Can't be operate on virtual buffer.                              ║
  64.        // ╚═════════════════════════════════════════════════════════════════╝
  65.        BUFF_OP  operator<< (const BYTE in_byte);
  66.  
  67.        // ╔══════════════════════════════════════════════════════════════════╗
  68.        // ║function to get the byte on the head of the queue.                ║
  69.        // ║Can't be operate on virtual buffer.                               ║
  70.        // ╚══════════════════════════════════════════════════════════════════╝
  71.        BUFF_OP  operator>> (BYTE& out_byte);
  72.  
  73.        // ╔══════════════════════════════════════════════════════════╗
  74.        // ║function to see the byte on the head of the queue without ║
  75.        // ║poping it out.                                            ║
  76.        // ╚══════════════════════════════════════════════════════════╝
  77.        BUFF_OP  operator>  (BYTE& out_byte);
  78.  
  79.        // ╔════════════════════════════════════════════════════╗
  80.        // ║function to add another buff to the sertain buffer. ║
  81.        // ║Can't be operate on virtual buffer.                 ║
  82.        // ║(but virtual buffer may be a parameter)             ║
  83.        // ╚════════════════════════════════════════════════════╝
  84.        BUFF_OP  operator<< (const BUFF& other_buff);
  85.  
  86.        // ╔════════════════════════════════════╗
  87.        // ║function to empty the buff.         ║
  88.        // ║Can't be operate on virtual buffer. ║
  89.        // ╚════════════════════════════════════╝
  90.        void     empty_buff (void);
  91.  
  92.        // ╔════════════════════════════════════════════════════════════════╗
  93.        // ║function to see an item according to its' index.                ║
  94.        // ║you may enter any index.                                        ║
  95.        // ║Pay attention- function may be used recoursively(by interrupts) ║
  96.        // ╚════════════════════════════════════════════════════════════════╝
  97.        BYTE     operator[] (const INDEX index) const;
  98.  
  99.        // ╔════════════════════════════════════════════════════════════════╗
  100.        // ║function to see and change an item according to its' index.     ║
  101.        // ║you may enter any index.                                        ║
  102.        // ║Pay attention- function may be used recoursively(by interrupts) ║
  103.        // ╚════════════════════════════════════════════════════════════════╝
  104.        BYTE&    operator[] (const INDEX index) ;
  105.  
  106.        // ╔════════════════════════════════════════════════════════╗
  107.        // ║function to change buffer size and to reset the buffer. ║
  108.        // ║Can't be operate on virtual buffer.                     ║
  109.        // ╚════════════════════════════════════════════════════════╝
  110.        BUFF_OP  reset_size (const unsigned new_size,
  111.                             const  BOOLEAN  reset= FALSE);
  112.  
  113.        // OOLA.
  114.        int buff_size(void) const { return buff_len; };
  115. };
  116. #endif /* __BUFF_H */
  117.