DUNE PDELab (git)

basic.hh
1// SPDX-FileCopyrightText: Copyright © 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
15#include <dune/grid/io/file/dgfparser/entitykey.hh>
16#include <dune/grid/io/file/dgfparser/dgfexception.hh>
17
18namespace 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
constexpr GeometryType line
GeometryType representing a line.
Definition: type.hh:498
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::bool_constant<(sizeof...(II)==0)> empty(std::integer_sequence< T, II... >)
Checks whether the sequence is empty.
Definition: integersequence.hh:80
Standard Dune debug streams.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)