Code Search for Developers
 
 
  

Cell.h from Magnus at Krugle


Show Cell.h syntax highlighted

// Copyright (C) 1994 The New York Group Theory Cooperative
// See magnus/doc/COPYRIGHT for the full notice.

// Contents: Definition and implementation of utility
//           template <class T> class Cell
//
// Cell is the basic component of externally linked lists.
//
// Principal Author: Roger Needham
//
// Status: Useable.
//
// Revision History:


#ifndef _CELL_H_
#define _CELL_H_

//#include "Word.h"

#include <iostream>
#include "IPC.h"
//@njz:
#include "error.h"
//


//@db 2.91

template<class T> class Cell;

template<class T>
std::ostream& operator < ( std::ostream& ostr, const Cell<T>& C ) 
{
  C.writeContents( ostr );
  return ostr;
}

template<class T>
std::istream& operator > ( std::istream& istr, Cell<T>& C ) 
{
  C.readContents( istr );
  return istr;
}

//@db end 


template<class T> class Cell {

public:

  Cell*  nextCell;

  Cell() : nextCell(NULL), contents(NULL) { }
  
  Cell(const Cell& C) : nextCell(NULL) {
    if (C.contents)
         contents = new T(*(C.contents));
    else
         contents = NULL;
  }
  Cell(const T& e, Cell* next = NULL) : nextCell(next) { contents = new T(e);}
  
  ~Cell() { delete contents; } // Compiler ~'s contents.
  // @stc @rn: why do you nullify?

  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // IPC tools:                                                          //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////

  friend std::ostream& operator < <T>( std::ostream& ostr, const Cell& C );

  friend std::istream& operator > <T>( std::istream& istr, Cell& C );
  
  void readContents(std::istream& istr);
  
  void writeContents(std::ostream& ostr) const;
   
  
  inline T getContents() {
        #if ( SAFETY > 0 )
                if (contents)
                    return *contents;
                else
		  //@njz
		  //   		    error("Reading noninicialized contents "
		  //						"in Cell::getContents");
		  error("Reading noninicialized contents Cell::getContents");
                  //
        #endif
        return *contents;
  }

  inline void setContents(const T& t) { 
     if (!contents) {contents = new T(t);}
     else *contents = t;
  }

private :
  T*     contents;
};

#endif




See more files for this project here

Magnus

Magnus is a special purpose mathematical package for Infinite Group Theory computations

Project homepage: http://sourceforge.net/projects/magnus
Programming language(s): C,C++
License: other

  Associations.h
  BTree.h
  BlackBox.h
  Cell.h
  Chars.h
  DArray.h
  DCell.h
  DList.h
  File.h
  GCD.h
  GlobalRandom.h
  IStreamPoll.h
  Int2.h
  List.h
  LogWatcher.h
  MagnusHome.h
  MultiDimArray.h
  QuickAssociations.h
  RandomNumbers.h
  Set.h
  Stack.h
  Timer.h
  Type.h
  Vector.h
  WordParser.h
  conversions.h