dune-grid  2.7.1
basic.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_DGF_BASICBLOCK_HH
4 #define DUNE_DGF_BASICBLOCK_HH
5 
6 #include <cassert>
7 #include <cctype>
8 #include <iostream>
9 #include <string>
10 #include <sstream>
11 
12 #include <dune/common/stdstreams.hh>
15 
16 namespace Dune
17 {
18 
19  namespace dgf
20  {
21 
22  inline void makeupcase( std :: string &s )
23  {
24  for (size_t i=0; i<s.size(); i++)
25  s[i]=std::toupper(s[i]);
26  }
27 
28  class BasicBlock
29  {
30  int pos; // line number
31  bool active; // block was found
32  bool empty; // block was found but was empty
33  std::string identifier; // identifier of this block
34  int linecount; // total number of lines in the block
35  std::stringstream block_; // the block itself
36  std::string oneline; // the active line in the block
37 
38  // get the block (if it exists)
39  void getblock ( std::istream &in );
40 
41  // count the number of lines in the block
42  // int countlines ();
43 
44  protected:
45  std::stringstream line; // the active line as string buffer
46  // for use in the derived classes
47 
48  // go back to beginning of block
49  void reset ()
50  {
51  pos = -1;
52  block_.clear();
53  block_.seekg( 0 );
54  }
55 
56  // get next line and store in string stream
57  bool getnextline ();
58 
59  // get next entry in line
60  template< class ENTRY >
61  bool getnextentry( ENTRY &entry )
62  {
63  line >> entry;
64  return static_cast< bool >( line );
65  }
66 
67  bool gettokenparam ( std :: string token, std :: string &entry );
68  bool findtoken( std :: string token );
69 
70  public:
71  // search for block in file and store in buffer
72  BasicBlock ( std::istream &in, const char* id );
73 
74  // some information on this block
75  bool isactive ()
76  {
77  return active;
78  }
79 
80  bool isempty ()
81  {
82  return empty;
83  }
84 
85  int &noflines ()
86  {
87  return linecount;
88  }
89 
90  int linenumber ()
91  {
92  return pos;
93  }
94 
95  const std::string & id () const
96  {
97  return identifier;
98  }
99 
100  // for error messages
101  friend std :: ostream &operator<< ( std :: ostream &os, const BasicBlock &b )
102  {
103  return os << "block " << b.identifier << " (line " << b.pos << ")";
104  }
105 
106  };
107 
108  } // end namespace dgf
109 
110 } // end namespace Dune
111 
112 #endif
Include standard header files.
Definition: agrid.hh:59
void makeupcase(std ::string &s)
Definition: basic.hh:22
Definition: basic.hh:29
void reset()
Definition: basic.hh:49
bool getnextline()
Definition: basic.cc:92
BasicBlock(std::istream &in, const char *id)
Definition: basic.cc:16
bool findtoken(std ::string token)
Definition: basic.cc:121
int & noflines()
Definition: basic.hh:85
const std::string & id() const
Definition: basic.hh:95
bool getnextentry(ENTRY &entry)
Definition: basic.hh:61
friend std ::ostream & operator<<(std ::ostream &os, const BasicBlock &b)
Definition: basic.hh:101
bool isempty()
Definition: basic.hh:80
bool isactive()
Definition: basic.hh:75
int linenumber()
Definition: basic.hh:90
std::stringstream line
Definition: basic.hh:45
bool gettokenparam(std ::string token, std ::string &entry)
Definition: basic.cc:102