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