void MapWriter::writeToStream(const Model::Map& map, std::ostream& stream) { assert(stream.good()); stream.unsetf(std::ios::floatfield); const Model::EntityList& entities = map.entities(); for (unsigned int i = 0; i < entities.size(); i++) writeEntity(*entities[i], stream); }
void MapWriter::writeToFileAtPath(Model::Map& map, const String& path, bool overwrite) { FileManager fileManager; if (fileManager.exists(path) && !overwrite) return; const String directoryPath = fileManager.deleteLastPathComponent(path); if (!fileManager.exists(directoryPath)) fileManager.makeDirectory(directoryPath); FILE* stream = fopen(path.c_str(), "w"); if (stream == NULL) throw IOException::openError(path); // std::fstream stream(path.c_str(), std::ios::out | std::ios::trunc); size_t lineNumber = 1; const Model::EntityList& entities = map.entities(); for (unsigned int i = 0; i < entities.size(); i++) lineNumber += writeEntity(*entities[i], lineNumber, stream); fclose(stream); }