basis_get.cc
Go to the documentation of this file.
//
// input basis from string or files
//
// author: Pierre.Saramito@imag.fr
//
// date: 2 october 2017
//
// Note:
// - some technical stuff with bison & flex
// - some others for distributed issues:
// * lecture du fichier sur proc=0 -> spec sur proc=0
// * lecture ecriture spec sur stringstream sur proc=0
// * broadcast string sur ts procs
// * lecture du stringstream sur ts les proc -> spec
// * conversion spec en basis sur ts les procs
//
//
#include <sstream> // flex include it, but in namespace rheolef
#include <cstring>
#include "rheolef/basis.h"
#include "rheolef/basis_get.h"
namespace rheolef {
// ================================================================================
// part 1 : basis specification
// ================================================================================
static family_index_option_type _current_fio;
} // namespace rheolef
// ================================================================================
// part 2 : read from istream and build family_index_option_type basis specification
// ================================================================================
/* AIX requires this to be the first thing in the file. */
#ifndef __GNUC__
# if _RHEOLEF_HAVE_ALLOCA_H
# include <alloca.h>
# else
# ifdef _AIX
#pragma alloca
# else
# ifndef alloca /* predefined by HP cc +Olibcalls */
char *alloca ();
# endif
# endif
# endif
#endif
namespace rheolef {
using namespace std;
typedef size_t size_type;
static size_type basis_line_no = 1;
static size_type basis_n_error = 0;
static std::string basis_input_string;
extern int basis_lex();
void basis_error (const char* msg) {
std::string near;
error_macro("invalid basis name: \"" << basis_input_string << "\"");
basis_n_error++;
}
int basis_wrap () { return 1; }
static std::vector<std::string> symbol_table;
static const std::string& symbol (size_t i) { return symbol_table[i]; }
static size_t insert (const std::string& str) {
size_t i = symbol_table.size();
symbol_table.push_back (str);
return i;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++" // avoid FlexLexer warnings
#define YYMALLOC ::malloc
#define YYFREE ::free
#include "basis_yacc.cc"
// avoid re-definition of YY_NULL within flex
#ifdef YY_NULL
#undef YY_NULL
#endif
#include "basis_lex.cc"
#pragma GCC diagnostic pop
static yyFlexLexer input_basis;
int basis_lex() { return input_basis.yylex(); }
static void basis_get_pass_2 (std::string& str);
// ================================================================================
// read from string via istrstream
// ================================================================================
// parse from string on all procs and re-build result_ptr available on all procs
static
void
internal_build_fio_from_string (const std::string& str)
{
std::istringstream istrstr;
// force reading until end of string
// otherwise skip all optional terms as "d" and "{...}" !
std::string str_eol = str + ";";
istrstr.str (str_eol);
input_basis.yyrestart(istrstr);
symbol_table.clear();
_current_fio = family_index_option_type();
basis_line_no = 1;
basis_n_error = 0;
basis_input_string = str; // for error msg
if (basis_parse() != 0 || basis_n_error != 0) {
_current_fio = family_index_option_type();
error_macro ("invalid basis name: \"" << str << "\"");
}
symbol_table.clear();
// then _current_fio is available on all procs
}
void
basis_parse_from_string (const std::string& str, family_index_option_type& fio)
{
internal_build_fio_from_string (str);
fio = _current_fio;
}
// the same for raw basis, without options:
template<class T>
void
basis_raw_basic<T>::reset (std::string& str)
{
if (str == "") {
base::operator= (0);
return;
}
internal_build_fio_from_string (str);
std::string name = _current_fio.family + itos(_current_fio.index);
base::operator= (basis_raw_rep<T>::make_ptr(name));
_clear();
_current_fio = family_index_option_type();
}
// -----------------------------------------------------------------------------
// instanciation in library
// -----------------------------------------------------------------------------
#define _RHEOLEF_instanciate(T) \
template void basis_raw_basic<T>::reset (std::string&); \
_RHEOLEF_instanciate(Float)
#undef _RHEOLEF_instanciate
} // namespace rheolef
Float
see the Float page for the full documentation
rheolef::basis_raw_basic::reset
void reset(std::string &name)
Definition: basis_get.cc:150
rheolef::basis_raw_rep
Definition: basis_raw.h:36
rheolef::symbol_table
static std::vector< std::string > symbol_table
Definition: basis_get.cc:90
rheolef::_current_fio
static family_index_option_type _current_fio
Definition: basis_get.cc:50
rheolef::basis_line_no
static size_type basis_line_no
Definition: basis_get.cc:78
rheolef::basis_n_error
static size_type basis_n_error
Definition: basis_get.cc:79
rheolef::size_type
size_t size_type
Definition: basis_get.cc:76
rheolef::input_basis
static yyFlexLexer input_basis
Definition: basis_get.cc:109
rheolef::basis_input_string
static std::string basis_input_string
Definition: basis_get.cc:80
error_macro
#define error_macro(message)
Definition: dis_macros.h:49
mkgeo_contraction.name
string name
Definition: mkgeo_contraction.sh:133
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::_RHEOLEF_instanciate
_RHEOLEF_instanciate(Float, sequential) _RHEOLEF_instanciate(Float
rheolef::basis_wrap
int basis_wrap()
Definition: basis_get.cc:88
rheolef::basis_parse_from_string
void basis_parse_from_string(const std::string &str, family_index_option_type &fio)
Definition: basis_get.cc:142
rheolef::itos
std::string itos(std::string::size_type i)
itos: see the rheostream page for the full documentation
rheolef::basis_lex
int basis_lex()
Definition: basis_get.cc:111
rheolef::basis_error
void basis_error(const char *msg)
Definition: basis_get.cc:83
rheolef::family_index_option_type
Definition: basis_get.h:31