home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IDIOMS.ZIP / 5-14.C < prev    next >
C/C++ Source or Header  |  1991-12-04  |  2KB  |  69 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 Setup;
  12. friend class Conn;
  13. public:
  14.     virtual int size() { return 0; }
  15.     void *operator new(size_t);
  16.     void operator delete(void *);
  17.     LAPD(char *const);
  18. protected:
  19.     LAPD() { /* no-op */ }
  20. private:
  21.     int:8;
  22.     union {
  23.         struct {
  24.             unsigned char flag;
  25.             unsigned int sapi:6;
  26.         unsigned int commandResponse:1;
  27.         unsigned int zero:1;
  28.         unsigned int tei:7;
  29.         unsigned int ext:1;
  30.             unsigned char control;
  31.         } header;
  32.         struct {
  33.             LAPD *linkf, *linkb;
  34.             unsigned short size;
  35.         } minfo;
  36.     };
  37.     unsigned char tag;   // minfo system allocated tag
  38.     int performCRCCheck() { /* . . . */ return 0; }
  39. };
  40.  
  41. class Setup: public LAPD {
  42. friend LAPD;
  43. private:
  44.     struct SetupPacketBody {
  45.         unsigned char rep[4096];
  46.     };
  47.     SetupPacketBody body;
  48.     int size() { return sizeof(Setup); }
  49.     Setup(const char *m): LAPD() {
  50.         manager.allocateResizeBlock( size() );
  51.         ::memcpy(&body, m+sizeof(header), sizeof(body));
  52.         // . . . .
  53.     }
  54. };
  55.  
  56. class Conn: public LAPD {
  57. friend LAPD;
  58. private:
  59.     struct ConnPacketBody {
  60.         unsigned char rep[4096];
  61.     };
  62.     ConnPacketBody body;
  63.     int size() { return sizeof(Conn); }
  64.     Conn(const char *m): LAPD() {
  65.         manager.allocateResizeBlock( size() );
  66.         ::memcpy(&body, m+sizeof(header), sizeof(body));
  67.     }
  68. };
  69.