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

/magnus/back_end/Elt/include/WordData.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: WordData.h,v 1.3 1999/11/23 20:22:43 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 of expanded format WordData class.
00009 //
00010 // Principal Author: Stephane Collart
00011 //
00012 // Status: Useable.
00013 //
00014 // Revision History:
00015 //
00016 
00017 #ifndef _WORD_DATA_H_
00018 #define _WORD_DATA_H_
00019 
00020 #include "global.h"
00021 #include "Generator.h"
00022 #include "List.h"
00023 #include "Vector.h"
00024 
00025 
00026 class WordData {
00027 
00028 public:
00029   
00030   // provide type parameter access to users
00031   typedef int GeneratorType;
00032   typedef GeneratorType* GeneratorPtrType; // for pseudo-ptr would be a class
00033   typedef const GeneratorType* cGeneratorPtrType;
00034   
00035   // copy constructor does deep copy
00036   WordData( const WordData& wd ) :
00037   len(wd.len), wrd(new GeneratorType[wd.len]) {
00038          for (int i = 0; i < len; i++) ref(i) = wd.val(i);
00039   }
00040   
00041   // destructor deletes data
00042   ~WordData( ) { delete[] wrd; }
00043   
00044   // data specific constructor(s)
00045 
00046   WordData( int le ) {
00047          #if SAFETY > 0
00048            if ( le > MAXLENGTH )
00049                   error("Tried to init a Word which is too long");
00050     #endif
00051          len = le;
00052          wrd = new GeneratorType[le];
00053   }
00054 
00055   WordData( const Generator& x ) : len(1), wrd(new GeneratorType[1]) {
00056          #if SAFETY > 0
00057       if ( ord(x) == 0 ) error("Tried to init Word with Generator of ord 0");
00058     #endif
00059          *wrd = ord(x);
00060   }
00061 
00062   WordData( const Generator& x, const Generator& y ) :
00063     len(2), wrd(new GeneratorType[2]) {
00064          #if SAFETY > 0
00065       if ( ord(x) == 0 || ord(y) == 0 )
00066                   error("Tried to init Word with Generator of ord 0");
00067     #endif
00068          wrd[0] = ord(x);
00069          wrd[1] = ord(y);
00070   }
00071 
00072   WordData( const VectorOf<Generator>& v ) {
00073          #if SAFETY > 0
00074            if ( v.length() > MAXLENGTH )
00075                   error("Tried to init a Word which is too long");
00076     #endif
00077          len = v.length();
00078          wrd = new GeneratorType[len];
00079          #if SAFETY > 0
00080       for (int i = 0; i < len; i++)
00081         if ( (wrd[i] = ord(v[i])) == 0 )
00082           error("Tried to init Word with Generator of ord 0");
00083     #else
00084            for (int i = 0; i < len; i++) wrd[i] = ord(v[i]);
00085     #endif
00086   }
00087 
00088   WordData( const ListOf<Generator>& l ) {
00089          #if SAFETY > 0
00090            if ( l.length() > MAXLENGTH )
00091                   error("Tried to init a Word which is too long");
00092     #endif
00093          len = l.length();
00094          wrd = new GeneratorType[len];
00095     ListIterator< ListOf<Generator> > it(l);
00096          #if SAFETY > 0
00097       for (int i = 0; i < len; i++) {
00098         if ( (wrd[i] = ord(it.value())) == 0 )
00099           error("Tried to init Word with Generator of ord 0");
00100                   it.next();
00101       }
00102     #else
00103            for (int i = 0; i < len; i++) {
00104         wrd[i] = ord(it.value());
00105         it.next();
00106       }
00107     #endif
00108   }
00109 
00110   WordData( const GeneratorType *p, int le ) {
00111          #if SAFETY > 0
00112            if ( le > MAXLENGTH )
00113                   error("Tried to init a Word which is too long");
00114     #endif
00115          len = le;
00116          wrd = new GeneratorType[le];
00117          #if SAFETY > 0
00118       for (int i = 0; i < le; i++)
00119         if ( (wrd[i] = *p++) == 0 )
00120           error("Tried to init Word with Generator of ord 0");
00121     #else
00122            for (int i = 0; i < le; i++) wrd[i] = *p++;
00123     #endif
00124   }
00125 
00126   
00127   // handles:
00128   
00129   int length( ) const { return len; }
00130   
00131   // for reference access
00132   GeneratorType& ref(int i) {
00133     #if ( SAFETY > 0 )
00134            if ( i < 0 || i >= len ) error("Word index out of bounds "
00135                         "in GeneratorType& WordData::ref(int)");
00136          #endif
00137          return wrd[i];
00138   }
00139   
00140   // for value access
00141   GeneratorType val(int i) const {
00142     #if ( SAFETY > 0 )
00143            if ( i < 0 || i >= len ) error("Word index out of bounds "
00144                         "in GeneratorType WordData::val(int)");
00145          #endif
00146          return wrd[i];
00147   }
00148   
00149   // for pointer and pseudo pointer manipulation
00150   GeneratorPtrType first( ) { return wrd; }
00151   cGeneratorPtrType cFirst( ) const { return wrd; }
00152   GeneratorPtrType last( ) { return wrd + len - 1; }
00153   cGeneratorPtrType cLast( ) const { return wrd + len - 1; }
00154   // for pseudo-p would have +, -, ++ and -- defined,
00155   // and a dereferencer operator*( )
00156 
00157 
00158 private:
00159 
00160   int len;
00161   static const int MAXLENGTH = 2000000000; // The biggest int which will fit in len.
00162   GeneratorType* wrd;
00163 
00164 
00165 //@@db temporary declaration.
00166 
00167   friend class WordRep;
00168 };
00169 
00170 #endif

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