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

  1.  
  2.  
  3. #ifndef _objset_h_ /* Wed Apr 20 11:06:03 1994 */
  4. #define _objset_h_
  5.  
  6.  
  7.  
  8.  
  9.  
  10. /*
  11.  *
  12.  *          Copyright (C) 1994, M. A. Sridhar
  13.  *  
  14.  *
  15.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  16.  *     to copy, modify or distribute this software  as you see fit,
  17.  *     and to use  it  for  any  purpose, provided   this copyright
  18.  *     notice and the following   disclaimer are included  with all
  19.  *     copies.
  20.  *
  21.  *                        DISCLAIMER
  22.  *
  23.  *     The author makes no warranties, either expressed or implied,
  24.  *     with respect  to  this  software, its  quality, performance,
  25.  *     merchantability, or fitness for any particular purpose. This
  26.  *     software is distributed  AS IS.  The  user of this  software
  27.  *     assumes all risks  as to its quality  and performance. In no
  28.  *     event shall the author be liable for any direct, indirect or
  29.  *     consequential damages, even if the  author has been  advised
  30.  *     as to the possibility of such damages.
  31.  *
  32.  */
  33.  
  34.  
  35.  
  36.  
  37. // An object set is a derived class, rather than a typedef, so that we may
  38. // support persistent sets, and for "finding" objects in sets.
  39.  
  40.  
  41. #ifdef __GNUC__
  42. #pragma interface
  43. #endif
  44.  
  45.  
  46. #include "base/set.h"
  47. #include "base/iofilter.h"
  48. #include "base/stream.h"
  49.  
  50. class CL_EXPORT CL_ObjectSet: public CL_Set<CL_ObjectPtr> {
  51.  
  52. public:
  53.     CL_ObjectSet (CL_ObjectIOFilter* builder = NULL);
  54.     // Construct an ObjectSet whose iofilter is the given parameter.
  55.     // The parameter specifies an object io filter; it will
  56.     // only be used by the ReadFrom method when this set needs to be
  57.     // read from a stream, to construct an object from its passive
  58.     // representation in the stream. If the  parameter is NULL, the
  59.     // ReadFrom method will always return FALSE. The builder object is
  60.     // {\it not\/} owned by the Set, but it must
  61.     // exist as long as the Set does.
  62.     
  63.  
  64.     CL_ObjectSet (const CL_ObjectSet&);
  65.     // Copy constructor.
  66.  
  67.     CL_ObjectPtr Find (CL_ObjectPtr p) const;
  68.     // Determine whether the given object is in the set, and if so, return
  69.     // a pointer to the contained object. If not, return \NULL. This method
  70.     // is useful in situations where a compound object is stored in the
  71.     // set, where equality testing for the contained object is based only
  72.     // on some (not all) of its components.
  73.     
  74.     void DestroyContents ();
  75.     // Invoke the destructors of all the contained objects, and set our
  76.     // size to zero. Note that this is not the same as the inherited
  77.     // method MakeEmpty, since the latter does not destroy contained
  78.     // objects.
  79.  
  80.  
  81.  
  82.     bool ReadFrom (const CL_Stream&);
  83.     // Override the method inherited from {\small\tt CL_Object}.
  84.  
  85.     bool WriteTo  (CL_Stream&) const;
  86.     // Override the method inherited from {\small\tt CL_Object}.
  87.  
  88.     
  89.     
  90.     CL_ClassId ClassId() const {return _CL_ObjectSequence_CLASSID;};
  91.     
  92.     const char* ClassName () const {return "CL_ObjectSet";};
  93.     
  94. };
  95.  
  96.  
  97. typedef CL_SetIterator<CL_ObjectPtr> CL_ObjectSetIterator;
  98.  
  99.  
  100.  
  101.  
  102. inline bool CL_ObjectSet::ReadFrom (const CL_Stream& s)
  103. {
  104.     CL_ClassId id;
  105.     register bool b = s.Read (id) && id == ClassId();
  106.     return b && _idata ?
  107.         ((CL_Sequence<CL_ObjectPtr> *)_idata)->ReadFrom (s) : FALSE;
  108. }
  109.  
  110. inline bool CL_ObjectSet::WriteTo  (CL_Stream& s) const
  111. {
  112.     return _idata ? s.Write (ClassId()) &&
  113.         ((CL_Sequence<CL_ObjectPtr>*)_idata)->WriteTo (s) : FALSE;
  114. }
  115.  
  116.  
  117. #endif /* _objctset_h_ */
  118.