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

  1.  
  2.  
  3. #ifndef _builder_h_ /* Wed Apr 20 22:49:51 1994 */
  4. #define _builder_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. // An ObjectBuilder is an object that can reconstruct another object from
  37. // a given data stream. This file contains an abstract class declaration;
  38. // each class that needs to be stored and retrieved must declare its own
  39. // derived version of ObjectBuilder.
  40.  
  41. #ifdef __GNUC__
  42. #pragma interface
  43. #endif
  44.  
  45. #include "base/object.h"
  46.  
  47. class CL_EXPORT CL_ObjectBuilder: public CL_Object {
  48.  
  49. public:
  50.     ~CL_ObjectBuilder () {};
  51.     
  52.     virtual CL_Object* BuildFrom (const CL_Stream&) = 0;
  53.     // Build a new object from its representation in the stream, and
  54.     // return it. The caller of this method then owns the new object, and
  55.     // must destroy it when done.
  56.  
  57.     const char* ClassName () const {return "CL_ObjectBuilder";};
  58.     
  59. };
  60.  
  61.  
  62.  
  63. // A Builder is a template-based specialization of ObjectBuilder, and
  64. // simply uses the object's ReadFrom method. This can be used in most
  65. // cases, obviating the need for defining an explicit ObjectBuilder class
  66. // for every client class.
  67.  
  68. template <class Base>
  69. class CL_EXPORT CL_Builder: public CL_ObjectBuilder {
  70.  
  71. public:
  72.     ~CL_Builder () {};
  73.     
  74.     CL_Object* BuildFrom (const CL_Stream& s)
  75.         { Base* p = new Base; p->ReadFrom (s); return p; };
  76.  
  77.     const char* ClassName () const {return "CL_Builder";};
  78.     
  79. };
  80.  
  81.  
  82.  
  83. #endif /* _builder_h_ */
  84.