16 #ifndef _MESH_READER_H2D_BSON_H_
17 #define _MESH_READER_H2D_BSON_H_
19 #include "mesh_reader.h"
42 class HERMES_API MeshReaderH2DBSON :
public MeshReader
46 virtual ~MeshReaderH2DBSON();
49 virtual void load(
const char *filename, MeshSharedPtr mesh);
52 void save(
const char *filename, MeshSharedPtr mesh);
57 void load(
const char *filename, std::vector<MeshSharedPtr> meshes);
60 void save(
const char *filename, std::vector<MeshSharedPtr> meshes);
66 vertex_BSON(
double x,
double y,
int i) : x(x), y(y), i(i) {}
67 void save_to_BSON(bson& bw)
69 bson_append_start_object(&bw,
"vertex");
70 bson_append_double(&bw,
"x", x);
71 bson_append_double(&bw,
"y", y);
72 bson_append_int(&bw,
"i", i);
73 bson_append_finish_object(&bw);
75 void load_from_BSON(bson& sub)
78 bson_find(&sub_it, &sub,
"x");
79 this->x = bson_iterator_double(&sub_it);
80 bson_find(&sub_it, &sub,
"y");
81 this->y = bson_iterator_double(&sub_it);
82 bson_find(&sub_it, &sub,
"i");
83 this->i = bson_iterator_int(&sub_it);
93 edge_BSON(
int v1,
int v2,
std::string marker,
int i) : v1(v1), v2(v2), marker(marker), i(i) {}
94 void save_to_BSON(bson& bw)
96 bson_append_start_object(&bw,
"edge");
97 bson_append_int(&bw,
"v1", v1);
98 bson_append_int(&bw,
"v2", v2);
99 bson_append_string(&bw,
"marker", marker.c_str());
100 bson_append_int(&bw,
"i", i);
101 bson_append_finish_object(&bw);
103 void load_from_BSON(bson& sub)
105 bson_iterator sub_it;
106 bson_find(&sub_it, &sub,
"v1");
107 this->v1 = bson_iterator_int(&sub_it);
108 bson_find(&sub_it, &sub,
"v2");
109 this->v2 = bson_iterator_int(&sub_it);
110 bson_find(&sub_it, &sub,
"marker");
111 this->marker = bson_iterator_string(&sub_it);
112 bson_find(&sub_it, &sub,
"i");
113 this->i = bson_iterator_int(&sub_it);
124 element_BSON(
int v1,
int v2,
int v3,
int v4,
std::string marker,
int i) : v1(v1), v2(v2), v3(v3), v4(v4), marker(marker), i(i) {}
125 void save_to_BSON(bson& bw)
127 bson_append_start_object(&bw,
"element");
128 bson_append_int(&bw,
"v1", v1);
129 bson_append_int(&bw,
"v2", v2);
130 bson_append_int(&bw,
"v3", v3);
131 bson_append_int(&bw,
"v4", v4);
132 bson_append_string(&bw,
"marker", marker.c_str());
133 bson_append_int(&bw,
"i", i);
134 bson_append_finish_object(&bw);
136 void load_from_BSON(bson& sub)
138 bson_iterator sub_it;
139 bson_find(&sub_it, &sub,
"v1");
140 this->v1 = bson_iterator_int(&sub_it);
141 bson_find(&sub_it, &sub,
"v2");
142 this->v2 = bson_iterator_int(&sub_it);
143 bson_find(&sub_it, &sub,
"v3");
144 this->v3 = bson_iterator_int(&sub_it);
145 bson_find(&sub_it, &sub,
"v4");
146 this->v4 = bson_iterator_int(&sub_it);
147 bson_find(&sub_it, &sub,
"marker");
148 this->marker = bson_iterator_string(&sub_it);
149 bson_find(&sub_it, &sub,
"i");
150 this->i = bson_iterator_int(&sub_it);
163 arc_BSON(
int p1,
int p2,
double angle) : p1(p1), p2(p2), angle(angle) {}
164 void save_to_BSON(bson& bw)
166 bson_append_start_object(&bw,
"arc");
167 bson_append_int(&bw,
"p1", p1);
168 bson_append_int(&bw,
"p2", p2);
169 bson_append_double(&bw,
"angle", angle);
170 bson_append_finish_object(&bw);
172 void load_from_BSON(bson& sub)
174 bson_iterator sub_it;
175 bson_find(&sub_it, &sub,
"p1");
176 this->p1 = bson_iterator_int(&sub_it);
177 bson_find(&sub_it, &sub,
"p2");
178 this->p2 = bson_iterator_int(&sub_it);
179 bson_find(&sub_it, &sub,
"angle");
180 this->angle = bson_iterator_double(&sub_it);
187 struct refinement_BSON
190 refinement_BSON(
int id,
int type) : id(id), type(type) {}
191 void save_to_BSON(bson& bw)
193 bson_append_start_object(&bw,
"refinement");
194 bson_append_int(&bw,
"id",
id);
195 bson_append_int(&bw,
"type",
type);
196 bson_append_finish_object(&bw);
198 void load_from_BSON(bson& sub)
200 bson_iterator sub_it;
201 bson_find(&sub_it, &sub,
"id");
202 this->
id = bson_iterator_int(&sub_it);
203 bson_find(&sub_it, &sub,
"type");
204 this->
type = bson_iterator_int(&sub_it);
210 struct subdomain_BSON
212 void save_to_BSON(bson& bw)
214 bson_append_start_object(&bw,
"subdomain");
216 bson_append_start_array(&bw,
"vertices");
217 for (
int i = 0; i < vertices.size(); i++)
218 bson_append_int(&bw,
"i", vertices[i]);
219 bson_append_finish_array(&bw);
222 bson_append_start_array(&bw,
"elements");
223 for (
int i = 0; i < elements.size(); i++)
224 bson_append_int(&bw,
"i", elements[i]);
225 bson_append_finish_array(&bw);
228 bson_append_start_array(&bw,
"boundary_edges");
229 for (
int i = 0; i < boundary_edges.size(); i++)
230 bson_append_int(&bw,
"i", boundary_edges[i]);
231 bson_append_finish_array(&bw);
234 bson_append_start_array(&bw,
"inner_edges");
235 for (
int i = 0; i < inner_edges.size(); i++)
236 bson_append_int(&bw,
"i", inner_edges[i]);
237 bson_append_finish_array(&bw);
240 bson_append_start_array(&bw,
"refinements");
241 for (
int i = 0; i < refinements.size(); i++)
242 refinements[i].save_to_BSON(bw);
243 bson_append_finish_array(&bw);
245 bson_append_finish_object(&bw);
247 void load_from_BSON(bson& sub)
250 bson_iterator sub_it, sub_sub_it;
252 bson_find(&sub_it, &sub,
"vertices");
253 bson_iterator_subobject_init(&sub_it, &sub_sub, 0);
254 bson_iterator_init(&sub_sub_it, &sub_sub);
255 while (bson_iterator_next(&sub_sub_it))
256 this->vertices.push_back(bson_iterator_int(&sub_sub_it));
259 bson_find(&sub_it, &sub,
"elements");
260 bson_iterator_subobject_init(&sub_it, &sub_sub, 0);
261 bson_iterator_init(&sub_sub_it, &sub_sub);
262 while (bson_iterator_next(&sub_sub_it))
263 this->elements.push_back(bson_iterator_int(&sub_sub_it));
266 bson_find(&sub_it, &sub,
"boundary_edges");
267 bson_iterator_subobject_init(&sub_it, &sub_sub, 0);
268 bson_iterator_init(&sub_sub_it, &sub_sub);
269 while (bson_iterator_next(&sub_sub_it))
270 this->boundary_edges.push_back(bson_iterator_int(&sub_sub_it));
273 bson_find(&sub_it, &sub,
"inner_edges");
274 bson_iterator_subobject_init(&sub_it, &sub_sub, 0);
275 bson_iterator_init(&sub_sub_it, &sub_sub);
276 while (bson_iterator_next(&sub_sub_it))
277 this->inner_edges.push_back(bson_iterator_int(&sub_sub_it));
280 bson_find(&sub_it, &sub,
"refinements");
281 bson_iterator_subobject_init(&sub_it, &sub_sub, 0);
282 bson_iterator_init(&sub_sub_it, &sub_sub);
284 while (bson_iterator_next(&sub_sub_it))
286 refinement_BSON refinement;
287 bson_iterator_subobject_init(&sub_sub_it, &b_sub_sub, 0);
288 refinement.load_from_BSON(b_sub_sub);
289 this->refinements.push_back(refinement);
292 std::vector<int> vertices;
293 std::vector<int> elements;
294 std::vector<int> boundary_edges;
295 std::vector<int> inner_edges;
296 std::vector<refinement_BSON> refinements;
299 static bool elementCompare(element_BSON el_i, element_BSON el_j) {
return (el_i.i < el_j.i); }
301 void load_domain(bson& br, MeshSharedPtr mesh, std::map<int, int>& vertex_is, std::map<int, int>& element_is, std::map<int, int>& edge_is,
302 std::vector<element_BSON>& elements, std::vector<edge_BSON>& edges, std::vector<vertex_BSON>& vertices, std::vector<arc_BSON>& arcs, std::vector<subdomain_BSON>& subdomains);
::xsd::cxx::tree::id< char, ncname > id
C++ type corresponding to the ID XML Schema built-in type.
::xsd::cxx::tree::type type
C++ type corresponding to the anyType XML Schema built-in type.
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.