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

Added: get a list of reals from a structure member

parent 49cbb4f4
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
This diff is collapsed.
...@@ -494,7 +494,7 @@ ...@@ -494,7 +494,7 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE typedef union YYSTYPE
#line 159 "Gmsh.y" #line 161 "Gmsh.y"
{ {
char *c; char *c;
int i; int i;
......
...@@ -140,6 +140,8 @@ double treat_Struct_FullName_Float ...@@ -140,6 +140,8 @@ double treat_Struct_FullName_Float
double treat_Struct_FullName_dot_tSTRING_Float double treat_Struct_FullName_dot_tSTRING_Float
(char* c1, char* c2, char* c3, int index = 0, (char* c1, char* c2, char* c3, int index = 0,
double val_default = 0., int type_treat = 0); double val_default = 0., int type_treat = 0);
List_T * treat_Struct_FullName_dot_tSTRING_ListOfFloat
(char* c1, char* c2, char* c3);
int treat_Struct_FullName_dot_tSTRING_Float_getDim int treat_Struct_FullName_dot_tSTRING_Float_getDim
(char* c1, char* c2, char* c3); (char* c1, char* c2, char* c3);
char* treat_Struct_FullName_String char* treat_Struct_FullName_String
...@@ -4904,7 +4906,7 @@ FExpr_Single : ...@@ -4904,7 +4906,7 @@ FExpr_Single :
Free($2); Free($2);
} }
| '#' Struct_FullName '.' tSTRING_Member_Float '(' ')' | '#' Struct_FullName '.' tSTRING_Member_Float LP RP
{ {
$$ = treat_Struct_FullName_dot_tSTRING_Float_getDim($2.char1, $2.char2, $4); $$ = treat_Struct_FullName_dot_tSTRING_Float_getDim($2.char1, $2.char2, $4);
} }
...@@ -5011,6 +5013,14 @@ FExpr_Single : ...@@ -5011,6 +5013,14 @@ FExpr_Single :
{ {
$$ = treat_Struct_FullName_dot_tSTRING_Float($1, $3, $5, (int)$7); $$ = treat_Struct_FullName_dot_tSTRING_Float($1, $3, $5, (int)$7);
} }
| String__Index '.' tSTRING_Member_Float '[' FExpr ']'
{
$$ = treat_Struct_FullName_dot_tSTRING_Float(NULL, $1, $3, (int)$5);
}
| String__Index tSCOPE String__Index '.' tSTRING_Member_Float '[' FExpr ']'
{
$$ = treat_Struct_FullName_dot_tSTRING_Float($1, $3, $5, (int)$7);
}
| String__Index '[' FExpr ']' '.' tSTRING | String__Index '[' FExpr ']' '.' tSTRING
{ {
...@@ -5464,6 +5474,16 @@ FExpr_Multi : ...@@ -5464,6 +5474,16 @@ FExpr_Multi :
} }
Free($1); Free($1);
} }
| String__Index '.' tSTRING_Member_Float LP RP
{
$$ = treat_Struct_FullName_dot_tSTRING_ListOfFloat(NULL, $1, $3);
}
| String__Index tSCOPE String__Index '.' tSTRING_Member_Float LP RP
{
$$ = treat_Struct_FullName_dot_tSTRING_ListOfFloat($1, $3, $5);
}
// for compatibility with GetDP // for compatibility with GetDP
| tList '[' String__Index ']' | tList '[' String__Index ']'
{ {
...@@ -6902,6 +6922,36 @@ double treat_Struct_FullName_dot_tSTRING_Float ...@@ -6902,6 +6922,36 @@ double treat_Struct_FullName_dot_tSTRING_Float
return out; return out;
} }
List_T * treat_Struct_FullName_dot_tSTRING_ListOfFloat
(char* c1, char* c2, char* c3)
{
List_T * out, * val_default = NULL;
const std::vector<double> * out_vector; double val_;
std::string struct_namespace(c1? c1 : std::string("")), struct_name(c2);
std::string key_member(c3);
switch (nameSpaces.getMember_Vector
(struct_namespace, struct_name, key_member, out_vector)) {
case 0:
out = List_Create(out_vector->size(), 1, sizeof(double));
for(int i = 0; i < out_vector->size(); i++) {
val_ = out_vector->at(i);
List_Add(out, &val_);
}
break;
case 1:
yymsg(0, "Unknown Struct: %s", struct_name.c_str());
out = val_default;
break;
case 2:
out = val_default;
yymsg(0, "Unknown member '%s' of Struct %s", c3, struct_name.c_str());
break;
}
Free(c1); Free(c2);
if (flag_tSTRING_alloc) Free(c3);
return out;
}
int treat_Struct_FullName_dot_tSTRING_Float_getDim int treat_Struct_FullName_dot_tSTRING_Float_getDim
(char* c1, char* c2, char* c3) (char* c1, char* c2, char* c3)
{ {
......
...@@ -101,6 +101,18 @@ public: ...@@ -101,6 +101,18 @@ public:
} }
} }
int getMember_Vector (std::string & key_member, const std::vector<double> * & out_vector) const
{
std::map<std::string, std::vector<double> >::const_iterator
it = _fopt.find(key_member);
if (it != _fopt.end()) {
out_vector = &it->second; return 0;
}
else {
out_vector = NULL; return 1; // Error: Unknown member of Struct
}
}
int getMember_ValMax () const { return _member_ValMax; } int getMember_ValMax () const { return _member_ValMax; }
void sprint(std::string & str, void sprint(std::string & str,
...@@ -340,6 +352,26 @@ public: ...@@ -340,6 +352,26 @@ public:
return 0; // 0: no error return 0; // 0: no error
} }
int getMember_Vector(std::string & key_namespace, std::string & key_name,
std::string & key_member, const std::vector<double> * & out_vector) 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) {
switch (struct_P->getMember_Vector(key_member, out_vector)) {
case 0:
break;
case 1:
out_vector = NULL; return 2; // 2: Error: Unknown member of Struct
break;
}
}
else {
out_vector = NULL; return 1; // 1: Error: Unknown Struct
}
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) const int tag, const std::string * & key_struct) const
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment