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

abkio.h

Go to the documentation of this file.
00001 /**************************************************************************
00002 ***    
00003 *** Copyright (c) 1995-2000 Regents of the University of California,
00004 ***               Andrew E. Caldwell, Andrew B. Kahng and Igor L. Markov
00005 *** Copyright (c) 2000-2004 Regents of the University of Michigan,
00006 ***               Saurabh N. Adya, Jarrod A. Roy and Igor L. Markov
00007 ***
00008 ***  Contact author(s): abk@cs.ucsd.edu, imarkov@umich.edu
00009 ***  Original Affiliation:   UCLA, Computer Science Department,
00010 ***                          Los Angeles, CA 90095-1596 USA
00011 ***
00012 ***  Permission is hereby granted, free of charge, to any person obtaining 
00013 ***  a copy of this software and associated documentation files (the
00014 ***  "Software"), to deal in the Software without restriction, including
00015 ***  without limitation 
00016 ***  the rights to use, copy, modify, merge, publish, distribute, sublicense, 
00017 ***  and/or sell copies of the Software, and to permit persons to whom the 
00018 ***  Software is furnished to do so, subject to the following conditions:
00019 ***
00020 ***  The above copyright notice and this permission notice shall be included
00021 ***  in all copies or substantial portions of the Software.
00022 ***
00023 *** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
00024 *** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00025 *** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
00026 *** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00027 *** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
00028 *** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
00029 *** THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00030 ***
00031 ***
00032 ***************************************************************************/
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00046 
00047 /* This file to be included into all projects in the group
00048 
00049  CHANGES
00050   970827 ilm  added arrangements for the needword(const char *) manipulator
00051         ilm  uninlined manipulators
00052   980213 ilm  renamed into abkio.h
00053          ilm  added printRange()
00054   980320 ilm  added optional lineNo arguments to asserting input manipulators
00055 */
00056 
00057 #ifndef  _ABKIO_H_
00058 #define  _ABKIO_H_
00059 #include <iostream>
00060 #include <iomanip>
00061 //#include <ctype.h>
00062 #include <stdio.h>
00063 #include <string.h>
00064 #include <vector>
00065 #include "abkassert.h"
00066 
00067 using std::istream;
00068 using std::ostream;
00069 using std::setw;
00070 using std::flush;
00071 using std::endl;
00072 using std::cin;
00073 using std::cout;
00074 using std::cerr;
00075 
00076 istream& eatblank(istream& i);
00077 istream& skiptoeol(istream& i);
00078 
00079 /*istream& eathash (istream\& i);
00080  istream& needeol (istream\& i);
00081 istream& noeol   (istream\& i);
00082 istream& isnumber(istream\& i);
00083 istream& isword(istream\& i);
00084 */
00085 //: Function template for the manipulators in istream and ostream
00086 template<class Arg>
00087 class ManipFuncObj1
00088 {
00089     istream& (*_func) (istream&, Arg);
00090     Arg _arg;
00091 public:
00092     ManipFuncObj1(istream& (*f) (istream&,Arg), Arg arg):_func(f),_arg(arg) {}
00093     istream& operator()(istream& i) const { return (*_func)(i,_arg) ; }
00094 };
00095 
00096 template<class Arg>
00097 istream& operator>>(istream& is, const ManipFuncObj1<Arg>& im)
00098 { return im(is); }
00099 
00100 template<class Arg1,class Arg2>
00101 class ManipFuncObj2
00102 {
00103     istream& (*_func) (istream&, Arg1, Arg2);
00104     Arg1 _arg1;
00105     Arg2 _arg2;
00106 public:
00107     ManipFuncObj2(istream& (*f) (istream&, Arg1, Arg2), Arg1 arg1, Arg2 arg2)
00108          :_func(f),_arg1(arg1),_arg2(arg2) {}
00109     istream& operator()(istream& i) const { return (*_func)(i,_arg1,_arg2) ; }
00110 };
00111 
00112 template<class Arg1, class Arg2>
00113 istream& operator>>(istream& is, const ManipFuncObj2<Arg1,Arg2>& im)
00114 { return im(is); }
00115 
00116 ManipFuncObj1<int&> eathash  (int& lineNo);
00117 ManipFuncObj1<int> needeol  (int lineNo=-1);
00118 ManipFuncObj1<int> noeol    (int lineNo=-1);
00119 //for 64-bit. isnumber is a system function. replace with my_isnumber()
00120 ManipFuncObj1<int> my_isnumber (int lineNo=-1);
00121 ManipFuncObj1<int> isword   (int lineNo=-1);
00122 
00123 ManipFuncObj2<const char *, int> needword(const char * word, int lineNo=-1);
00124 ManipFuncObj2<const char *, int> needcaseword(const char * word, int lineNo=-1);
00125 
00126 template<class T>
00127 inline
00128 ostream& operator<<(ostream& out, const std::vector<T>& rhs)
00129 {
00130         unsigned size=rhs.size();
00131         for (unsigned i=0; i!=size; ++i)
00132         {
00133                 if ( i % 10 == 0 )
00134                 {
00135                     if (i) out << endl;
00136                     out<<"     ";
00137                 }
00138                 out<<setw(6)<<rhs[i]<<" ";
00139         }
00140         out<<"\n";
00141         return out;
00142 }
00143 
00144 
00145 template<class Iter>
00146 inline
00147 unsigned printRange(ostream& out, Iter first, Iter last)
00148 {
00149     unsigned count=0;
00150     for (;first!=last; first++, count++)
00151     {
00152         if (count % 10 == 0)
00153         {
00154             if (count)
00155                 out<<'\n';
00156             out<<"     ";
00157         }
00158         out<<setw(6)<<*first<<' ';
00159     }
00160     out<<'\n';
00161     return count;
00162 }
00163 
00164 
00165 #endif 

Generated on Mon Apr 25 01:09:23 2005 for Parquete by doxygen 1.3.2