uint32_t AsmFunc::write(ostream &out) const { out.write((const char *) name.index, 2); out.write((const char *) doc.index, 2); out.write((const char *) (&line_no), 2); if (ctx) { out.write((const char *) ctx->index, 2); } else { uint16_t zero(0); out.write((const char *) &zero, 2); } out.write((const char *) param_types.index, 2); out.write((const char *) result_type.index, 2); out.put(this->fcontext); out.put(argc); out.put(regc); out.put('\0'); uint32_t func_size(FunctionHeader::SIZE); AsmParamList::const_iterator pit(params.begin()); for (; pit!=params.end(); ++pit) { out.write((const char *) (*pit)->name.index, 2); out.write((const char *) (*pit)->type.index, 2); func_size += 4; } codeblock::const_iterator ci(code.begin()); for (; ci!=code.end(); ++ci) { uint8_t isize(write_instruction(out, **ci)); func_size += isize; } return func_size; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Properties::save(ostream& out) const { // Write out each of the key and value pairs bool changed = false; for(int i = 0; i < LastPropType; ++i) { // Try to save some space by only saving the items that differ from default if(myProperties[i] != ourDefaultProperties[i]) { writeQuotedString(out, ourPropertyNames[i]); out.put(' '); writeQuotedString(out, myProperties[i]); out.put('\n'); changed = true; } } if(changed) { // Put a trailing null string so we know when to stop reading writeQuotedString(out, ""); out.put('\n'); out.put('\n'); } }
//--------------------------------------------------------------------------------- // Function: boxLine() // Title: Box Line // Description: // draws a a line of text aligned in the middle of the box // Programmer: Paul Bladek // // Date: 10/3/2006 // // Version: 1.01 // // Environment: Hardware: i3 // Software: OS: Windows 7; // Compiles under Microsoft Visual C++ 2012 // // Output: Formatted text to sout // // Called By: header() // endbox() // // Parameters: sout: ostream&; stream to print to // text: const string&; text to print // length: unsigned short; length of the box // alignment: unsigned char; 'L' (left), 'C'(center),'R'(right) // fillc: char; fill character // // Returns: void // // History Log: // 10/3/2006 PB completed v 1.01 // //--------------------------------------------------------------------------------- void boxLine(ostream& sout, const string& text, unsigned short length, unsigned char alignment, char fillc) { long originalformat = sout.flags(); // saves original format alignment = toupper(alignment); if(alignment != LEFT && alignment != RIGHT && alignment != CENTER) throw exception(); if(length > MAX_LINE_LENGTH) length = MAX_LINE_LENGTH; sout << setfill(fillc); // change fill character sout.put(VERT); if(alignment == CENTER) { sout << setw((length + static_cast<streamsize>(text.length())) / 2 - 1) << text << setw((length - static_cast<streamsize>(text.length())) / 2 - 1) << fillc; if(text.length() % 2 == 0) sout << fillc; } else { if(alignment == LEFT) sout << left; sout << setw(length - OFFSET) << text; } sout.flags(originalformat); // reset flags sout.put(VERT); sout << endl; }
void Alg_smf_write::write_update(Alg_update_ptr update) { char *name = update->parameter.attr_name(); /****Non-Meta Events****/ if (!strcmp(name, "pressurer")) { write_delta(update->time); if (update->get_identifier() < 0) { // channel pressure message out_file->put(0xD0 + to_midi_channel(update->chan)); write_data((int)(update->parameter.r * 127)); } else { // just 1 key -- poly pressure out_file->put(0xA0 + to_midi_channel(update->chan)); write_data(update->get_identifier()); write_data((int)(update->parameter.r * 127)); } } else if (!strcmp(name, "programi")) { write_delta(update->time); out_file->put(0xC0 + to_midi_channel(update->chan)); write_data(update->parameter.i); } else if (!strcmp(name, "bendr")) { int temp = ROUND(0x2000 * (update->parameter.r + 1)); if (temp > 0x3fff) temp = 0x3fff; // 14 bits maximum if (temp < 0) temp = 0; int c1 = temp & 0x7F; // low 7 bits int c2 = temp >> 7; // high 7 bits write_delta(update->time); out_file->put(0xE0 + to_midi_channel(update->chan)); write_data(c1); write_data(c2); } else if (!strncmp(name, "control", 7) &&
void Image::writePPM(ostream& o) { o << "P6\n"; o << mWidth << ' ' << mHeight << '\n'; o << "255\n"; int i, j; unsigned int ired, igreen, iblue; unsigned char red, green, blue; for (i = mHeight - 1; i >= 0; i--) { for (j = 0; j < mWidth;++j) { ired = (unsigned int)(256 * mRaster[j][i].r()); igreen = (unsigned int)(256 * mRaster[j][i].g()); iblue = (unsigned int)(256 * mRaster[j][i].b()); if (ired > 255) ired = 255; if (igreen > 255) igreen = 255; if (iblue > 255) iblue = 255; red = (unsigned char)ired; green = (unsigned char)igreen; blue = (unsigned char)iblue; o.put(red); o.put(green); o.put(blue); } } }
FIT_UINT8 FieldDefinition::Write(ostream &file) { file.put(num); file.put(size); file.put(type); return 3; }
void Alg_smf_write::write_smpteoffset(Alg_update_ptr update, char *s) { write_midi_channel_prefix(update); write_delta(update->time); out_file->put(0xFF); // meta event out_file->put(0x54); // smpte offset type code out_file->put(5); // length for (int i = 0; i < 5; i++) *out_file << s[i]; }
void Alg_smf_write::write_text(Alg_update_ptr update, char type) { write_midi_channel_prefix(update); write_delta(update->time); out_file->put(0xFF); out_file->put(type); out_file->put((char) strlen(update->parameter.s)); *out_file << update->parameter.s; }
//--------------------------------------------------------------------------------- // Function: boxBottom() // Title: Box Bottom // Description: // draws a a line for the bottom of the box // Programmer: Paul Bladek // // Date: 10/3/2006 // // Version: 1.01 // // Environment: Hardware: i3 // Software: OS: Windows 7; // Compiles under Microsoft Visual C++ 2012 // // Output: Formatted line to sout // // Called By: header() // endbox() // // Parameters: sout: ostream&; stream to print to // ength: unsigned short; length of the box // // Returns: void // // History Log: // 10/3/2006 PB completed v 1.01 // //--------------------------------------------------------------------------------- void boxBottom(ostream& sout, unsigned short length) { if(length > MAX_LINE_LENGTH) length = MAX_LINE_LENGTH; sout.put(LL); for(int i = 0; i < length - OFFSET; i++) sout.put(HORIZ); sout.put(LR); sout << endl; }
void Alg_smf_write::write_binary(int type_byte, char *msg) { int len = strlen(msg) / 2; out_file->put(type_byte); write_varinum(len); for (int i = 0; i < len; i++) { out_file->put(hex_to_char(msg)); msg += 2; } }
void write_delimited(ostream& os, const string& s) /* PURPOSE: write a "" delimited string (including spaces) to a stream. Embedded " and \ are quoted by \ */ { os.put('"'); for (unsigned i = 0; i < s.length(); i++) { char ch = s[i]; if (ch == '"' || ch == '\\') os.put('\\'); os.put(ch); } os.put('"'); }
void writePPM(ostream& out,int **raster,int ny,int nx) { //output header out << "P6\n"; out << nx <<' '<< ny << '\n'; out << "255\n"; for(int i=ny-1;i>=0;i--) for(int j=0;j<nx;j++){ out.put(raster[j][i]); out.put(raster[j][i]); out.put(raster[j][i]); } }
void Alg_smf_write::write_midi_channel_prefix(Alg_update_ptr update) { if (update->chan >= 0) { // write MIDI Channel Prefix write_delta(update->time); out_file->put(0xFF); // Meta Event out_file->put(0x20); // Type code for MIDI Channel Prefix out_file->put(1); // length out_file->put(to_midi_channel(update->chan)); // one thing odd about the Std MIDI File spec is that once // you turn on MIDI Channel Prefix, there seems to be no // way to cancel it unless a non-Meta event shows up. We // don't do any analysis to avoid assigning channels to // meta events. } }
void Engine::Crypt(istream& I, ostream& O, bool unwrapFlag) { vector<thread> threads; vector<ostream&> Os; if (phase != fresh) throw Exception("The phase must be fresh to call Engine::Crypt()."); for(unsigned int i=0; i<Pi; i++) { // Pistons[i].Crypt(I, O, Et[i], unwrapFlag); stringstream stream; Os.push_back(stream); threads.push_back(thread(&Piston::Crypt, &Pistons[i], I, Os.at[i], Et[i], unwrapFlag)); } for(unsigned int i=0; i<Pi; i++) { threads.at(i).join(); O.put(Os.at(i).str()); } if (hasMore(I)) phase = crypted; else phase = endOfCrypt; }
void Engine::GetTags(ostream& T, const vector<unsigned int>& l) { vector<thread> threads; vector<stringstream> Ts; if (phase != endOfMessage) throw Exception("The phase must be endOfMessage to call Engine::GetTags()."); Spark(true, l); for(unsigned int i=0; i<Pi; i++) { // Pistons[i].GetTag(T, l[i]); stringstream stream; Ts.push_back(stream); threads.push_back(thread(&Piston::GetTag, &Pistons[i], Ts.at(i), l[i])); } for(unsigned int i=0; i<Pi; i++) { threads.at(i).join(); T.put(Ts.at(i).str()); } phase = fresh; }
void OutputStreamHelper::WriteObject(ostream& stream, T value) { for (uint32_t size = sizeof(T); size > 0; --size, value >>= 8) { stream.put(static_cast<char>(value & 0xFF)); } }
void Piston::GetTag(ostream& T, unsigned int l) const { if (l > Rs) throw Exception("The requested tag is too long."); for(unsigned int i=0; i<l; i++) T.put(state.get()[i]); }
//------------------------------------------------------------------------// bool TokenFile::Write(ostream &Output, TokenList* pTokenList, DWORD dwFlags) { Clear(); if(dwFlags & TF_CASE_SENSITIVE) m_bCaseSensitive = true; else m_bCaseSensitive = false; // clear the queue while(!m_queBuffer.empty()) m_queBuffer.pop(); m_pTokenList = pTokenList; WriteHeader(); GenerateTables(); WriteTables(); WriteTokens(); while(!m_queBuffer.empty()) { Output.put(m_queBuffer.front()); m_queBuffer.pop(); } Output.flush(); return true; }
// write_data - limit data to the range of [0...127] and write it void Alg_smf_write::write_data(int data) { if (data < 0) data = 0; else if (data > 0x7F) data = 0x7F; out_file->put(data); }
void print (ostream& out = cout) const { out << name << ":\n" << from.name << " ----> "; for (size_t i = 0; i < to.size(); ++i) out << to[i].name << ((i == to.size() - 1) ? "" : ", "); out.put('\n'); }
void decodeData(ibitstream& input, HuffmanNode* encodingTree, ostream& output) { int bit; HuffmanNode* curr = encodingTree; while ((bit = input.readBit()) != -1) { if (bit == 0 && curr->zero != NULL) curr = curr->zero; else if (bit == 1 && curr->one != NULL) curr = curr->one; else if (bit == 0 && curr->zero == NULL) { output.put(curr->character); curr = encodingTree->zero; } else { output.put(curr->character); curr = encodingTree->one; } } }
void ast_node::output_at_level(ostream& stream,int level) const { stream.width(4); stream << _lineno << ' '; for (int i = 0;i < level;++i) stream.put('\t'); output_impl(stream,level+1); }
int printVLE(tick_t value, ostream& out) { if (value == 0) { out.put('\0'); return 1; } vector<uint8_t> deltav; while (value > 0) { deltav.push_back(value & 0x7F); value >>= 7; } reverse(deltav.begin(), deltav.end()); for (int i = 0; i < ((int) deltav.size()) - 1; ++i) deltav[i] = (deltav[i] | 0x80); for (unsigned i = 0; i < deltav.size(); ++i) out.put((char) deltav[i]); return deltav.size(); }
// writes byte as 1 and 0 chars to ostream if DEBUG is true, // otherwise a byte to file void Bitstream::write_byte(const unsigned char byte, ostream &out){ if(DEBUG){ unsigned char b = byte; unsigned char mask = 1 << 7; for(char i=0; i<BYTE_SIZE; i++){ if((b & mask) == mask){ out.put(ONE); }else{ out.put(ZERO); } //if(i < (BYTE_SIZE-1) ) b = b << 1; } } else { out.put(byte); } }
void decodeData(ibitstream& input, HuffmanNode* encodingTree, ostream& output) { while (true) { int character = getCharacter(input, encodingTree); if (character == NOT_A_CHAR || input.tellg() == -1) return; output.put(character); } }
void ast_relational_expression_node::output_impl(ostream& stream,int nlevel) const { stream << "relational-expression\n"; _operands[0].node->output_at_level(stream,nlevel); for (int cnt = 0;cnt < nlevel;++cnt) stream.put('\t'); stream << *_operator << '\n'; _operands[1].node->output_at_level(stream,nlevel); }
/*! * \brief Saves the field (specified when constructing the object) to the * specified \a stream (makes a "SimpleTag" element). * * \throws Throws std::ios_base::failure when an IO error occurs. * \throws Throws Assumes the data is already validated and thus does NOT * throw TagParser::Failure or a derived exception. */ void MatroskaTagFieldMaker::make(ostream &stream) const { BinaryWriter writer(&stream); char buff[8]; // write header of "SimpleTag" element writer.writeUInt16BE(MatroskaIds::SimpleTag); byte sizeDenotationLen = EbmlElement::makeSizeDenotation(m_simpleTagSize, buff); stream.write(buff, sizeDenotationLen); // write header of "TagName" element writer.writeUInt16BE(MatroskaIds::TagName); sizeDenotationLen = EbmlElement::makeSizeDenotation(m_field.id().size(), buff); stream.write(buff, sizeDenotationLen); stream.write(m_field.id().c_str(), m_field.id().size()); // write header of "TagLanguage" element writer.writeUInt16BE(MatroskaIds::TagLanguage); if (m_field.value().language().empty()) { stream.put(static_cast<ostream::char_type>(0x80 | 3)); stream.write("und", 3); } else { sizeDenotationLen = EbmlElement::makeSizeDenotation(m_field.value().language().size(), buff); stream.write(buff, sizeDenotationLen); stream.write(m_field.value().language().c_str(), m_field.value().language().size()); } // write header of "TagDefault" element writer.writeUInt16BE(MatroskaIds::TagDefault); stream.put(static_cast<ostream::char_type>(0x80 | 1)); stream.put(m_field.isDefault() ? 1 : 0); // write header of "TagString"/"TagBinary" element if (m_isBinary) { writer.writeUInt16BE(MatroskaIds::TagBinary); sizeDenotationLen = EbmlElement::makeSizeDenotation(m_field.value().dataSize(), buff); stream.write(buff, sizeDenotationLen); stream.write(m_field.value().dataPointer(), m_field.value().dataSize()); } else { writer.writeUInt16BE(MatroskaIds::TagString); sizeDenotationLen = EbmlElement::makeSizeDenotation(m_stringValue.size(), buff); stream.write(buff, sizeDenotationLen); stream.write(m_stringValue.data(), m_stringValue.size()); } // make nested tags for (const auto &maker : m_nestedMaker) { maker.make(stream); } }
void bilou_ner_trainer::train(ner_id id, int stages, const network_parameters& parameters, const tagger& tagger, istream& features, istream& train, istream& heldout, ostream& os) { if (stages <= 0) runtime_failure("Cannot train NER with <= 0 stages!"); if (stages >= 256) runtime_failure("Cannot train NER with >= 256 stages!"); // Load training and possibly also heldout data entity_map entities; vector<labelled_sentence> train_data; cerr << "Loading train data: "; load_data(train, tagger, train_data, entities, true); cerr << "done, " << train_data.size() << " sentences" << endl; cerr << "Found " << entities.size() << " annotated entity types." << endl; vector<labelled_sentence> heldout_data; if (heldout) { cerr << "Loading heldout data: "; load_data(heldout, tagger, heldout_data, entities, false); cerr << "done, " << heldout_data.size() << " sentences" << endl; } // Parse feature templates feature_templates templates; unique_ptr<tokenizer> tokenizer(bilou_ner::new_tokenizer(id)); cerr << "Parsing feature templates: "; templates.parse(features, entities, nlp_pipeline(tokenizer.get(), &tagger)); cerr << "done" << endl; // Train required number of stages vector<network_classifier> networks(stages); for (auto&& network : networks) { // Generate features cerr << "Generating features: "; vector<classifier_instance> train_instances, heldout_instances; generate_instances(train_data, templates, train_instances, true); generate_instances(heldout_data, templates, heldout_instances, false); cerr << "done" << endl; // Train and encode the recognizer cerr << "Training network classifier." << endl; if (!network.train(templates.get_total_features(), bilou_entity::total(entities.size()), train_instances, heldout_instances, parameters, true)) runtime_failure("Cannot train the network classifier!"); // Use the trained classifier to compute previous_stage compute_previous_stage(train_data, templates, network); compute_previous_stage(heldout_data, templates, network); } // Encode the recognizer cerr << "Encoding the recognizer." << endl; if (!entities.save(os)) runtime_error("Cannot save entity map!"); if (!templates.save(os)) runtime_error("Cannot save feature templates!"); if (!os.put(stages)) runtime_error("Cannot save number of stages!"); for (auto&& network : networks) if (!network.save(os)) runtime_error("Cannot save classifier network!"); }
void ast_multiplicative_expression_node::output_impl(ostream& stream,int nlevel) const { deque<operand>::size_type i = 0, j = 0; stream << "multiplicative-expression\n"; while (j < _operators.size()) { _operands[i++].node->output_at_level(stream,nlevel); for (int cnt = 0;cnt < nlevel;++cnt) stream.put('\t'); stream << *_operators[j++] << '\n'; } _operands[i].node->output_at_level(stream,nlevel); }
/* Prints out this node and its children to the named output * stream, to the specified level of indentation. */ void plainTextOut(ostream& out, int indent) { out << label; for (vector<ParseTree*>::iterator iter = children.begin(); iter != children.end(); ++iter) { out << endl; for (int i=0; i<indent; ++i) out.put(' '); out << "( "; (*iter)->plainTextOut(out, indent + 2); out << " )"; } }