/usr/include/getfem/bgeot_ftool.h is in libgetfem++-dev 4.2.1~beta1~svn4635~dfsg-3+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | /* -*- c++ -*- (enables emacs c++ mode) */
/*===========================================================================
Copyright (C) 2000-2012 Yves Renard
This file is a part of GETFEM++
Getfem++ is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version along with the GCC Runtime Library
Exception either version 3.1 or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License and GCC Runtime Library Exception for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
As a special exception, you may use this file as it is a part of a free
software library without restriction. Specifically, if other files
instantiate templates or use macros or inline functions from this file,
or you compile this file and link it with other files to produce an
executable, this file does not by itself cause the resulting executable
to be covered by the GNU Lesser General Public License. This exception
does not however invalidate any other reasons why the executable file
might be covered by the GNU Lesser General Public License.
===========================================================================*/
/**@file bgeot_ftool.h
@author Yves Renard <Yves.Renard@insa-lyon.fr>
@date March 09, 2000.
@brief "File Tools"
*/
#ifndef BGEOT_FTOOL_H
#define BGEOT_FTOOL_H
#include <iostream>
#include <map>
#include <vector>
namespace bgeot
{
/* ********************************************************************* */
/* Read a char string. */
/* ********************************************************************* */
bool read_until(std::istream &ist, const char *st);
/** Very simple lexical analysis of general interest for reading small
* langages with a "MATLAB like" syntax :
* spaces are ignored, '%' indicates a commentary until the end of the line,
* '...' indicates that the instruction continue on the next line
* (or separate two sub part of the same character string).
*
* The function returns
* 0 if there is nothing else to read in the file
* 1 if an end line has been found (st is empty in this case)
* 2 if a number as been read
* 3 if a string has been read
* 4 if a alphanumeric name has been read
* 5 for a one character symbol
* 6 for a two characters symbol (<=, >=, ==, !=, &&, ||)
*
* Note that when the end of line is not significant the option ignore_cr
* allows to consider the carriage return as a space character.
*/
int get_token(std::istream &ist, std::string &st,
bool ignore_cr = true, bool to_up = true,
bool read_un_pm = true, int *linenb = 0);
struct skip {
const char *s;
skip(const char *s_) : s(s_) {}
};
std::istream& operator>>(std::istream& is, const skip& t);
/* ********************************************************************* */
/* Case-insensitive string operations */
/* ********************************************************************* */
int casecmp(const char *a, const char *b, unsigned n=unsigned(-1));
inline int casecmp(const std::string& a, const char *b,
unsigned n=unsigned(-1))
{ return casecmp(a.c_str(),b,n); }
inline int casecmp(const std::string& a, const std::string& b,
unsigned n=unsigned(-1))
{ return casecmp(a.c_str(), b.c_str(),n); }
inline int casecmp(char a, char b)
{ return toupper(a)<toupper(b) ? -1 : (toupper(a) == toupper(b) ? 0 : +1); }
/* ********************************************************************* */
/* Read a parameter file. */
/* ********************************************************************* */
// The associated langage has approximatively the following grammar:
//
// 'instruction' := 'parameter_name' '=' 'expression';
// or 'if' 'expression'
// 'instruction_list'
// [ 'else' 'instruction_list' ]
// 'end'
// 'expression' := '[' 'expression' ',' ... ']'
// or 'parameter_name'
// or 'numeric_value'
// or 'character_string'
// or '(' 'expression' ')'
// or '+' 'expression'
// or '-' 'expression'
// or '!' 'expression'
// or 'expression' '+' 'expression'
// or 'expression' '-' 'expression'
// or 'expression' '*' 'expression'
// or 'expression' '/' 'expression'
// or 'expression' '||' 'expression'
// or 'expression' '&&' 'expression'
// or 'expression' '==' 'expression'
// or 'expression' '!=' 'expression'
// or 'expression' '<' 'expression'
// or 'expression' '>' 'expression'
// or 'expression' '<=' 'expression'
// or 'expression' '>=' 'expression'
class md_param {
public :
typedef enum { REAL_VALUE, STRING_VALUE, ARRAY_VALUE } param_type;
class param_value {
param_type pt;
double real_value;
std::string string_value;
std::vector<param_value> array_value;
public :
param_type type_of_param(void) const { return pt; }
double &real(void) { return real_value; }
double real(void) const { return real_value; }
std::string &string(void) { return string_value; }
const std::string &string(void) const { return string_value; }
std::vector<param_value> &array(void) { return array_value; }
const std::vector<param_value> &array(void) const { return array_value; }
param_value(double e = 0.0) : pt(REAL_VALUE), real_value(e) {}
param_value(std::string s) : pt(STRING_VALUE), real_value(0.0),
string_value(s) {}
param_value(char *s) : pt(STRING_VALUE), real_value(0.0),
string_value(s) {}
param_value(param_type p): pt(p), real_value(0.0) {}
};
protected :
std::map<std::string, param_value> parameters;
bool token_is_valid;
int current_line;
std::string current_file;
int get_next_token(std::istream &f);
void valid_token(void);
std::string temp_string;
param_value read_expression_list(std::istream &f, bool skipped);
param_value read_expression(std::istream &f, bool skipped);
int read_instruction_list(std::istream &f, bool sk = false);
int read_instruction(std::istream &f, bool sk = false);
void parse_error(const std::string &t);
void syntax_error(const std::string &t);
void do_bin_op(std::vector<md_param::param_value> &value_list,
std::vector<int> &op_list, std::vector<int> &prior_list);
public :
double real_value(const std::string &name, const char *comment = 0);
long int_value(const std::string &name, const char *comment = 0);
const std::string &string_value(const std::string &name,
const char *comment = 0);
const std::vector<param_value> &array_value(const std::string &name,
const char *comment = 0);
void add_int_param(const std::string &name, long e)
{ parameters[name] = param_value(double(e)); }
void add_real_param(const std::string &name, double e)
{ parameters[name] = param_value(e); }
void add_string_param(const std::string &name, const std::string &s)
{ parameters[name] = param_value(s); }
// todo : add the access to the arrays
void read_param_file(std::istream &f);
/** Read the parameters on the command line. If a name is found the
* corresponding .param file is searched. If a -dNOM=VALUE is found
* (or -d NOM=VALUE), it is evaluated.
*/
void read_command_line(int argc, char *argv[]);
};
}
namespace ftool {
// For compatibility with Getfem 2.0
using bgeot::md_param;
}
#endif
|