dune-grid  2.2.0
basic.hh
Go to the documentation of this file.
00001 #ifndef DUNE_DGF_BASICBLOCK_HH
00002 #define DUNE_DGF_BASICBLOCK_HH
00003 
00004 #include <cassert>
00005 #include <iostream>
00006 #include <string>
00007 #include <sstream>
00008 
00009 #include <dune/common/stdstreams.hh>
00010 #include <dune/grid/io/file/dgfparser/entitykey.hh>
00011 #include <dune/grid/io/file/dgfparser/dgfexception.hh>
00012 
00013 namespace Dune
00014 {
00015 
00016   namespace dgf
00017   {
00018 
00019     inline void makeupcase( std :: string &s )
00020     {
00021       for (size_t i=0;i<s.size();i++)
00022         s[i]=toupper(s[i]);
00023     }
00024 
00025     class BasicBlock
00026     {
00027       int pos;                   // line number
00028       bool active;               // block was found
00029       bool empty;                // block was found but was empty
00030       std::string identifier;    // identifier of this block
00031       int linecount;             // total number of lines in the block
00032       std::stringstream block;   // the block itself
00033       std::string oneline;       // the active line in the block
00034 
00035       // get the block (if it exists)
00036       void getblock ( std::istream &in );
00037 
00038       // count the number of lines in the block
00039       // int countlines ();
00040 
00041     protected:
00042       std::stringstream line; // the active line as string buffer 
00043                               // for use in the derived classes
00044 
00045       // go back to beginning of block
00046       void reset ()
00047       {
00048         pos = -1;
00049         block.clear();
00050         block.seekg( 0 );
00051       }
00052 
00053       // get next line and store in string stream
00054       bool getnextline ();
00055 
00056       // get next entry in line
00057       template< class ENTRY >
00058       bool getnextentry( ENTRY &entry )
00059       {
00060         line >> entry;
00061         return line;
00062       }
00063 
00064       bool gettokenparam ( std :: string token, std :: string &entry );
00065       bool findtoken( std :: string token );
00066 
00067     public:
00068       // search for block in file and store in buffer
00069       BasicBlock ( std::istream &in, const char* id );
00070 
00071       // some information on this block
00072       bool isactive ()
00073       {
00074         return active;
00075       }
00076 
00077       bool isempty ()
00078       {
00079         return empty;
00080       }
00081 
00082       int &noflines ()
00083       {
00084         return linecount;
00085       }
00086 
00087       int linenumber ()
00088       {
00089         return pos;
00090       }
00091 
00092       const std::string & id () const
00093       {
00094         return identifier;
00095       }
00096 
00097       // for error messages
00098       friend std :: ostream &operator<< ( std :: ostream &os, const BasicBlock &b )
00099       {
00100         return os << "block " << b.identifier << " (line " << b.pos << ")";
00101       }
00102 
00103     };
00104 
00105   } // end namespace dgf
00106 
00107 } // end namespace Dune
00108 
00109 #endif
00110