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

/magnus/back_end/Elt/include/Generator.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: Generator.h,v 1.4 1997/04/15 22:28:15 alex 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 the Generator class.
00009 //
00010 //      Should be considered part of the implementation of class Word
00011 //      and similar classes. Serves as an interface class for these.
00012 //  A Generator is something with an ordinal and an inverse, and
00013 //  can be compared with other ordinals.
00014 //
00015 // Principal Author: Stephane Collart
00016 //
00017 // Status: Useable.
00018 //
00019 // Questions to consider:
00020 //
00021 // * should Generator have a cast operator to Elt?
00022 //
00023 // Revision History:
00024 //
00025 // * 95/07 @dp added method  int hash() const;
00026 //
00027 // * 01/96 Dmitry B. implemented IPC tools.
00028 //
00029 // * 11/96 EP added new global functions: power, abs, shortLexIndex
00030 
00031 #ifndef _GENERATOR_H_
00032 #define _GENERATOR_H_
00033 
00034 
00035 class Generator {
00036 
00037 public:
00038   
00039   // copy constructor compiler-supplied
00040   // destructor compiler-supplied
00041   // assignment operator compiler-supplied
00042 
00043   Generator( ) : genrep(0) { }
00044   // A default constructor for making, e.g., arrays of uninitialized
00045   // Generators. With SAFETY > 0, the Word constructor which takes arrays of
00046   // Generators checks for uninitialized ones.
00047 
00048   Generator( int i ) : genrep(i) {
00049          #if SAFETY > 0
00050       if ( i == 0 ) error("initialization of Generator with ord 0");
00051          #endif
00052   }
00053   // @rn Is it worthwhile to refuse negative args, thus forcing the use
00054   // of inv?
00055 
00056   // Generator has no non-static members in its public interface
00057   // in order to have the use of a Genref wherever a Generator is expected
00058   // (the compiler would not understand g.member() if g were a Genref
00059   // and member() in Generator).
00060     
00061   inline friend int ord( Generator g ) { return g.genrep; }
00062   // this is the only friend; all other functions in the public interface
00063   // of Generator are defined in terms of ord()
00064 
00065   int hash() const { return genrep; }
00066 
00067 
00068   /////////////////////////////////////////////////////////////////////////
00069   //                                                                     //
00070   // IPC tools:                                                          //
00071   //                                                                     //
00072   /////////////////////////////////////////////////////////////////////////
00073 
00074   friend ostream& operator < ( ostream& ostr, const Generator& g )
00075   {
00076     ostr < g.genrep;
00077     return ostr;
00078   }
00079   
00080   friend istream& operator > ( istream& istr, Generator& g )
00081   {
00082     istr > g.genrep;
00083     return istr;
00084   }
00085 
00086 
00087 private:
00088   
00089   // data members
00090 
00091   int genrep;
00092 
00093   /*@stc
00094         // alternative implementation:
00095 
00096         class GenData { protected: int genrep; }
00097         class Generator : private GenData {
00098         // ...
00099         private:
00100                 // only Word or other classes using Generator should see the cast to int
00101                 friend class Word;
00102                 operator int( ) const { return ord(*this); }
00103         }
00104 
00105         // this would make it possible to implicitly use a generator as an
00106         // int in Word. Pushing genrep up into GenData is necessary so Word
00107         // doesn't see it.
00108   */
00109 
00110 };
00111 
00112 
00113 // functions for manipulating Generators
00114 
00115 // the notion of inverse:
00116 
00117 inline Generator inv( Generator g ) { return Generator(-ord(g)); }
00118 
00119 // comparators:
00120 
00121 inline int operator == ( Generator g, Generator h ) { return ord(g) == ord(h); }
00122 
00123 inline int operator != ( Generator g, Generator h ) { return ord(g) != ord(h); }
00124 
00125 inline int operator < ( Generator g, Generator h ) { return ord(g) < ord(h); }
00126 
00127 inline int operator <= ( Generator g, Generator h ) { return ord(g) <= ord(h); }
00128 
00129 inline int operator > ( Generator g, Generator h ) { return ord(g) > ord(h); }
00130 
00131 inline int operator >= ( Generator g, Generator h ) { return ord(g) >= ord(h); }
00132 
00133 // I/O
00134 
00135 inline ostream& operator << ( ostream& ostr, Generator g ) {
00136         ostr << ord(g);
00137         return ostr;
00138 }
00139 
00140 // Generator properties
00141 
00142 inline int power(Generator g) {
00143         return ( ord(g) < 0 ) ? -1 : 1;
00144 }
00145 
00146 inline int abs(Generator g) {
00147         int v = ord(g);
00148         return ( v < 0) ? -v : v;
00149 }
00150 // The absolute value of generator representation
00151 
00152 inline int shortLexIndex(Generator g) {
00153   int i = ord(g);
00154         return (i > 0 ) ? 2*(i-1) : -2*i - 1;
00155 }
00156 // Return the generator's index in ShortLex ordering:
00157 //   1  -> 0
00158 //  -1  -> 1
00159 //   2  -> 2
00160 //  -2  -> 3
00161 //  ........
00162 
00163 #endif

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