home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IDIOMS.ZIP / 5-16.C < prev    next >
C/C++ Source or Header  |  1991-12-04  |  1KB  |  56 lines

  1. /* Copyright (c) 1992 by AT&T Bell Laboratories. */
  2. /* Advanced C++ Programming Styles and Idioms */
  3. /* James O. Coplien */
  4. /* All rights reserved. */
  5.  
  6. #include <stddef.h>
  7. #include <memory.h>
  8.  
  9. class LAPD {
  10. friend class LAPDMemoryManager;
  11. friend class Conn;
  12. public:
  13.     virtual int size() { return 0; }
  14.     void *operator new(size_t);
  15.     void operator delete(void *);
  16.     LAPD(char *const);
  17. protected:
  18.     LAPD() { /* no-op */ }
  19. private:
  20.     int:8;
  21.     union {
  22.         struct {
  23.             unsigned char flag;
  24.             unsigned int sapi:6;
  25.         unsigned int commandResponse:1;
  26.         unsigned int zero:1;
  27.         unsigned int tei:7;
  28.         unsigned int ext:1;
  29.             unsigned char control;
  30.         } header;
  31.         struct {
  32.             LAPD *linkf, *linkb;
  33.             unsigned short size;
  34.         } minfo;
  35.     };
  36.     unsigned char tag;   // minfo system allocated tag
  37.     int performCRCCheck() { /* . . . */ return 0; }
  38. };
  39.  
  40. class Conn: public LAPD {
  41. friend LAPD;
  42. private:
  43.     struct ConnPacketBody {
  44.         unsigned char rep[4096];
  45.     } *body;
  46.     int bodySize;
  47.     int size() { return sizeof(Conn) + bodySize; }
  48.     Conn(const char *m): LAPD() {
  49.         // . . . .
  50.         ::memcpy(bodyStorage, m+sizeof(header), bodySize);
  51.         body = (ConnPacketBody*) bodyStorage;
  52.         manager.allocateResizeBlock( size() );
  53.     }
  54.     char bodyStorage[1];
  55. };
  56.