home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / base / clntset.cxx < prev    next >
C/C++ Source or Header  |  1995-04-04  |  4KB  |  147 lines

  1.  
  2.  
  3.  
  4.  
  5. /*
  6.  *
  7.  *          Copyright (C) 1994, M. A. Sridhar
  8.  *  
  9.  *
  10.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  11.  *     to copy, modify or distribute this software  as you see fit,
  12.  *     and to use  it  for  any  purpose, provided   this copyright
  13.  *     notice and the following   disclaimer are included  with all
  14.  *     copies.
  15.  *
  16.  *                        DISCLAIMER
  17.  *
  18.  *     The author makes no warranties, either expressed or implied,
  19.  *     with respect  to  this  software, its  quality, performance,
  20.  *     merchantability, or fitness for any particular purpose. This
  21.  *     software is distributed  AS IS.  The  user of this  software
  22.  *     assumes all risks  as to its quality  and performance. In no
  23.  *     event shall the author be liable for any direct, indirect or
  24.  *     consequential damages, even if the  author has been  advised
  25.  *     as to the possibility of such damages.
  26.  *
  27.  */
  28.  
  29.  
  30.  
  31. #ifdef __GNUC__
  32. #pragma implementation
  33. #endif
  34.  
  35.  
  36. #include "base/clntset.h"
  37.  
  38.  
  39. class CL_BindingElement: public CL_Object {
  40.  
  41. public:
  42.     CL_BindingElement (const CL_AbstractBinding& bind, long parameter)
  43.         :_bind ((CL_AbstractBinding*) bind.Clone()), _param (parameter) {};
  44.     ~CL_BindingElement ()
  45.         {delete _bind;};
  46.  
  47.     bool operator== (const CL_Object& o) const;
  48.     const char* ClassName () const {return "CL_BindingElement";};
  49.  
  50.  
  51.     CL_AbstractBinding* _bind;
  52.     long                _param;
  53. };
  54.  
  55.  
  56. bool CL_BindingElement::operator== (const CL_Object& o) const
  57. {
  58.     if (!_bind)
  59.         return FALSE;
  60.     return (*_bind == *(((const CL_BindingElement&) o)._bind));
  61. }
  62.  
  63.  
  64.  
  65. CL_ClientSet::~CL_ClientSet ()
  66. {
  67.     DestroyContents();
  68. }
  69.  
  70.  
  71. bool CL_ClientSet::Add (const CL_AbstractBinding& b, long p)
  72. {
  73.     CL_BindingElement* element = new CL_BindingElement (b, p);
  74.     if (CL_ObjectSet::Add (element))
  75.         return TRUE;
  76.     else {
  77.         delete element;
  78.         return FALSE;
  79.     }
  80. }
  81.  
  82.  
  83.  
  84. bool CL_ClientSet::Remove (const CL_AbstractBinding& b)
  85. {
  86.     CL_BindingElement e (b, 0); // We don't care about the second
  87.                                 // parameter, since it's not used for
  88.                                 // comparison
  89.     CL_BindingElement* element = (CL_BindingElement*)
  90.         CL_ObjectSet::Remove (&e);
  91.     if (element) {
  92.         delete element;
  93.         Notify ();
  94.         return TRUE;
  95.     }
  96.     return FALSE;
  97. }
  98.  
  99.  
  100. bool CL_ClientSet::Includes (const CL_AbstractBinding& b) const
  101. {
  102.     CL_BindingElement e (b, 0);
  103.     return CL_ObjectSet::Includes (&e);
  104. }
  105.  
  106.  
  107.  
  108. static long __NullVal = 0;
  109.  
  110. long& CL_ClientSet::CodeFor (const CL_AbstractBinding& b) const
  111. {
  112.     CL_BindingElement e (b, 0);
  113.     CL_BindingElement* element = (CL_BindingElement*) Find (&e);
  114.     if (!element) {
  115.         __NullVal = 0;
  116.         return __NullVal;
  117.     }
  118.     return element->_param;
  119. }
  120.  
  121.  
  122. void CL_ClientSet::NotifyAll (CL_Object& source) const
  123. {
  124.     CL_BindingElement* e;
  125.     long n = Size();
  126.     for (short i = 0; i < n; i++) {
  127.         e = (CL_BindingElement*) ItemWithRank (i);
  128.         e->_bind->Execute (source, e->_param);
  129.     }
  130. }
  131.  
  132.  
  133. bool CL_ClientSet::Permits (CL_Object& source) const
  134. {
  135.     CL_BindingElement* e;
  136.     long n = Size();
  137.     // Stop after the first FALSE return
  138.     for (short i = 0; i < n; i++) {
  139.         e = (CL_BindingElement*) ItemWithRank (i);
  140.         if (!e->_bind->Execute (source, e->_param))
  141.             return FALSE;
  142.     }
  143.     return TRUE;
  144. }
  145.  
  146.  
  147.