AMROC Main     Blockstructured Adaptive Mesh Refinement in object-oriented C++


Main Page   Class Hierarchy   Compound List   File List  

skip-comments.h

Go to the documentation of this file.
00001 #ifndef NMWR_GB_SKIP_COMMENTS_H
00002 #define NMWR_GB_SKIP_COMMENTS_H
00003 
00004 
00011 #include <iostream.h>
00012 #include <limits.h>
00013 #include "string_CompConf.h"
00014 
00015 class skip_comments_istream {
00016 public:
00017   skip_comments_istream(istream& in, 
00018                         char comment_begin = '#',
00019                         char comment_end   = '\n') 
00020     : in_(&in),
00021       comment_begin_(comment_begin), 
00022       comment_end_(comment_end) {}
00023  
00024   istream& the_istream() { return skip_comments(*in_);} 
00025   char begin_comment() const {return comment_begin_;}
00026 
00027   istream& skip_comments(istream& in) 
00028   {
00029     while(true) {
00030       in >> ws;
00031       if (in.peek() != comment_begin_)
00032         break;
00033       in.get();
00034       in.ignore(INT_MAX,comment_end_);
00035     }
00036     return in;
00037   } 
00038 
00039 private:
00040  istream* in_;
00041   char comment_begin_, comment_end_;
00042 };
00043 
00044 inline istream& skip_comment(istream& in) {
00045   if(in) {
00046     skip_comments_istream sk(in);
00047     sk.skip_comments(in);
00048   }
00049   return in;
00050 }
00051 
00052 inline skip_comments_istream& operator>>(skip_comments_istream& in, string& s)
00053 {
00054   istream& in1(in.the_istream());
00055   int max_len = 256;
00056   char* ss = new char[max_len];
00057   // string ss = "";
00058   int i = 0;
00059   char c = 'a';
00060   while(in1 && i < max_len-1 && (c != in.begin_comment()) && ! isspace(c)) {
00061     c = in1.get();
00062     ss[i] = c;
00063     i++;
00064   };
00065   
00066   if(c == in.begin_comment() || isspace(c)) {
00067     if(in1)
00068       in1.putback(c);
00069     i--;
00070   }
00071 
00072    ss[i] = '\0';
00073   s = ss;
00074   return in;
00075 }
00076 
00077 
00078 template<class T>
00079 inline skip_comments_istream& operator>>(skip_comments_istream& in, T& t)
00080 { 
00081   in.the_istream() >> t;
00082   return in;
00083 }
00084 
00085 
00086 
00087 
00088 #endif


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



AMROC Main      Home      Contact
last update: 06/01/04