Rheolef  7.1
an efficient C++ finite element environment
scatch.icc
Go to the documentation of this file.
1 #ifndef _RHEOLEF_SCATCH_ICC
2 #define _RHEOLEF_SCATCH_ICC
3 // utility included by rheostream.cc
24 // and shared by msh2geo.cc bamg2geo.cc and others utilities
25 // => avoid code redundancies
26 #include <iostream>
27 #include<sys/stat.h> // stat()
28 
29 namespace rheolef {
30 using namespace std;
31 
33 string
35 {
36  char buffer [100];
37  sprintf (buffer, "%d", int(i));
38  return buffer;
39 }
41 bool
42 file_exists (const string& filename)
43 {
44  struct stat s;
45  if (stat(filename.c_str(), &s) != 0) {
46  return false;
47  }
48  return true;
49 }
51 bool
52 scatch (istream& in, const string& ch, bool full_match)
53 {
54  // null string case
55  unsigned int l = ch.length();
56  if (l == 0) return true;
57 
58  // check file
59  char c = '\0';
60  unsigned int state = 0;
61  const char *p = ch.c_str();
62  do {
63  in.get(c);
64  if (*p == '\n') {
65  // begining of stream <==> begining of a line, e.g.
66  // we look at "\nfield" while file starts
67  // with string "field"; it's ok
68  state++;
69  p++;
70  }
71  do {
72 
73  if (*p == c) {
74  // advance in the string
75  state++;
76  p++;
77  } else if (state != 0 && ch[0] == c) {
78  // come back to the second position
79  state = 1;
80  p = ch.c_str() + 1;
81  } else if (state != 0) {
82  // come back to the begining of the string
83  state = 0;
84  p = ch.c_str();
85  }
86  }
87  while (state < l && in.get(c) && in.good());
88  // here: either state == l or end-of-file is reached
89  if (!full_match) return (state == l);
90  if (state != l) return false; // reaches end-of-file whithout finding the string
91  // here: state == l and we want a full match: check also that next char is a space, tab, end-of-line, or end-of-file
92  // => otherwise ambiguity with scatch("u") that reaches either "uh" or "u_exact"...!
93  c = in.peek();
94  if (!c || !in.good()) return true; // end-of-file just after the string: ok...
95  if (isspace(c)) return true; // nice! the expected situation
96  } while (true);
97  // stops when reaching either the string or end-of-file: the next statement is not reached
98  return false;
99 }
100 
101 }// namespace rheolef
102 #endif // _RHEOLEF_SCATCH_ICC
rheolef::file_exists
bool file_exists(const std::string &filename)
file_exists: see the rheostream page for the full documentation
Definition: scatch.icc:42
mkgeo_ball.c
c
Definition: mkgeo_ball.sh:153
p
Definition: sphere.icc:25
rheolef::scatch
bool scatch(std::istream &in, const std::string &ch, bool full_match=true)
scatch: see the rheostream page for the full documentation
Definition: scatch.icc:52
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
size_type
field::size_type size_type
Definition: branch.cc:425
rheolef::itos
std::string itos(std::string::size_type i)
itos: see the rheostream page for the full documentation