proj home

Files   Classes   Functions   Hierarchy  

print.h

Go to the documentation of this file.
00001 #ifndef PRINT_H
00002 #define PRINT_H
00003 
00004 #include <cassert>
00005 #include <iostream>
00006 using namespace std;
00007 
00008 #include <typedefs.h>
00009 
00032 template< typename Iter >
00033 class printcontainer
00034 {
00035 public:
00036 
00038   Iter ibeg;
00040   Iter iend;
00041 
00043   string space;
00044 
00046   printcontainer
00047   (
00048     Iter ibeg_,
00049     Iter iend_,
00050     stringc & space_=" "
00051   )
00052     : ibeg(ibeg_), iend(iend_), space(space_) {}
00053 
00055   ostream & print(ostream & os) const;
00056 };
00057 
00059 template< typename T >
00060 printcontainer< typename T::const_iterator > 
00061   print( T const & data, stringc & space=" " )
00062   { return typename printcontainer< typename T::const_iterator >::printcontainer(data.begin(),data.end(),space); }
00063 
00065 template< typename Iter >
00066 printcontainer< Iter >
00067   print( Iter ibeg, Iter iend, stringc & space=" " )
00068   { return typename printcontainer< Iter >::printcontainer(ibeg,iend,space); }
00069 
00072 template< typename T >
00073 ostream & operator << (ostream & os, printcontainer<T> const & x )
00074   { return x.print(os); }
00075 
00076 template< typename Iter >
00077 printcontainer< Iter > printvecfunc
00078 ( 
00079   Iter ibeg, 
00080   long unsigned int const N,
00081   stringc & space=" " 
00082 )
00083 {
00084   return print(ibeg,ibeg+N,space);
00085 }
00086 
00087 //----------------------------------------------------------
00088 // Implementation
00089 
00090 
00091 template< typename Iter >
00092 ostream & printcontainer<Iter>::print(ostream & os) const
00093 {
00094   Iter i=ibeg;
00095   if (i!=iend)
00096     os << *i++;
00097   for ( ; i!=iend; )
00098     os << space << *i++;
00099 
00100   return os;
00101 }
00102 
00103 
00104 #endif
00105 

Generated on Fri Mar 4 00:49:29 2011 for Chelton Evans Source by  doxygen 1.5.8