Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

/magnus/back_end/general/include/Cell.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: Cell.h,v 1.7 1999/11/23 20:37:29 bormotov Exp $
00003  */
00004 
00005 // Copyright (C) 1994 The New York Group Theory Cooperative
00006 // See magnus/doc/COPYRIGHT for the full notice.
00007 
00008 // Contents: Definition and implementation of utility
00009 //           template <class T> class Cell
00010 //
00011 // Cell is the basic component of externally linked lists.
00012 //
00013 // Principal Author: Roger Needham
00014 //
00015 // Status: Useable.
00016 //
00017 // Revision History:
00018 
00019 
00020 #ifndef _CELL_H_
00021 #define _CELL_H_
00022 
00023 //#include "Word.h"
00024 
00025 #include <iostream.h>
00026 #include "IPC.h"
00027 
00028 
00029 //@db 2.91
00030 
00031 template<class T> class Cell;
00032 
00033 template<class T>
00034 ostream& operator < ( ostream& ostr, const Cell<T>& C ) 
00035 {
00036   C.writeContents( ostr );
00037   return ostr;
00038 }
00039 
00040 template<class T>
00041 istream& operator > ( istream& istr, Cell<T>& C ) 
00042 {
00043   C.readContents( istr );
00044   return istr;
00045 }
00046 
00047 //@db end 
00048 
00049 
00050 //! Cell is the basic component of externally linked lists.
00051 template<class T> class Cell {
00052 
00053 public:
00054 
00055   Cell*  nextCell;
00056   //!< Pointer to the next cell.
00057 
00058   Cell() : nextCell(NULL), contents(NULL) { }
00059   //!< Default constructor
00060 
00061   Cell(const Cell& C) : nextCell(NULL) {
00062     if (C.contents)
00063          contents = new T(*(C.contents));
00064     else
00065          contents = NULL;
00066   }
00067   //!< Copy constructor
00068 
00069   Cell(const T& e, Cell* next = NULL) : nextCell(next) { contents = new T(e);}
00070   //!< Creates a cell with content 'e' and next cell pointing to 'next'.
00071   
00072   ~Cell() { delete contents; } // Compiler ~'s contents.
00073   // @stc @rn: why do you nullify?
00074 
00075   /////////////////////////////////////////////////////////////////////////
00076   //                                                                     //
00077   // IPC tools:                                                          //
00078   //                                                                     //
00079   /////////////////////////////////////////////////////////////////////////
00080 
00081   friend ostream& operator < <T>( ostream& ostr, const Cell& C );
00082   //!< IPC tools:                                                          
00083 
00084   friend istream& operator > <T>( istream& istr, Cell& C );
00085   //!< IPC tools:                                                          
00086   
00087   void readContents(istream& istr);
00088   //!< Read contents from the stream
00089   
00090   void writeContents(ostream& ostr) const;
00091   //!< Write contents to the stream
00092    
00093   
00094   //! Returns contents of the cell
00095   inline T getContents() {
00096         #if ( SAFETY > 0 )
00097                 if (contents)
00098                     return *contents;
00099                 else
00100                     error("Reading noninicialized contents "
00101                                                 "in Cell::getContents");
00102         #endif
00103         return *contents;
00104   }
00105 
00106   //! Set contents of the cell
00107   inline void setContents(const T& t) { 
00108      if (!contents) {contents = new T(t);}
00109      else *contents = t;
00110   }
00111 
00112 private :
00113   T*     contents;
00114 //!< Contents of the cell 
00115 };
00116 
00117 #endif

Generated at Tue Jun 19 09:49:35 2001 for Magnus Classes by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001