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

/magnus/back_end/general/include/conversions.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: conversions.h,v 1.4 1997/07/18 21:29:16 bormotov Exp $
00003  */
00004 
00005 // Copyright (C) 1995 The New York Group Theory Cooperative
00006 // See magnus/doc/COPYRIGHT for the full notice.
00007 
00008 // Contents: Global template functions for converting between
00009 //           container classes.
00010 //
00011 // Principal Author: Roger Needham
00012 //
00013 // Status: Useable.
00014 //
00015 // Revision History:
00016 //
00017 // * 96/10/28 @dp fixed `makeListOf<T>( const SetOf<T>& )'.
00018 //
00019 // Discussion:
00020 //
00021 // * We use global functions to both break circular dependence, and to
00022 //   avoid clashes between different requirements on the element types
00023 //   of the various container classes.
00024 //
00025 // * The functions are inlined to work around the lack of template
00026 //   repositories in gcc 2.6.3.
00027 //
00028 // Further implementation steps:
00029 //
00030 // * The other conversions.
00031 
00032 
00033 #ifndef _CONVERSIONS_H_
00034 #define _CONVERSIONS_H_
00035 
00036 
00037 #include "List.h"
00038 #include "Set.h"
00039 #include "Vector.h"
00040 
00041 
00042 template <class T> VectorOf<T> makeVectorOf(const ListOf<T>& L)
00043 {
00044   VectorOf<T> result( L.length() );
00045 
00046   int i = 0;
00047   ListIterator< ListOf<T> > I(L);
00048 
00049   while ( !I.done() ) {
00050     result[i++] = I.value();
00051     I.next();
00052   }
00053 
00054   return result;
00055 }
00056 
00057 
00058 template <class T> VectorOf<T> makeVectorOf(const SetOf<T>& S)
00059 {
00060   VectorOf<T> result( S.cardinality() );
00061 
00062   int ii = 0;
00063   SetIterator<T> I(S);
00064 
00065   while ( !I.done() ) {
00066     result[ii++] = I.value();
00067     I.next();
00068   }
00069 
00070   return result;
00071 }
00072 
00073 
00074 template <class T> SetOf<T> makeSetOf(const VectorOf<T>& V)
00075 {
00076   int ii = V.length();
00077 
00078   SetOf<T> result( ii );
00079 
00080   while( --ii >= 0 ) result.adjoinElement( V[ii] );
00081 
00082   return result;
00083 }
00084 
00085 
00086 template <class T> SetOf<T> makeSetOf(const ListOf<T>& L)
00087 {
00088   SetOf<T> result( L.length() );
00089 
00090   ListIterator< ListOf<T> > I( L );
00091 
00092   while ( !I.done() ) {
00093     result.adjoinElement( I.value() );
00094     I.next();
00095   }
00096 
00097   return result;
00098 }
00099 
00100 
00101 template <class T> ListOf<T> makeListOf(const VectorOf<T>& V)
00102 {
00103   ListOf<T> result;
00104 
00105   int i = V.length();
00106 
00107   while ( --i >= 0 ) result.prepend( V[i] );
00108 
00109   return result;
00110 }
00111 
00112 
00113 template <class T> ListOf<T> makeListOf(const SetOf<T>& S)
00114 {
00115   ListOf<T> result;
00116 
00117   SetIterator<T> I(S);
00118 
00119   while ( !I.done() ) {
00120     result.append( I.value() );
00121     I.next();
00122   }
00123 
00124   return result;
00125 }
00126 
00127 #endif

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