Skip to content
Snippets Groups Projects
Commit 4c541895 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

use for_each like Real Men(tm) do
parent 0e5a7d87
No related branches found
No related tags found
No related merge requests found
// $Id: gmshModel.cpp,v 1.20 2006-10-10 00:44:41 geuzaine Exp $ // $Id: gmshModel.cpp,v 1.21 2006-10-14 21:13:50 geuzaine Exp $
// //
// Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
// //
...@@ -124,10 +124,11 @@ void gmshModel::import() ...@@ -124,10 +124,11 @@ void gmshModel::import()
Msg(DEBUG, "%d Regions", regions.size()); Msg(DEBUG, "%d Regions", regions.size());
} }
static FILE *geo = 0;
class writeGVertexGEO { class writeGVertexGEO {
private :
FILE *geo;
public : public :
writeGVertexGEO(FILE *fp) { geo = fp ? fp : stdout; }
void operator() (GVertex *gv) void operator() (GVertex *gv)
{ {
Vertex *v = (Vertex*)gv->getNativePtr(); Vertex *v = (Vertex*)gv->getNativePtr();
...@@ -137,7 +138,10 @@ class writeGVertexGEO { ...@@ -137,7 +138,10 @@ class writeGVertexGEO {
}; };
class writeGEdgeGEO { class writeGEdgeGEO {
private :
FILE *geo;
public : public :
writeGEdgeGEO(FILE *fp) { geo = fp ? fp : stdout; }
void operator () (GEdge *ge) void operator () (GEdge *ge)
{ {
Curve *c = (Curve *)ge->getNativePtr(); Curve *c = (Curve *)ge->getNativePtr();
...@@ -212,7 +216,10 @@ class writeGEdgeGEO { ...@@ -212,7 +216,10 @@ class writeGEdgeGEO {
}; };
class writeGFaceGEO { class writeGFaceGEO {
private :
FILE *geo;
public : public :
writeGFaceGEO(FILE *fp) { geo = fp ? fp : stdout; }
void operator () (GFace *gf) void operator () (GFace *gf)
{ {
Surface *s = (Surface *)gf->getNativePtr(); Surface *s = (Surface *)gf->getNativePtr();
...@@ -290,7 +297,10 @@ class writeGFaceGEO { ...@@ -290,7 +297,10 @@ class writeGFaceGEO {
}; };
class writeGRegionGEO { class writeGRegionGEO {
private :
FILE *geo;
public : public :
writeGRegionGEO(FILE *fp) { geo = fp ? fp : stdout; }
void operator () (GRegion *gr) void operator () (GRegion *gr)
{ {
Volume *vol = (Volume *)gr->getNativePtr(); Volume *vol = (Volume *)gr->getNativePtr();
...@@ -320,51 +330,43 @@ class writeGRegionGEO { ...@@ -320,51 +330,43 @@ class writeGRegionGEO {
} }
}; };
void writePhysicalGroupGEO(void *a, void *b) class writePhysicalGroupGEO {
private :
FILE *geo;
int dim;
public :
writePhysicalGroupGEO(FILE *fp, int i) : dim(i) { geo = fp ? fp : stdout; }
void operator () (std::pair<const int, std::vector<GEntity *> > &g)
{ {
PhysicalGroup *pg = *(PhysicalGroup **) a; switch (dim) {
case 0: fprintf(geo, "Physical Point"); break;
switch (pg->Typ) { case 1: fprintf(geo, "Physical Line"); break;
case MSH_PHYSICAL_POINT: case 2: fprintf(geo, "Physical Surface"); break;
fprintf(geo, "Physical Point (%d) = ", pg->Num); case 3: fprintf(geo, "Physical Volume"); break;
break;
case MSH_PHYSICAL_LINE:
fprintf(geo, "Physical Line (%d) = ", pg->Num);
break;
case MSH_PHYSICAL_SURFACE:
fprintf(geo, "Physical Surface (%d) = ", pg->Num);
break;
case MSH_PHYSICAL_VOLUME:
fprintf(geo, "Physical Volume (%d) = ", pg->Num);
break;
} }
fprintf(geo, " (%d) = {", g.first);
for(int i = 0; i < List_Nbr(pg->Entities); i++) { for(unsigned int i = 0; i < g.second.size(); i++) {
int j; if(i) fprintf(geo, ", ");
List_Read(pg->Entities, i, &j); fprintf(geo, "%d", g.second[i]->tag());
if(i)
fprintf(geo, ", %d", j);
else
fprintf(geo, "{%d", j);
} }
fprintf(geo, "};\n"); fprintf(geo, "};\n");
} }
};
int gmshModel::writeGEO(const std::string &name) int gmshModel::writeGEO(const std::string &name)
{ {
geo = fopen(name.c_str(), "w"); FILE *fp = fopen(name.c_str(), "w");
if(!geo){
Msg(GERROR, "Unable to open file '%s'", name.c_str());
return 0;
}
std::for_each(firstVertex(), lastVertex(), writeGVertexGEO()); std::for_each(firstVertex(), lastVertex(), writeGVertexGEO(fp));
std::for_each(firstEdge(), lastEdge(), writeGEdgeGEO()); std::for_each(firstEdge(), lastEdge(), writeGEdgeGEO(fp));
std::for_each(firstFace(), lastFace(), writeGFaceGEO()); std::for_each(firstFace(), lastFace(), writeGFaceGEO(fp));
std::for_each(firstRegion(), lastRegion(), writeGRegionGEO()); std::for_each(firstRegion(), lastRegion(), writeGRegionGEO(fp));
List_Action(THEM->PhysicalGroups, writePhysicalGroupGEO); std::map<int, std::vector<GEntity*> > groups[4];
getPhysicalGroups(groups);
for(int i = 0; i < 4; i++)
std::for_each(groups[i].begin(), groups[i].end(), writePhysicalGroupGEO(fp, i));
fclose(geo); if(fp) fclose(fp);
return 1; return 1;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment