1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
/*****************************************************************************\
* Filename : projectio.hh
* Author : Emmanouil Stafilarakis
* Project : HMM
* Version : 0.1
*
* Copyright: ©Stafilarakis
*
* Description: Some manipulators for streams.
*
*
* Date | Author | Changes
*------------|-----------------------|----------------------------------------
* 11.09.2001 | Stafilarakis Emm. | Creation of the file
* 03.09.2002 | Mario Stanke | change line length to 8192 (before 256)
\******************************************************************************/
#ifndef _PROJECTIO_HH
#define _PROJECTIO_HH
// standard C/C++ includes
#include <istream>
#include <fstream>
#include <sstream>
#include <vector>
#include <cstring>
#define MAX_ROW_LEN 8192
using namespace std;
/*
* This function should not be used directly, use the function
* defined below ('imanip<char> comment( char c )') instead!!
*/
inline istream& comment_c( istream& strm, char c ){
char buff[MAX_ROW_LEN];
while( (strm >> ws) && (strm.peek() == c) ){
strm.getline( buff, MAX_ROW_LEN );
}
return strm;
}
/*
* istream& comment( istream& strm )
*--------------------------------------------------------------
* This function removes all comment lines from a stream until
* a line which not begins with a comment sign '#'.
* USAGE:
* istrm >> comment >> ... ;
*/
inline istream& comment(istream& strm ){
return comment_c( strm, '#' );
}
inline stringstream& find_line_after (stringstream& strm, const char* str ){
char buff[MAX_ROW_LEN];
do{
strm >> ws;
strm.getline( buff, MAX_ROW_LEN-1 );
if ( strncmp( buff, str, strlen(str) ) == 0 )
return strm;
} while( strm );
strm.clear( ios::failbit );
return strm;
}
inline istream& find_line_after (istream& strm, const char* str ){
char buff[MAX_ROW_LEN];
do{
strm >> ws;
strm.getline( buff, MAX_ROW_LEN-1 );
if ( strncmp( buff, str, strlen(str) ) == 0 )
return strm;
} while( strm );
strm.clear( ios::failbit );
return strm;
}
struct Goto_line_after { const char *keyword; };
inline Goto_line_after goto_line_after(const char *str){
Goto_line_after gla;
gla.keyword = str;
return gla;
}
stringstream& operator>>(stringstream& is, Goto_line_after gla);
istream& operator>>(istream& is, Goto_line_after gla);
template <class T>
ostream &operator<<(ostream &output, const vector<T> &v) {
output << "[";
if (v.size()>0) {
output << v[0];
for(int i=1; i<v.size(); i++) {
output << " , " << v[i];
}
}
output << "]" << endl;
return output;
}
#endif // _PROJECTIO_HH
|