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
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
...@@ -1228,7 +1228,7 @@ DefineConstants : ...@@ -1228,7 +1228,7 @@ DefineConstants :
} }
| DefineConstants Comma String__Index tAFFECT '{' ListOfDouble | DefineConstants Comma String__Index tAFFECT '{' ListOfDouble
{ floatOptions.clear(); charOptions.clear(); } { floatOptions.clear(); charOptions.clear(); }
FloatParameterOptions '}' FloatParameterOptionsOrNone '}'
{ {
if(List_Nbr($6) != 1) if(List_Nbr($6) != 1)
yymsg(1, "List notation should be used to define list '%s[]'", $3); yymsg(1, "List notation should be used to define list '%s[]'", $3);
...@@ -1248,7 +1248,7 @@ DefineConstants : ...@@ -1248,7 +1248,7 @@ DefineConstants :
} }
| DefineConstants Comma String__Index LP RP tAFFECT '{' ListOfDouble | DefineConstants Comma String__Index LP RP tAFFECT '{' ListOfDouble
{ floatOptions.clear(); charOptions.clear(); } { floatOptions.clear(); charOptions.clear(); }
FloatParameterOptions '}' FloatParameterOptionsOrNone '}'
{ {
std::string key($3); std::string key($3);
std::vector<double> val; std::vector<double> val;
...@@ -1275,7 +1275,7 @@ DefineConstants : ...@@ -1275,7 +1275,7 @@ DefineConstants :
} }
| DefineConstants Comma String__Index tAFFECT '{' StringExpr | DefineConstants Comma String__Index tAFFECT '{' StringExpr
{ floatOptions.clear(); charOptions.clear(); } { floatOptions.clear(); charOptions.clear(); }
CharParameterOptions '}' CharParameterOptionsOrNone '}'
{ {
std::string key($3), val($6); std::string key($3), val($6);
if(!gmsh_yysymbols.count(key)){ if(!gmsh_yysymbols.count(key)){
...@@ -1334,90 +1334,113 @@ Enumeration : ...@@ -1334,90 +1334,113 @@ Enumeration :
} }
; ;
FloatParameterOptionsOrNone :
// none
| ',' FloatParameterOptions
;
FloatParameterOptionsOrNone_NoComma :
// none
| FloatParameterOptions
;
FloatParameterOptions : FloatParameterOptions :
| FloatParameterOptions FloatParameterOption FloatParameterOption
| FloatParameterOptions ',' FloatParameterOption
; ;
FloatParameterOption : FloatParameterOption :
',' tSTRING ListOfDouble tSTRING ListOfDouble
{ {
std::string key($2); std::string key($1);
for(int i = 0; i < List_Nbr($3); i++){ for(int i = 0; i < List_Nbr($2); i++){
double v; double v;
List_Read($3, i, &v); List_Read($2, i, &v);
floatOptions[key].push_back(v); floatOptions[key].push_back(v);
} }
Free($2); Free($1);
List_Delete($3); List_Delete($2);
}
| tSTRING
{
std::string key($1);
floatOptions[key].push_back(1.);
Free($1);
} }
| ',' tSTRING '{' Enumeration '}' | tSTRING '{' Enumeration '}'
{ {
std::string key($2); std::string key($1);
for(int i = 0; i < List_Nbr($4); i++){ for(int i = 0; i < List_Nbr($3); i++){
doubleXstring v; doubleXstring v;
List_Read($4, i, &v); List_Read($3, i, &v);
floatOptions[key].push_back(v.d); floatOptions[key].push_back(v.d);
charOptions[key].push_back(v.s); charOptions[key].push_back(v.s);
} }
Free($2); Free($1);
for(int i = 0; i < List_Nbr($4); i++) for(int i = 0; i < List_Nbr($3); i++)
Free(((doubleXstring*)List_Pointer($4, i))->s); Free(((doubleXstring*)List_Pointer($3, i))->s);
List_Delete($4); List_Delete($3);
} }
| ',' tSTRING StringExpr | tSTRING StringExpr
{ {
std::string key($2); std::string key($1);
std::string val($3); std::string val($2);
charOptions[key].push_back(val); charOptions[key].push_back(val);
Free($1);
Free($2); Free($2);
Free($3);
} }
; ;
CharParameterOptionsOrNone :
// none
| ',' CharParameterOptions
;
CharParameterOptions : CharParameterOptions :
| CharParameterOptions CharParameterOption CharParameterOption
| CharParameterOptions ',' CharParameterOption
; ;
CharParameterOption : CharParameterOption :
',' tSTRING FExpr tSTRING FExpr
{ {
std::string key($2); std::string key($1);
double val = $3; double val = $2;
floatOptions[key].push_back(val); floatOptions[key].push_back(val);
Free($2); Free($1);
} }
| ',' tSTRING StringExpr | tSTRING StringExpr
{ {
std::string key($2); std::string key($1);
std::string val($3); std::string val($2);
charOptions[key].push_back(val); charOptions[key].push_back(val);
Free($1);
Free($2); 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 key("Macro");
std::string val($3); std::string val($2);
charOptions[key].push_back(val); charOptions[key].push_back(val);
Free($3); Free($2);
} }
| ',' tSTRING '{' RecursiveListOfStringExprVar '}' | tSTRING '{' RecursiveListOfStringExprVar '}'
{ {
std::string key($2); std::string key($1);
for(int i = 0; i < List_Nbr($4); i++){ for(int i = 0; i < List_Nbr($3); i++){
char *s; char *s;
List_Read($4, i, &s); List_Read($3, i, &s);
std::string val(s); std::string val(s);
Free(s); Free(s);
charOptions[key].push_back(val); charOptions[key].push_back(val);
} }
Free($2); Free($1);
List_Delete($4); List_Delete($3);
} }
; ;
...@@ -4638,7 +4661,7 @@ FExpr_Single : ...@@ -4638,7 +4661,7 @@ FExpr_Single :
| tDefineNumber LP FExpr | tDefineNumber LP FExpr
{ floatOptions.clear(); charOptions.clear(); } { floatOptions.clear(); charOptions.clear(); }
FloatParameterOptions RP FloatParameterOptionsOrNone RP
{ {
std::vector<double> val(1, $3); std::vector<double> val(1, $3);
Msg::ExchangeOnelabParameter("", val, floatOptions, charOptions); Msg::ExchangeOnelabParameter("", val, floatOptions, charOptions);
...@@ -4942,7 +4965,7 @@ FExpr_Single : ...@@ -4942,7 +4965,7 @@ FExpr_Single :
DefineStruct : DefineStruct :
tDefineStruct Struct_FullName AppendOrNot tDefineStruct Struct_FullName AppendOrNot
{ floatOptions.clear(); charOptions.clear(); } { floatOptions.clear(); charOptions.clear(); }
'[' FExpr FloatParameterOptions ']' '[' FloatParameterOptionsOrNone_NoComma ']'
{ {
std::string struct_namespace($2.char1? $2.char1 : std::string("")), std::string struct_namespace($2.char1? $2.char1 : std::string("")),
struct_name($2.char2); struct_name($2.char2);
...@@ -5564,21 +5587,23 @@ StringExprVar : ...@@ -5564,21 +5587,23 @@ StringExprVar :
std::string out; std::string out;
std::string struct_namespace($1.char1? $1.char1 : std::string("")), std::string struct_namespace($1.char1? $1.char1 : std::string("")),
struct_name($1.char2); struct_name($1.char2);
std::string key_member($3); 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 switch (nameSpaces.getMember
(struct_namespace, struct_name, key_member, out)) { (struct_namespace, struct_name, key_member, out)) {
case 0: case 0:
break; break;
case 1: case 1:
StringOption(GMSH_GET, $1, 0, $3, out); StringOption(GMSH_GET, $1, 0, $3, out_tmp);
out = &out_tmp;
break; break;
case 2: case 2:
yymsg(0, "Unknown member '%s' of Struct %s", $3, struct_name.c_str()); yymsg(0, "Unknown member '%s' of Struct %s", $3, struct_name.c_str());
break; break;
} }
char* out_c = (char*)Malloc((out.size() + 1) * sizeof(char)); char* out_c = (char*)Malloc((out->size() + 1) * sizeof(char));
strcpy(out_c, out.c_str()); strcpy(out_c, out->c_str());
Free($1.char1); Free($1.char2); Free($1.char1); Free($1.char2);
if (flag_tSTRING_alloc) Free(c3); if (flag_tSTRING_alloc) Free(c3);
*/ */
...@@ -5859,7 +5884,7 @@ StringExpr : ...@@ -5859,7 +5884,7 @@ StringExpr :
} }
| tDefineString LP StringExpr | tDefineString LP StringExpr
{ floatOptions.clear(); charOptions.clear(); } { floatOptions.clear(); charOptions.clear(); }
CharParameterOptions RP CharParameterOptionsOrNone RP
{ {
std::string val($3); std::string val($3);
Msg::ExchangeOnelabParameter("", val, floatOptions, charOptions); Msg::ExchangeOnelabParameter("", val, floatOptions, charOptions);
...@@ -6647,7 +6672,6 @@ double treat_Struct_FullName_dot_tSTRING_Float(char* c1, char* c2, char* c3) ...@@ -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) char* treat_Struct_FullName_dot_tSTRING_String(char* c1, char* c2, char* c3)
{ {
std::string out;
std::string struct_namespace(c1? c1 : std::string("")), std::string struct_namespace(c1? c1 : std::string("")),
struct_name(c2); struct_name(c2);
/* /*
...@@ -6655,20 +6679,23 @@ char* treat_Struct_FullName_dot_tSTRING_String(char* c1, char* c2, char* c3) ...@@ -6655,20 +6679,23 @@ char* treat_Struct_FullName_dot_tSTRING_String(char* c1, char* c2, char* c3)
struct_name($1.char2); struct_name($1.char2);
*/ */
std::string key_member(c3); 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 switch (nameSpaces.getMember
(struct_namespace, struct_name, key_member, out)) { (struct_namespace, struct_name, key_member, out)) {
case 0: case 0:
break; break;
case 1: case 1:
StringOption(GMSH_GET, c2, 0, c3, out); StringOption(GMSH_GET, c2, 0, c3, out_tmp);
out = &out_tmp;
break; break;
case 2: case 2:
yymsg(0, "Unknown member '%s' of Struct %s", c3, struct_name.c_str()); yymsg(0, "Unknown member '%s' of Struct %s", c3, struct_name.c_str());
break; break;
} }
char* out_c = (char*)Malloc((out.size() + 1) * sizeof(char)); char* out_c = (char*)Malloc((out->size() + 1) * sizeof(char));
strcpy(out_c, out.c_str()); strcpy(out_c, out->c_str());
Free(c1); Free(c2); Free(c1); Free(c2);
if (flag_tSTRING_alloc) Free(c3); if (flag_tSTRING_alloc) Free(c3);
return out_c; return out_c;
......
...@@ -43,16 +43,17 @@ public: ...@@ -43,16 +43,17 @@ public:
int append(int tag, int append(int tag,
std::map<std::string, std::vector<double> > & fopt, std::map<std::string, std::vector<double> > & fopt,
std::map<std::string, std::vector<std::string> > & copt) { std::map<std::string, std::vector<std::string> > & copt) {
this->_fopt.insert(fopt.begin(), fopt.end()); _fopt.insert(fopt.begin(), fopt.end());
this->_copt.insert(copt.begin(), copt.end()); _copt.insert(copt.begin(), copt.end());
if (tag >= 0) _tag = tag; if (tag >= 0) _tag = tag;
return _tag; return _tag;
} }
inline int getTag() { return _tag; } inline int getTag() const { return _tag; }
int getMember(std::string & key_member, double &out) { int getMember (std::string & key_member, double & out) const {
std::map<std::string, std::vector<double> >::iterator it = _fopt.find(key_member); std::map<std::string, std::vector<double> >::const_iterator
it = _fopt.find(key_member);
if (it != _fopt.end()) { if (it != _fopt.end()) {
out = it->second[0]; return 0; out = it->second[0]; return 0;
} }
...@@ -61,20 +62,41 @@ public: ...@@ -61,20 +62,41 @@ public:
} }
} }
int getMember(std::string & key_member, std::string & out) { int getMember (std::string & key_member, const std::string * & out) const {
std::map<std::string, std::vector<std::string> >::iterator std::map<std::string, std::vector<std::string> >::const_iterator
it = _copt.find(key_member); it = _copt.find(key_member);
if (it != _copt.end()) { if (it != _copt.end()) {
out = it->second[0]; return 0; out = &it->second[0]; return 0;
} }
else { 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: private:
...@@ -96,10 +118,17 @@ public: ...@@ -96,10 +118,17 @@ public:
else return NULL; 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 T & operator[] (K key) { return _map[key]; }
inline std::map<K, T> & get() { return _map; } inline std::map<K, T> & get() { return _map; }
inline int count (std::string key) { return _map.count(key); } inline const std::map<K, T> & get() const { return _map; }
inline int size () { return _map.size(); } inline int count (const std::string key) const { return _map.count(key); }
inline int size () const { return _map.size(); }
public: public:
std::map<K, T> _map; std::map<K, T> _map;
...@@ -118,13 +147,15 @@ public: ...@@ -118,13 +147,15 @@ public:
std::map<std::string, std::vector<std::string> > & copt, std::map<std::string, std::vector<std::string> > & copt,
bool append = false) { bool append = false) {
int tag; 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()) { if (it != fopt.end()) {
tag = it->second[0]; // Tag forced tag = (int)it->second[0]; // Tag forced
_max_tag = std::max(_max_tag, tag); _max_tag = std::max(_max_tag, tag);
} }
else else {
tag = (!append)? ++_max_tag : -1; // Tag auto tag = (!append)? ++_max_tag : -1; // Tag auto
if (!append) fopt["Tag"].push_back((double)tag);
}
if (!append) if (!append)
(*this)[struct_name] = Struct(tag, fopt, copt); (*this)[struct_name] = Struct(tag, fopt, copt);
else else
...@@ -132,21 +163,19 @@ public: ...@@ -132,21 +163,19 @@ public:
return tag; return tag;
} }
int get_key_struct_from_tag(int tag, const std::string * & key_struct) { int get_key_struct_from_tag(int tag, const std::string * & key_struct) const {
Map_string_Struct::iterator it_st; Map_string_Struct::const_iterator it_st;
for (it_st = this->get().begin(); it_st != this->get().end(); ++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->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; key_struct = &it_st->first;
return 0; return 0; // 0: no error
}
else return 2;
} }
void print(const std::string & struct_namespace) { void sprint(std::string & str, const std::string & struct_namespace) const {
for (Map_string_Struct::iterator it_st = this->get().begin(); for (Map_string_Struct::const_iterator it_st = this->get().begin();
it_st != this->get().end(); ++it_st ) 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: private:
...@@ -168,69 +197,69 @@ public: ...@@ -168,69 +197,69 @@ public:
Structs * structs_P = &(*this)[key_namespace]; Structs * structs_P = &(*this)[key_namespace];
if (!append && structs_P->count(key_name)) { if (!append && structs_P->count(key_name)) {
tag_out = (*structs_P)[key_name].getTag(); 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); 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, int getTag(std::string & key_namespace, std::string & key_name,
double & out) { double & out) const {
const Structs * structs_P = this->Find(key_namespace);
Structs * structs_P = this->Find(key_namespace); const Struct * struct_P = (structs_P)? structs_P->Find(key_name) : NULL;
Struct * struct_P = (structs_P)? structs_P->Find(key_name) : NULL;
if (structs_P && struct_P) { if (structs_P && struct_P) {
out = (double)struct_P->getTag(); out = (double)struct_P->getTag();
} }
else { 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, 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); const Structs * structs_P = this->Find(key_namespace);
Struct * struct_P = (structs_P)? structs_P->Find(key_name) : NULL; const Struct * struct_P = (structs_P)? structs_P->Find(key_name) : NULL;
if (structs_P && struct_P) { if (structs_P && struct_P) {
if (struct_P->getMember(key_member, out)) { 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 { 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, 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); const Structs * structs_P = this->Find(key_namespace);
Struct * struct_P = (structs_P)? structs_P->Find(key_name) : NULL; const Struct * struct_P = (structs_P)? structs_P->Find(key_name) : NULL;
if (structs_P && struct_P) { if (structs_P && struct_P) {
if (struct_P->getMember(key_member, out)) { 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 { 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 get_key_struct_from_tag(std::string & key_namespace,
int tag, const std::string * & key_struct) { int tag, const std::string * & key_struct) const {
if (this->count(key_namespace)) const Structs * structs_P = this->Find(key_namespace);
return (*this)[key_namespace].get_key_struct_from_tag(tag, key_struct); if (structs_P != NULL)
else return 1; return structs_P->get_key_struct_from_tag(tag, key_struct);
else return 1; // 1: Error: Unknown NameSpace
} }
void print() { void sprint(std::string & str) const {
for (Map_string_Structs::iterator it_ns = this->get().begin(); for (Map_string_Structs::const_iterator it_ns = this->get().begin();
it_ns != this->get().end(); ++it_ns ) 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