void Storage::Binary::write_classifier(Classifier::Classifier *classifier) { if(!classifier) { write_mark(none_mark); } else { write_mark(classifier_mark); write_mark(classifier->mark()); classifier->write_binary(this); } }
void write_map(Archive & ar, std::unordered_map<K, T> const& xs) { write_mark(ar, "MAP="); write(ar, xs.size()); for (auto & x: xs) { write(ar, x.first); write(ar, x.second); } write_mark(ar, "END="); }
void Storage::Binary::open_for_writing() { // open/create file file.open(path.c_str(), fstream::out | fstream::binary); // ensure file is ok for writing if(!file.good()) throw runtime_error("Error opening binary file for writing"); // write the file marker so reads can test the file format write_mark(file_mark); }
void Storage::Binary::write_text_pipeline(Preprocessing::Text::TextPipeline *pipeline) { if(!pipeline) { write_mark(none_mark); return; } else { write_mark(text_pipeline_mark); } // tokeniser write_mark(pipeline->tokeniser->mark()); // inplace processors int count = pipeline->processors.size(); write_int(count); for(int i = 0; i < count; i++) write_mark(pipeline->processors[i]->mark()); // token selectors count = pipeline->selectors.size(); write_int(count); for(int i = 0; i < count; i++) write_mark(pipeline->selectors[i]->mark()); // example generator write_mark(pipeline->generator->mark()); }
void write(Archive & ar, Env const& env) { auto ver = current_version; auto verbose = 0; // version write(ar, ver); // nations write_mark(ar, "FACS"); { if (verbose) print("save nations\n"); auto & ps = env.get_cont<Faction>(); // num of nations write(ar, ps.size()); for (auto& p: ps) { // nation id write(ar, p.first); // nation data write(ar, env, p.second); } } // terrain write_mark(ar, "TERS"); { if (verbose) print( "save terrain\n"); write(ar, env.dim); for(Coord j = 0; j < env.dim[1]; ++j) { for(Coord i = 0; i < env.dim[0]; ++i) { auto& x = env.get_terr({i,j}); // terr value write(ar, env, x); } } } // colonies write_mark(ar, "COLS"); { if (verbose) print("save colonies\n"); // write_byte(ar, 'C'); auto& ps = env.get_cont<Colony>(); write(ar, ps.size()); for (auto& p: ps) { auto& x = p.second; if (verbose) print("save colony name = %||\n", x.name); // colony write(ar, x.id); write(ar, x.name); write_reg(ar, x.store); // buildings for (auto& b: x.builds) { if (verbose) print("save building type id = %||\n", b.type->id); // build write(ar, b.type->id); write(ar, b.free_slots); // task write(ar, env, b.task); } // fields write(ar, x.fields.size()); for (auto& f: x.fields) { // field write(ar, env.get_coords(f.get_terr())); write(ar, f.get_proditem()); } // location auto cr = env.get_coords(env.get_terr(x)); write(ar, cr); } } // units write_mark(ar, "UNIS"); { if (verbose) print("save units\n"); auto& ps = env.get_cont<Unit>(); write(ar, ps.size()); for (auto& p: ps) { auto& x = p.second; write(ar, p.first); write(ar, env, x); } } write_mark(ar, "MISC"); if (verbose) print("save misc\n"); // turn info write(ar, env.turn_no); // next id write(ar, env.next_id); // state write(ar, env.state); // current control write(ar, env.get_current_control()); }