// ************************************** // Input Functions // ************************************** void ParseDataFile(ifstream &in, NodeSetPtr NS, EdgeSetPtr ES, TileSetPtr TS, FaceSetPtr FS) { string specifier; while (1) { LoadAlphaString(in, specifier); if (in.eof()) break; if (specifier == "nodeset") { LoadNodes(in, NS); } else if (specifier == "edgeset") { LoadEdges(in, NS, ES, TS); } else if (specifier == "tileset") { Error e("Loading tileset not yet implemented"); throw(e); } else if (specifier == "faceset") { LoadFaces(in, ES, FS); } else { // error, unknown specifier string tmp("Unknown specifier: "); tmp.append(specifier); Error e(tmp); throw(e); } } }; unsigned int LoadNodes(ifstream &in, NodeSetPtr nodes) throw (Error){ unsigned int count = 0; if (!GetAndDiscard(in, '{')) { Error e("Missing brace in node definition"); throw(e); } string specifier; while (!GetAndDiscard(in, '}')) { LoadAlphaString(in, specifier); if (in.eof()) { Error e("Unexpected end of file in nodeset"); throw(e); } if (specifier == "node") { new Node(in, nodes); ++count; } else { Error e("Non node definition within nodeset"); throw(e); } } return count; }; unsigned int LoadEdges(ifstream &in, NodeSetPtr validNodes, EdgeSetPtr edges, TileSetPtr tiles) { unsigned int count = 0; if (!GetAndDiscard(in, '{')) { Error e("Missing brace in edge definition"); throw(e); } string specifier; while (!GetAndDiscard(in, '}')) { LoadAlphaString(in, specifier); if (in.eof()) { Error e("Unexpected end of file in edgeset"); throw(e); } if (specifier == "edge") { new Edge(in, validNodes, edges); ++count; } else { Error e("Non edge definition within edgeset"); throw(e); } } // now that we have loaded all the edges in this set, work out all the tiles that these create CalculateTileSet(edges, tiles); return count; }; unsigned int LoadFaces(ifstream &in, EdgeSetPtr validEdges, FaceSetPtr faces) { unsigned int count = 0; if (!GetAndDiscard(in, '{')) { Error e("Missing brace in face definition"); throw(e); } string specifier; while (!GetAndDiscard(in, '}')) { LoadAlphaString(in, specifier); if (in.eof()) { Error e("Unexpected end of file in faceset"); throw(e); } if (specifier == "face") { new Face(in, validEdges, faces); ++count; } else { Error e("Non edge definition within edgeset"); throw(e); } } return count; };