Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
basis_get.cc
Go to the documentation of this file.
1
21//
22// input basis from string or files
23//
24// author: Pierre.Saramito@imag.fr
25//
26// date: 2 october 2017
27//
28// Note:
29// - some technical stuff with bison & flex
30// - some others for distributed issues:
31// * lecture du fichier sur proc=0 -> spec sur proc=0
32// * lecture ecriture spec sur stringstream sur proc=0
33// * broadcast string sur ts procs
34// * lecture du stringstream sur ts les proc -> spec
35// * conversion spec en basis sur ts les procs
36//
37
38//
39#include <sstream> // flex include it, but in namespace rheolef
40#include <cstring>
41#include "rheolef/basis.h"
42#include "rheolef/basis_get.h"
43
44namespace rheolef {
45
46// ================================================================================
47// part 1 : basis specification
48// ================================================================================
49
50static family_index_option_type _current_fio;
51
52} // namespace rheolef
53
54// ================================================================================
55// part 2 : read from istream and build family_index_option_type basis specification
56// ================================================================================
57/* AIX requires this to be the first thing in the file. */
58#ifndef __GNUC__
59# if _RHEOLEF_HAVE_ALLOCA_H
60# include <alloca.h>
61# else
62# ifdef _AIX
63#pragma alloca
64# else
65# ifndef alloca /* predefined by HP cc +Olibcalls */
66char *alloca ();
67# endif
68# endif
69# endif
70#endif
71
72namespace rheolef {
73
74using namespace std;
75
76typedef size_t size_type;
77
80static std::string basis_input_string;
81
82extern int basis_lex();
83void basis_error (const char* msg) {
84 std::string near;
85 error_macro("invalid basis name: \"" << basis_input_string << "\"");
86 basis_n_error++;
87}
88int basis_wrap () { return 1; }
89
90static std::vector<std::string> symbol_table;
91static const std::string& symbol (size_t i) { return symbol_table[i]; }
92static size_t insert (const std::string& str) {
93 size_t i = symbol_table.size();
94 symbol_table.push_back (str);
95 return i;
96}
97#pragma GCC diagnostic push
98#pragma GCC diagnostic ignored "-Weffc++" // avoid FlexLexer warnings
99#define YYMALLOC ::malloc
100#define YYFREE ::free
101#include "basis_yacc.cc"
102// avoid re-definition of YY_NULL within flex
103#ifdef YY_NULL
104#undef YY_NULL
105#endif
106#include "basis_lex.cc"
107#pragma GCC diagnostic pop
108
109static yyFlexLexer input_basis;
110
111int basis_lex() { return input_basis.yylex(); }
112
113static void basis_get_pass_2 (std::string& str);
114
115// ================================================================================
116// read from string via istrstream
117// ================================================================================
118// parse from string on all procs and re-build result_ptr available on all procs
119static
120void
121internal_build_fio_from_string (const std::string& str)
122{
123 std::istringstream istrstr;
124 // force reading until end of string
125 // otherwise skip all optional terms as "d" and "{...}" !
126 std::string str_eol = str + ";";
127 istrstr.str (str_eol);
128 input_basis.yyrestart(istrstr);
129 symbol_table.clear();
130 _current_fio = family_index_option_type();
131 basis_line_no = 1;
132 basis_n_error = 0;
133 basis_input_string = str; // for error msg
134 if (basis_parse() != 0 || basis_n_error != 0) {
135 _current_fio = family_index_option_type();
136 error_macro ("invalid basis name: \"" << str << "\"");
137 }
138 symbol_table.clear();
139 // then _current_fio is available on all procs
140}
141void
142basis_parse_from_string (const std::string& str, family_index_option_type& fio)
143{
144 internal_build_fio_from_string (str);
145 fio = _current_fio;
146}
147// the same for raw basis, without options:
148template<class T>
149void
151{
152 if (str == "") {
153 base::operator= (0);
154 return;
155 }
156 internal_build_fio_from_string (str);
157 std::string name = _current_fio.family + std::to_string(_current_fio.index);
158 base::operator= (basis_raw_rep<T>::make_ptr(name));
159 _clear();
160 _current_fio = family_index_option_type();
161}
162// -----------------------------------------------------------------------------
163// instanciation in library
164// -----------------------------------------------------------------------------
165#define _RHEOLEF_instanciate(T) \
166template void basis_raw_basic<T>::reset (std::string&); \
167
169
170#undef _RHEOLEF_instanciate
171
172} // namespace rheolef
field::size_type size_type
Definition branch.cc:430
see the Float page for the full documentation
void reset(std::string &name)
Definition basis_get.cc:150
static std::vector< std::string > symbol_table
Definition basis_get.cc:90
static family_index_option_type _current_fio
Definition basis_get.cc:50
static size_type basis_line_no
Definition basis_get.cc:78
static size_type basis_n_error
Definition basis_get.cc:79
size_t size_type
Definition basis_get.cc:76
static yyFlexLexer input_basis
Definition basis_get.cc:109
static std::string basis_input_string
Definition basis_get.cc:80
#define _RHEOLEF_instanciate(T)
Definition csr_seq.cc:491
#define error_macro(message)
Definition dis_macros.h:49
This file is part of Rheolef.
void basis_error(const char *msg)
Definition basis_get.cc:83
int basis_wrap()
Definition basis_get.cc:88
void basis_parse_from_string(const std::string &str, family_index_option_type &fio)
Definition basis_get.cc:142
int basis_lex()
Definition basis_get.cc:111
STL namespace.