bool MCSessionWriteIndex(MCSessionIndexRef p_index) { bool t_success = true; t_success = write_uint32(p_index->file, p_index->session_count); for (uint32_t i = 0; t_success && i < p_index->session_count; i++) { t_success = write_cstring(p_index->file, p_index->session[i]->id) && write_cstring(p_index->file, p_index->session[i]->ip) && write_cstring(p_index->file, p_index->session[i]->filename) && write_real64(p_index->file, p_index->session[i]->expires); } return t_success; }
void VoxelFile::save_palette() { if (global_palette == NULL) return; QFile fp(PALETTE_FILE); if (!fp.open(QIODevice::WriteOnly)) return; for (int i = 0; i < 256; i++) fp.write((char*)&global_palette[i], sizeof(RGBColor)); QDataStream stream(&fp); stream.setByteOrder(QDataStream::LittleEndian); for (int i = 0; i < 256; i++) write_cstring(stream, palette_names[i]); fp.close(); }
void VoxelFile::save_fp(QFile & fp) { QDataStream stream(&fp); stream.setByteOrder(QDataStream::LittleEndian); stream << x_size; stream << y_size; stream << z_size; stream << x_offset; stream << y_offset; stream << z_offset; stream.writeRawData((char*)data, x_size * y_size * z_size); stream.writeRawData((char*)global_palette, 256 * 3); stream << quint8(points.size()); ReferencePoints::const_iterator it; for (it = points.begin(); it != points.end(); it++) { const ReferencePoint & point = *it; write_cstring(stream, point.name); stream << point.x; stream << point.y; stream << point.z; } save_palette(); }
void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) { // Get the option groups and options. const std::vector<Record*> &Groups = Records.getAllDerivedDefinitions("OptionGroup"); std::vector<Record*> Opts = Records.getAllDerivedDefinitions("Option"); emitSourceFileHeader("Option Parsing Definitions", OS); array_pod_sort(Opts.begin(), Opts.end(), CompareOptionRecords); // Generate prefix groups. typedef SmallVector<SmallString<2>, 2> PrefixKeyT; typedef std::map<PrefixKeyT, std::string> PrefixesT; PrefixesT Prefixes; Prefixes.insert(std::make_pair(PrefixKeyT(), "prefix_0")); unsigned CurPrefix = 0; for (unsigned i = 0, e = Opts.size(); i != e; ++i) { const Record &R = *Opts[i]; std::vector<std::string> prf = R.getValueAsListOfStrings("Prefixes"); PrefixKeyT prfkey(prf.begin(), prf.end()); unsigned NewPrefix = CurPrefix + 1; if (Prefixes.insert(std::make_pair(prfkey, (Twine("prefix_") + Twine(NewPrefix)).str())).second) CurPrefix = NewPrefix; } // Dump prefixes. OS << "/////////\n"; OS << "// Prefixes\n\n"; OS << "#ifdef PREFIX\n"; OS << "#define COMMA ,\n"; for (PrefixesT::const_iterator I = Prefixes.begin(), E = Prefixes.end(); I != E; ++I) { OS << "PREFIX("; // Prefix name. OS << I->second; // Prefix values. OS << ", {"; for (PrefixKeyT::const_iterator PI = I->first.begin(), PE = I->first.end(); PI != PE; ++PI) { OS << "\"" << *PI << "\" COMMA "; } OS << "0})\n"; } OS << "#undef COMMA\n"; OS << "#endif\n\n"; OS << "/////////\n"; OS << "// Groups\n\n"; OS << "#ifdef OPTION\n"; for (unsigned i = 0, e = Groups.size(); i != e; ++i) { const Record &R = *Groups[i]; // Start a single option entry. OS << "OPTION("; // The option prefix; OS << "0"; // The option string. OS << ", \"" << R.getValueAsString("Name") << '"'; // The option identifier name. OS << ", "<< getOptionName(R); // The option kind. OS << ", Group"; // The containing option group (if any). OS << ", "; if (const DefInit *DI = dyn_cast<DefInit>(R.getValueInit("Group"))) OS << getOptionName(*DI->getDef()); else OS << "INVALID"; // The other option arguments (unused for groups). OS << ", INVALID, 0, 0, 0"; // The option help text. if (!isa<UnsetInit>(R.getValueInit("HelpText"))) { OS << ",\n"; OS << " "; write_cstring(OS, R.getValueAsString("HelpText")); } else OS << ", 0"; // The option meta-variable name (unused). OS << ", 0)\n"; } OS << "\n"; OS << "//////////\n"; OS << "// Options\n\n"; for (unsigned i = 0, e = Opts.size(); i != e; ++i) { const Record &R = *Opts[i]; // Start a single option entry. OS << "OPTION("; // The option prefix; std::vector<std::string> prf = R.getValueAsListOfStrings("Prefixes"); OS << Prefixes[PrefixKeyT(prf.begin(), prf.end())] << ", "; // The option string. write_cstring(OS, R.getValueAsString("Name")); // The option identifier name. OS << ", "<< getOptionName(R); // The option kind. OS << ", " << R.getValueAsDef("Kind")->getValueAsString("Name"); // The containing option group (if any). OS << ", "; if (const DefInit *DI = dyn_cast<DefInit>(R.getValueInit("Group"))) OS << getOptionName(*DI->getDef()); else OS << "INVALID"; // The option alias (if any). OS << ", "; if (const DefInit *DI = dyn_cast<DefInit>(R.getValueInit("Alias"))) OS << getOptionName(*DI->getDef()); else OS << "INVALID"; // The option alias arguments (if any). // Emitted as a \0 separated list in a string, e.g. ["foo", "bar"] // would become "foo\0bar\0". Note that the compiler adds an implicit // terminating \0 at the end. OS << ", "; std::vector<std::string> AliasArgs = R.getValueAsListOfStrings("AliasArgs"); if (AliasArgs.size() == 0) { OS << "0"; } else { OS << "\""; for (size_t i = 0, e = AliasArgs.size(); i != e; ++i) OS << AliasArgs[i] << "\\0"; OS << "\""; } // The option flags. const ListInit *LI = R.getValueAsListInit("Flags"); if (LI->empty()) { OS << ", 0"; } else { OS << ", "; for (unsigned i = 0, e = LI->size(); i != e; ++i) { if (i) OS << " | "; OS << cast<DefInit>(LI->getElement(i))->getDef()->getName(); } } // The option parameter field. OS << ", " << R.getValueAsInt("NumArgs"); // The option help text. if (!isa<UnsetInit>(R.getValueInit("HelpText"))) { OS << ",\n"; OS << " "; write_cstring(OS, R.getValueAsString("HelpText")); } else OS << ", 0"; // The option meta-variable name. OS << ", "; if (!isa<UnsetInit>(R.getValueInit("MetaVarName"))) write_cstring(OS, R.getValueAsString("MetaVarName")); else OS << "0"; OS << ")\n"; } OS << "#endif\n"; }
void EmitOptParser(RecordKeeper &Records, raw_ostream &OS, bool GenDefs) { // Get the option groups and options. const std::vector<Record*> &Groups = Records.getAllDerivedDefinitions("OptionGroup"); std::vector<Record*> Opts = Records.getAllDerivedDefinitions("Option"); if (GenDefs) emitSourceFileHeader("Option Parsing Definitions", OS); else emitSourceFileHeader("Option Parsing Table", OS); array_pod_sort(Opts.begin(), Opts.end(), CompareOptionRecords); if (GenDefs) { OS << "#ifndef OPTION\n"; OS << "#error \"Define OPTION prior to including this file!\"\n"; OS << "#endif\n\n"; OS << "/////////\n"; OS << "// Groups\n\n"; for (unsigned i = 0, e = Groups.size(); i != e; ++i) { const Record &R = *Groups[i]; // Start a single option entry. OS << "OPTION("; // The option string. OS << '"' << R.getValueAsString("Name") << '"'; // The option identifier name. OS << ", "<< getOptionName(R); // The option kind. OS << ", Group"; // The containing option group (if any). OS << ", "; if (const DefInit *DI = dynamic_cast<DefInit*>(R.getValueInit("Group"))) OS << getOptionName(*DI->getDef()); else OS << "INVALID"; // The other option arguments (unused for groups). OS << ", INVALID, 0, 0"; // The option help text. if (!dynamic_cast<UnsetInit*>(R.getValueInit("HelpText"))) { OS << ",\n"; OS << " "; write_cstring(OS, R.getValueAsString("HelpText")); } else OS << ", 0"; // The option meta-variable name (unused). OS << ", 0)\n"; } OS << "\n"; OS << "//////////\n"; OS << "// Options\n\n"; for (unsigned i = 0, e = Opts.size(); i != e; ++i) { const Record &R = *Opts[i]; // Start a single option entry. OS << "OPTION("; // The option string. write_cstring(OS, R.getValueAsString("Name")); // The option identifier name. OS << ", "<< getOptionName(R); // The option kind. OS << ", " << R.getValueAsDef("Kind")->getValueAsString("Name"); // The containing option group (if any). OS << ", "; if (const DefInit *DI = dynamic_cast<DefInit*>(R.getValueInit("Group"))) OS << getOptionName(*DI->getDef()); else OS << "INVALID"; // The option alias (if any). OS << ", "; if (const DefInit *DI = dynamic_cast<DefInit*>(R.getValueInit("Alias"))) OS << getOptionName(*DI->getDef()); else OS << "INVALID"; // The option flags. const ListInit *LI = R.getValueAsListInit("Flags"); if (LI->empty()) { OS << ", 0"; } else { OS << ", "; for (unsigned i = 0, e = LI->size(); i != e; ++i) { if (i) OS << " | "; OS << dynamic_cast<DefInit*>(LI->getElement(i))->getDef()->getName(); } } // The option parameter field. OS << ", " << R.getValueAsInt("NumArgs"); // The option help text. if (!dynamic_cast<UnsetInit*>(R.getValueInit("HelpText"))) { OS << ",\n"; OS << " "; write_cstring(OS, R.getValueAsString("HelpText")); } else OS << ", 0"; // The option meta-variable name. OS << ", "; if (!dynamic_cast<UnsetInit*>(R.getValueInit("MetaVarName"))) write_cstring(OS, R.getValueAsString("MetaVarName")); else OS << "0"; OS << ")\n"; } } }