Skip to content
Snippets Groups Projects
Commit 7623d443 authored by Patrick Dular's avatar Patrick Dular
Browse files

Reorganization of FloatParameterOptions and CharParameterOptions (possibly...

Reorganization of FloatParameterOptions and CharParameterOptions (possibly without comma at the beginning); Struct is now without value
parent 8c87f107
Branches
Tags
No related merge requests found
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -1228,7 +1228,7 @@ DefineConstants :
}
| DefineConstants Comma String__Index tAFFECT '{' ListOfDouble
{ floatOptions.clear(); charOptions.clear(); }
FloatParameterOptions '}'
FloatParameterOptionsOrNone '}'
{
if(List_Nbr($6) != 1)
yymsg(1, "List notation should be used to define list '%s[]'", $3);
......@@ -1248,7 +1248,7 @@ DefineConstants :
}
| DefineConstants Comma String__Index LP RP tAFFECT '{' ListOfDouble
{ floatOptions.clear(); charOptions.clear(); }
FloatParameterOptions '}'
FloatParameterOptionsOrNone '}'
{
std::string key($3);
std::vector<double> val;
......@@ -1275,7 +1275,7 @@ DefineConstants :
}
| DefineConstants Comma String__Index tAFFECT '{' StringExpr
{ floatOptions.clear(); charOptions.clear(); }
CharParameterOptions '}'
CharParameterOptionsOrNone '}'
{
std::string key($3), val($6);
if(!gmsh_yysymbols.count(key)){
......@@ -1334,90 +1334,113 @@ Enumeration :
}
;
FloatParameterOptionsOrNone :
// none
| ',' FloatParameterOptions
;
FloatParameterOptionsOrNone_NoComma :
// none
| FloatParameterOptions
;
FloatParameterOptions :
| FloatParameterOptions FloatParameterOption
FloatParameterOption
| FloatParameterOptions ',' FloatParameterOption
;
FloatParameterOption :
',' tSTRING ListOfDouble
tSTRING ListOfDouble
{
std::string key($2);
for(int i = 0; i < List_Nbr($3); i++){
std::string key($1);
for(int i = 0; i < List_Nbr($2); i++){
double v;
List_Read($3, i, &v);
List_Read($2, i, &v);
floatOptions[key].push_back(v);
}
Free($2);
List_Delete($3);
Free($1);
List_Delete($2);
}
| ',' tSTRING '{' Enumeration '}'
| tSTRING
{
std::string key($2);
for(int i = 0; i < List_Nbr($4); i++){
std::string key($1);
floatOptions[key].push_back(1.);
Free($1);
}
| tSTRING '{' Enumeration '}'
{
std::string key($1);
for(int i = 0; i < List_Nbr($3); i++){
doubleXstring v;
List_Read($4, i, &v);
List_Read($3, i, &v);
floatOptions[key].push_back(v.d);
charOptions[key].push_back(v.s);
}
Free($2);
for(int i = 0; i < List_Nbr($4); i++)
Free(((doubleXstring*)List_Pointer($4, i))->s);
List_Delete($4);
Free($1);
for(int i = 0; i < List_Nbr($3); i++)
Free(((doubleXstring*)List_Pointer($3, i))->s);
List_Delete($3);
}
| ',' tSTRING StringExpr
| tSTRING StringExpr
{
std::string key($2);
std::string val($3);
std::string key($1);
std::string val($2);
charOptions[key].push_back(val);
Free($1);
Free($2);
Free($3);
}
;
CharParameterOptionsOrNone :
// none
| ',' CharParameterOptions
;
CharParameterOptions :
| CharParameterOptions CharParameterOption
CharParameterOption
| CharParameterOptions ',' CharParameterOption
;
CharParameterOption :
',' tSTRING FExpr
tSTRING FExpr
{
std::string key($2);
double val = $3;
std::string key($1);
double val = $2;
floatOptions[key].push_back(val);
Free($2);
Free($1);
}
| ',' tSTRING StringExpr
| tSTRING StringExpr
{
std::string key($2);
std::string val($3);
std::string key($1);
std::string val($2);
charOptions[key].push_back(val);
Free($1);
Free($2);
Free($3);
}
| ',' tMacro StringExpr // Macro is already a reserved keyword
| tMacro StringExpr // Macro is already a reserved keyword
{
std::string key("Macro");
std::string val($3);
std::string val($2);
charOptions[key].push_back(val);
Free($3);
Free($2);
}
| ',' tSTRING '{' RecursiveListOfStringExprVar '}'
| tSTRING '{' RecursiveListOfStringExprVar '}'
{
std::string key($2);
for(int i = 0; i < List_Nbr($4); i++){
std::string key($1);
for(int i = 0; i < List_Nbr($3); i++){
char *s;
List_Read($4, i, &s);
List_Read($3, i, &s);
std::string val(s);
Free(s);
charOptions[key].push_back(val);
}
Free($2);
List_Delete($4);
Free($1);
List_Delete($3);
}
;
......@@ -4638,7 +4661,7 @@ FExpr_Single :
| tDefineNumber LP FExpr
{ floatOptions.clear(); charOptions.clear(); }
FloatParameterOptions RP
FloatParameterOptionsOrNone RP
{
std::vector<double> val(1, $3);
Msg::ExchangeOnelabParameter("", val, floatOptions, charOptions);
......@@ -4942,7 +4965,7 @@ FExpr_Single :
DefineStruct :
tDefineStruct Struct_FullName AppendOrNot
{ floatOptions.clear(); charOptions.clear(); }
'[' FExpr FloatParameterOptions ']'
'[' FloatParameterOptionsOrNone_NoComma ']'
{
std::string struct_namespace($2.char1? $2.char1 : std::string("")),
struct_name($2.char2);
......@@ -5564,21 +5587,23 @@ StringExprVar :
std::string out;
std::string struct_namespace($1.char1? $1.char1 : std::string("")),
struct_name($1.char2);
std::string key_member($3);
const std::string * out = NULL;
std::string out_tmp; // PD: we should avoid that -> StringOption() to be changed
switch (nameSpaces.getMember
(struct_namespace, struct_name, key_member, out)) {
case 0:
break;
case 1:
StringOption(GMSH_GET, $1, 0, $3, out);
StringOption(GMSH_GET, $1, 0, $3, out_tmp);
out = &out_tmp;
break;
case 2:
yymsg(0, "Unknown member '%s' of Struct %s", $3, struct_name.c_str());
break;
}
char* out_c = (char*)Malloc((out.size() + 1) * sizeof(char));
strcpy(out_c, out.c_str());
char* out_c = (char*)Malloc((out->size() + 1) * sizeof(char));
strcpy(out_c, out->c_str());
Free($1.char1); Free($1.char2);
if (flag_tSTRING_alloc) Free(c3);
*/
......@@ -5859,7 +5884,7 @@ StringExpr :
}
| tDefineString LP StringExpr
{ floatOptions.clear(); charOptions.clear(); }
CharParameterOptions RP
CharParameterOptionsOrNone RP
{
std::string val($3);
Msg::ExchangeOnelabParameter("", val, floatOptions, charOptions);
......@@ -6647,7 +6672,6 @@ double treat_Struct_FullName_dot_tSTRING_Float(char* c1, char* c2, char* c3)
char* treat_Struct_FullName_dot_tSTRING_String(char* c1, char* c2, char* c3)
{
std::string out;
std::string struct_namespace(c1? c1 : std::string("")),
struct_name(c2);
/*
......@@ -6655,20 +6679,23 @@ char* treat_Struct_FullName_dot_tSTRING_String(char* c1, char* c2, char* c3)
struct_name($1.char2);
*/
std::string key_member(c3);
const std::string * out = NULL;
std::string out_tmp; // PD: we should avoid that -> StringOption() to be changed
switch (nameSpaces.getMember
(struct_namespace, struct_name, key_member, out)) {
case 0:
break;
case 1:
StringOption(GMSH_GET, c2, 0, c3, out);
StringOption(GMSH_GET, c2, 0, c3, out_tmp);
out = &out_tmp;
break;
case 2:
yymsg(0, "Unknown member '%s' of Struct %s", c3, struct_name.c_str());
break;
}
char* out_c = (char*)Malloc((out.size() + 1) * sizeof(char));
strcpy(out_c, out.c_str());
char* out_c = (char*)Malloc((out->size() + 1) * sizeof(char));
strcpy(out_c, out->c_str());
Free(c1); Free(c2);
if (flag_tSTRING_alloc) Free(c3);
return out_c;
......
......@@ -43,16 +43,17 @@ public:
int append(int tag,
std::map<std::string, std::vector<double> > & fopt,
std::map<std::string, std::vector<std::string> > & copt) {
this->_fopt.insert(fopt.begin(), fopt.end());
this->_copt.insert(copt.begin(), copt.end());
_fopt.insert(fopt.begin(), fopt.end());
_copt.insert(copt.begin(), copt.end());
if (tag >= 0) _tag = tag;
return _tag;
}
inline int getTag() { return _tag; }
inline int getTag() const { return _tag; }
int getMember(std::string & key_member, double &out) {
std::map<std::string, std::vector<double> >::iterator it = _fopt.find(key_member);
int getMember (std::string & key_member, double & out) const {
std::map<std::string, std::vector<double> >::const_iterator
it = _fopt.find(key_member);
if (it != _fopt.end()) {
out = it->second[0]; return 0;
}
......@@ -61,20 +62,41 @@ public:
}
}
int getMember(std::string & key_member, std::string & out) {
std::map<std::string, std::vector<std::string> >::iterator
int getMember (std::string & key_member, const std::string * & out) const {
std::map<std::string, std::vector<std::string> >::const_iterator
it = _copt.find(key_member);
if (it != _copt.end()) {
out = it->second[0]; return 0;
out = &it->second[0]; return 0;
}
else {
out = std::string(""); return 1; // Error: Unknown member of Struct
out = NULL; return 1; // Error: Unknown member of Struct
}
}
void print(const std::string & struct_name, const std::string & struct_namespace)
void sprint(std::string & str,
const std::string & struct_name, const std::string & struct_namespace)
const
{
//...
str += "Struct ";
if (struct_namespace.size()) str += struct_namespace + "::";
str += struct_name + " [ ";
bool flag_comma = false;
for (std::map<std::string, std::vector<double> >::const_iterator
it_attrib = _fopt.begin();
it_attrib != _fopt.end(); ++it_attrib ) {
if (!flag_comma && it_attrib != _fopt.begin()) flag_comma = true;
if (flag_comma) str += ", ";
str += it_attrib->first + " ";
char tmp[32]; sprintf(tmp, "%g", it_attrib->second[0]); str += tmp;
}
for (std::map<std::string, std::vector<std::string> >::const_iterator
it_attrib = _copt.begin();
it_attrib != _copt.end(); ++it_attrib ) {
if (!flag_comma && it_attrib != _copt.begin()) flag_comma = true;
if (flag_comma) str += ", ";
str += it_attrib->first + " \"" + it_attrib->second[0] + "\"";
}
str += " ];\n";
}
private:
......@@ -96,10 +118,17 @@ public:
else return NULL;
}
const T * Find(K key) const {
typename std::map<K, T>::const_iterator it;
if ( (it = _map.find(key)) != _map.end() ) return &it->second;
else return NULL;
}
inline T & operator[] (K key) { return _map[key]; }
inline std::map<K, T> & get() { return _map; }
inline int count (std::string key) { return _map.count(key); }
inline int size () { return _map.size(); }
inline const std::map<K, T> & get() const { return _map; }
inline int count (const std::string key) const { return _map.count(key); }
inline int size () const { return _map.size(); }
public:
std::map<K, T> _map;
......@@ -118,13 +147,15 @@ public:
std::map<std::string, std::vector<std::string> > & copt,
bool append = false) {
int tag;
std::map<std::string, std::vector<double> >::iterator it = fopt.find("Tag");
std::map<std::string, std::vector<double> >::const_iterator it = fopt.find("Tag");
if (it != fopt.end()) {
tag = it->second[0]; // Tag forced
tag = (int)it->second[0]; // Tag forced
_max_tag = std::max(_max_tag, tag);
}
else
else {
tag = (!append)? ++_max_tag : -1; // Tag auto
if (!append) fopt["Tag"].push_back((double)tag);
}
if (!append)
(*this)[struct_name] = Struct(tag, fopt, copt);
else
......@@ -132,21 +163,19 @@ public:
return tag;
}
int get_key_struct_from_tag(int tag, const std::string * & key_struct) {
Map_string_Struct::iterator it_st;
int get_key_struct_from_tag(int tag, const std::string * & key_struct) const {
Map_string_Struct::const_iterator it_st;
for (it_st = this->get().begin(); it_st != this->get().end(); ++it_st )
if (it_st->second.getTag() == tag) break;
if (it_st != this->get().end()) {
if (it_st == this->get().end()) return 2; // 2: Error: Unknown Struct
key_struct = &it_st->first;
return 0;
}
else return 2;
return 0; // 0: no error
}
void print(const std::string & struct_namespace) {
for (Map_string_Struct::iterator it_st = this->get().begin();
void sprint(std::string & str, const std::string & struct_namespace) const {
for (Map_string_Struct::const_iterator it_st = this->get().begin();
it_st != this->get().end(); ++it_st )
it_st->second.print(it_st->first, struct_namespace);
it_st->second.sprint(str, it_st->first, struct_namespace);
}
private:
......@@ -168,69 +197,69 @@ public:
Structs * structs_P = &(*this)[key_namespace];
if (!append && structs_P->count(key_name)) {
tag_out = (*structs_P)[key_name].getTag();
return 1; // Error: Redefinition of Struct
return 1; // 1: Error: Redefinition of Struct
}
tag_out = structs_P->defStruct(key_name, fopt, copt, append);
return 0;
return 0; // 0: no error
}
int getTag(std::string & key_namespace, std::string & key_name,
double & out) {
Structs * structs_P = this->Find(key_namespace);
Struct * struct_P = (structs_P)? structs_P->Find(key_name) : NULL;
double & out) const {
const Structs * structs_P = this->Find(key_namespace);
const Struct * struct_P = (structs_P)? structs_P->Find(key_name) : NULL;
if (structs_P && struct_P) {
out = (double)struct_P->getTag();
}
else {
out = 0.; return 1; // Error: Unknown Struct
out = 0.; return 1; // 1: Error: Unknown Struct
}
return 0;
return 0; // 0: no error
}
int getMember(std::string & key_namespace, std::string & key_name,
std::string & key_member, double & out) {
std::string & key_member, double & out) const {
Structs * structs_P = this->Find(key_namespace);
Struct * struct_P = (structs_P)? structs_P->Find(key_name) : NULL;
const Structs * structs_P = this->Find(key_namespace);
const Struct * struct_P = (structs_P)? structs_P->Find(key_name) : NULL;
if (structs_P && struct_P) {
if (struct_P->getMember(key_member, out)) {
out = 0.; return 2; // Error: Unknown member of Struct
out = 0.; return 2; // 2: Error: Unknown member of Struct
}
}
else {
out = 0.; return 1; // Error: Unknown Struct
out = 0.; return 1; // 1: Error: Unknown Struct
}
return 0;
return 0; // 0: no error
}
int getMember(std::string & key_namespace, std::string & key_name,
std::string & key_member, std::string & out) {
std::string & key_member, const std::string * & out) const {
Structs * structs_P = this->Find(key_namespace);
Struct * struct_P = (structs_P)? structs_P->Find(key_name) : NULL;
const Structs * structs_P = this->Find(key_namespace);
const Struct * struct_P = (structs_P)? structs_P->Find(key_name) : NULL;
if (structs_P && struct_P) {
if (struct_P->getMember(key_member, out)) {
out = std::string(""); return 2; // Error: Unknown member of Struct
out = NULL; return 2; // 2: Error: Unknown member of Struct
}
}
else {
out = std::string(""); return 1; // Error: Unknown Struct
out = NULL; return 1; // 1: Error: Unknown Struct
}
return 0;
return 0; // 0: no error
}
int get_key_struct_from_tag(std::string & key_namespace,
int tag, const std::string * & key_struct) {
if (this->count(key_namespace))
return (*this)[key_namespace].get_key_struct_from_tag(tag, key_struct);
else return 1;
int tag, const std::string * & key_struct) const {
const Structs * structs_P = this->Find(key_namespace);
if (structs_P != NULL)
return structs_P->get_key_struct_from_tag(tag, key_struct);
else return 1; // 1: Error: Unknown NameSpace
}
void print() {
for (Map_string_Structs::iterator it_ns = this->get().begin();
void sprint(std::string & str) const {
for (Map_string_Structs::const_iterator it_ns = this->get().begin();
it_ns != this->get().end(); ++it_ns )
it_ns->second.print(it_ns->first);
it_ns->second.sprint(str, it_ns->first);
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment