home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / SRCBDTO.PAK / BDTEVENT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  2.0 KB  |  97 lines

  1. //----------------------------------------------------------------------------
  2. // Visual Database Tools
  3. // Copyright (c) 1996 by Borland International, All Rights Reserved
  4. //
  5. // bdtevent.cpp
  6. // Event mechanism portion of the PME subsystem for BDT
  7. //-----------------------------------------------------------------------------
  8.  
  9. #include <vdbt\bdte.h>
  10.  
  11. #pragma hdrstop
  12.  
  13. //-----------------------------------------------------------------------------
  14. //
  15. //
  16. //
  17. TBdtEventSourceBase::TBdtEventSourceBase(const TSrcAttachFunctor& ftor)
  18. :
  19.   Sink(0),
  20.   Ftor(ftor)
  21. {
  22. }
  23.  
  24. //
  25. // Clean up the sink chain on destruction
  26. //
  27. TBdtEventSourceBase::~TBdtEventSourceBase()
  28. {
  29.   for (TBdtEventSinkBase* sp = Sink; sp; sp = sp->Next)
  30.     sp->Source = 0;
  31. }
  32.  
  33. //
  34. // Add an event sink to the chain for this source
  35. //
  36. void TBdtEventSourceBase::operator +=(TBdtEventSinkBase& sink)
  37. {
  38.   // Notify that we now have connections
  39.   //
  40.   if (!Sink)
  41.     Ftor(*this,true);
  42.  
  43.   // Detach from existing chain
  44.   //
  45.   if (sink.Source)
  46.     (*sink.Source) -= sink;
  47.  
  48.   // Insert at head of event sink chain
  49.   //
  50.   TBdtEventSinkBase* oldsink = Sink;
  51.   Sink = &sink;
  52.   sink.Next = oldsink;
  53.   sink.Source = this;
  54. }
  55.  
  56. //
  57. // Remove an event sink from the chain for this source
  58. //
  59. void TBdtEventSourceBase::operator -=(TBdtEventSinkBase& sink)
  60. {
  61.   if (Sink) {
  62.     for (TBdtEventSinkBase** sp = &Sink; *sp; sp = &(*sp)->Next) {
  63.       if (*sp == &sink) {
  64.         *sp = (*sp)->Next;
  65.         sink.Next = 0;
  66.         sink.Source = 0;
  67.         break;
  68.       }
  69.     }
  70.  
  71.     // Notify that we no longer have connections
  72.     //
  73.     if (!Sink)
  74.       Ftor(*this,false);
  75.   }
  76. }
  77.  
  78. //-----------------------------------------------------------------------------
  79.  
  80. //
  81. // Events sinks auto-detach when destructed
  82. //
  83. TBdtEventSinkBase::~TBdtEventSinkBase()
  84. {
  85.   if (Source)
  86.     *Source -= *this;
  87. }
  88.  
  89. //
  90. // Events sinks auto-detach when destructed
  91. //
  92. void TBdtEventSinkBase::Detach()
  93. {
  94.   if (Source)
  95.     *Source -= *this;
  96. }
  97.