Augustus 3.4.0
Loading...
Searching...
No Matches
projectio.hh
1/*
2 * projectio.hh
3 *
4 * License: Artistic License, see file LICENSE.TXT or
5 * https://opensource.org/licenses/artistic-license-1.0
6 *
7 * Description: Some manipulators for streams.
8 */
9
10#ifndef _PROJECTIO_HH
11#define _PROJECTIO_HH
12
13// standard C/C++ includes
14#include <istream>
15#include <fstream>
16#include <sstream>
17#include <vector>
18#include <cstring>
19
20
21#define MAX_ROW_LEN 8192
22using namespace std;
23
24/*
25 * This function should not be used directly, use the function
26 * defined below ('imanip<char> comment( char c )') instead!!
27 */
28inline istream& comment_c( istream& strm, char c ){
29 char buff[MAX_ROW_LEN];
30 while( (strm >> ws) && (strm.peek() == c) ){
31 strm.getline( buff, MAX_ROW_LEN );
32 }
33 return strm;
34}
35
36
37/*
38 * istream& comment( istream& strm )
39 *--------------------------------------------------------------
40 * This function removes all comment lines from a stream until
41 * a line which not begins with a comment sign '#'.
42 * USAGE:
43 * istrm >> comment >> ... ;
44 */
45inline istream& comment(istream& strm ){
46 return comment_c( strm, '#' );
47}
48
49inline stringstream& find_line_after (stringstream& strm, const char* str ){
50 char buff[MAX_ROW_LEN];
51 do{
52 strm >> ws;
53 strm.getline( buff, MAX_ROW_LEN-1 );
54 if ( strncmp( buff, str, strlen(str) ) == 0 )
55 return strm;
56 } while( strm );
57 strm.clear( ios::failbit );
58 return strm;
59}
60
61inline istream& find_line_after (istream& strm, const char* str ){
62 char buff[MAX_ROW_LEN];
63 do{
64 strm >> ws;
65 strm.getline( buff, MAX_ROW_LEN-1 );
66 if ( strncmp( buff, str, strlen(str) ) == 0 )
67 return strm;
68 } while( strm );
69 strm.clear( ios::failbit );
70 return strm;
71}
72
73struct Goto_line_after { const char *keyword; };
74inline Goto_line_after goto_line_after(const char *str){
76 gla.keyword = str;
77 return gla;
78}
79
80stringstream& operator>>(stringstream& is, Goto_line_after gla);
81
82istream& operator>>(istream& is, Goto_line_after gla);
83
84
85template <class T>
86ostream &operator<<(ostream &output, const vector<T> &v) {
87 output << "[";
88 if (v.size()>0) {
89 output << v[0];
90 for(int i=1; i<v.size(); i++) {
91 output << " , " << v[i];
92 }
93 }
94 output << "]" << endl;
95 return output;
96}
97
98
99#endif // _PROJECTIO_HH
Definition projectio.hh:73