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

  1.  
  2.  
  3. #ifndef _basicops_h_ /* Sun May 22 12:44:53 1994 */
  4. #define _basicops_h_
  5.  
  6.  
  7.  
  8.  
  9. /*
  10.  *
  11.  *          Copyright (C) 1994, M. A. Sridhar
  12.  *  
  13.  *
  14.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  15.  *     to copy, modify or distribute this software  as you see fit,
  16.  *     and to use  it  for  any  purpose, provided   this copyright
  17.  *     notice and the following   disclaimer are included  with all
  18.  *     copies.
  19.  *
  20.  *                        DISCLAIMER
  21.  *
  22.  *     The author makes no warranties, either expressed or implied,
  23.  *     with respect  to  this  software, its  quality, performance,
  24.  *     merchantability, or fitness for any particular purpose. This
  25.  *     software is distributed  AS IS.  The  user of this  software
  26.  *     assumes all risks  as to its quality  and performance. In no
  27.  *     event shall the author be liable for any direct, indirect or
  28.  *     consequential damages, even if the  author has been  advised
  29.  *     as to the possibility of such damages.
  30.  *
  31.  */
  32.  
  33.  
  34.  
  35.  
  36. // The "basic operations" class provides inline functions for primitive
  37. // operations on data types, namely null values, comparison and archival.
  38.  
  39.  
  40. #ifdef __GNUC__
  41. #pragma interface
  42. #endif
  43.  
  44.  
  45. #include "base/defs.h"
  46. #include "base/string.h"
  47.  
  48. class CL_EXPORT CL_ObjectIOFilter;
  49.  
  50. template <class Base>
  51. class CL_EXPORT CL_Basics {
  52.  
  53. public:
  54.     inline static Base       NullValue () ;
  55.  
  56.     inline static short      Compare (const Base& o1, const Base& o2);
  57.  
  58.     inline static CL_String  PrintableForm (const Base& o) ;
  59.  
  60.     inline static long       StoreWidth (const Base& o) ;
  61.  
  62. //     static bool       RestoreFrom (Base& b, const CL_Stream& s,
  63. //                                    CL_ObjectIOFilter* f);
  64. //     
  65. //     static bool       SaveTo      (const Base& b, CL_Stream& s,
  66. //                                    CL_ObjectIOFilter* f);
  67.  
  68.     inline static Base&      Deref (CL_VoidPtr& b) ;
  69.     
  70.     inline static void       Destroy (CL_VoidPtr p);
  71.  
  72.     inline static void       ReallyDestroy (const Base&);
  73.  
  74.     inline static CL_VoidPtr    MakeCopy (const Base& o) ;
  75.  
  76.     inline static CL_VoidPtr    MakePointer (const Base& o) ;
  77.  
  78. };
  79.  
  80.  
  81.  
  82. // Warning: Place the template specialization functions textually BEFORE the
  83. // general template-based definitions (e.g., CL_Basics<long>::Compare is
  84. // defined BEFORE template <class Base> CL_Basics<Base>::Compare), otherwise
  85. // Borland C++ complains. 
  86.  
  87. // Include the template specializations for these static methods:
  88. #include "base/voidptr.h"
  89. #include "base/long.h"
  90. #include "base/objptr.h"
  91.  
  92. // The real template methods:
  93.  
  94. template <class Base>
  95. inline Base       CL_Basics<Base>::NullValue ()
  96. {
  97.     return Base ();
  98. }
  99.  
  100.     
  101.  
  102. template <class Base>
  103. inline short CL_Basics<Base>::Compare (const Base& o1, const Base& o2)
  104. {
  105.     return o1.Compare (o2);
  106. }
  107.     
  108.  
  109.  
  110. template <class Base>
  111. inline CL_String      CL_Basics<Base>::PrintableForm (const Base& o) 
  112. {
  113.     return o.AsString ();
  114. }
  115.  
  116. template <class Base>
  117. inline long       CL_Basics<Base>::StoreWidth (const Base& o) 
  118. {
  119.     return o.StorableFormWidth();
  120. }
  121.  
  122. template <class Base>
  123. inline void       CL_Basics<Base>::Destroy (CL_VoidPtr p)
  124. {
  125.     if (p) delete (Base*) p;
  126. }
  127.  
  128.  
  129.  
  130. template <class Base>
  131. inline void       CL_Basics<Base>::ReallyDestroy (const Base&)
  132. {
  133. }
  134.  
  135. template <class Base>
  136. inline CL_VoidPtr    CL_Basics<Base>::MakeCopy (const Base& o) 
  137. {
  138.     return  (CL_VoidPtr) new Base (o);
  139. }
  140.  
  141. template <class Base>
  142. inline CL_VoidPtr    CL_Basics<Base>::MakePointer (const Base& o)
  143. {
  144.     return (CL_VoidPtr) &o;
  145. }
  146.  
  147.  
  148. template <class Base>
  149. inline Base&      CL_Basics<Base>::Deref (CL_VoidPtr& b)
  150. {
  151.     return *(Base*&) b;
  152. }
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160. // ---------------------- Storage and retrieval operations ---------
  161.  
  162.  
  163.  
  164. bool CL_RestoreFrom (long& b, const CL_Stream& s, CL_ObjectIOFilter* );
  165.  
  166. bool CL_RestoreFrom (CL_ObjectPtr& b, const CL_Stream& s, 
  167.                      CL_ObjectIOFilter* f = 0);
  168.  
  169. bool CL_RestoreFrom (CL_Object& b, const CL_Stream& s,
  170.                      CL_ObjectIOFilter* f = 0);
  171.  
  172. inline bool CL_RestoreFrom (CL_VoidPtr&, const CL_Stream&,
  173.                             CL_ObjectIOFilter*)
  174. {
  175.     return FALSE; // Do nothing
  176. }
  177.  
  178.  
  179.  
  180. bool CL_SaveTo (const CL_Object& b, CL_Stream& s,
  181.                 CL_ObjectIOFilter* f = 0);
  182.  
  183. bool CL_SaveTo (const long& b, CL_Stream& s,
  184.                 CL_ObjectIOFilter*  = 0);
  185.  
  186. bool CL_SaveTo (const CL_ObjectPtr& b, CL_Stream& s,
  187.                 CL_ObjectIOFilter* f = 0);
  188.  
  189. inline bool CL_SaveTo (const CL_VoidPtr&, CL_Stream&,
  190.                        CL_ObjectIOFilter* = 0)
  191. {
  192.     return FALSE; // Do nothing
  193. }
  194.  
  195.  
  196.  
  197.  
  198.  
  199. #endif /* _basicops_h_ */
  200.