void MachineAST::generate() { StateMachine* machine_ptr = new StateMachine(*m_ident_ptr, getLocation(), getPairs()); g_sym_table.newSym(machine_ptr); // Make a new frame g_sym_table.pushFrame(); // Create a new machine g_sym_table.newCurrentMachine(machine_ptr); // Setup the "id" variable Type* type_ptr = g_sym_table.getType("NodeID"); if (type_ptr == NULL) { error("Type 'NodeID' not declared."); } g_sym_table.newTempSym(new Var("id", getLocation(), type_ptr, "m_id", getPairs())); // Generate code for all the internal decls m_decl_list_ptr->generate(); // Build the transition table machine_ptr->buildTable(); // Pop the frame g_sym_table.popFrame(); }
bool ofxTLVideoDepthAlignmentScrubber::mousePressed(ofMouseEventArgs& args, long millis){ cout << "mouse pressed in depth align. active? " << isActive() << endl; if(!isActive()){ return false; } vector<VideoDepthPair>& alignedFrames = getPairs(); for(int i = 0; i < alignedFrames.size(); i++){ // long videoMillis; // if(depthSequence->doFramesHaveTimestamps()){ //// videoMillis = videoSequence->getPlayer()->getTotalNumFrames() * alignedFrames[i].videoMillis / (videoSequence->getPlayer()->getDuration()*1000.0); // float videoPercent = alignedFrames[i].videoMillis / (videoSequence->getPlayer()->getDuration()*1000.0); // videoMillis = videoPercent * videoSequence->getPlayer()->getTotalNumFrames(); // } // else{ // videoMillis = alignedFrames[i].videoMillis; // } int screenX = millisToScreenX( alignedFrames[i].videoMillis ); cout << "clicked on x " << screenX << " for vidoe millis " << alignedFrames[i].videoMillis << " mouse x is " << args.x << endl; if(abs(args.x - screenX) < 5){ cout << " selecting pair " << endl; selectedPairIndex = i; return false; } } selectedPairIndex = -1; return false; }
void LatticeSolidPhase::setParametersFromXML(const XML_Node& eosdata) { eosdata._require("model","LatticeSolid"); XML_Node& la = eosdata.child("LatticeArray"); std::vector<XML_Node*> lattices = la.getChildren("phase"); for (size_t n = 0; n < lattices.size(); n++) { m_lattice.push_back((LatticePhase*)newPhase(*lattices[n])); } std::vector<string> pnam; std::vector<string> pval; int np = getPairs(eosdata.child("LatticeStoichiometry"), pnam, pval); theta_.resize(m_lattice.size()); for (int i = 0; i < np; i++) { double val = fpValueCheck(pval[i]); bool found = false; for (size_t j = 0; j < m_lattice.size(); j++) { ThermoPhase& tp = *m_lattice[j]; string idj = tp.id(); if (idj == pnam[i]) { theta_[j] = val; found = true; break; } } if (!found) { throw CanteraError("LatticeSolidPhase::setParametersFromXML", "not found"); } } }
void EnumDeclAST::generate() { string machine_name; string id = m_type_ast_ptr->toString(); Vector<Type*> param_type_vec; // used by to_string func call // Make the new type Type* new_type_ptr = new Type(id, getLocation(), getPairs(), g_sym_table.getStateMachine()); g_sym_table.newSym(new_type_ptr); // Add all of the fields of the type to it if (m_field_vec_ptr != NULL) { int size = m_field_vec_ptr->size(); for(int i=0; i<size; i++) { (*m_field_vec_ptr)[i]->generate(new_type_ptr); } } // Add the implicit State_to_string method - FIXME, this is a bit dirty param_type_vec.insertAtBottom(new_type_ptr); // add state to param vector string func_id = new_type_ptr->cIdent()+"_to_string"; Map<string, string> pairs; pairs.add("external", "yes"); Vector<string> string_vec; g_sym_table.newSym(new Func(func_id, getLocation(), g_sym_table.getType("string"), param_type_vec, string_vec, string(""), pairs, NULL)); }
void CopyHeadStatementAST::generate(string& code, Type* return_type_ptr) const { m_in_queue_ptr->assertType("InPort"); m_out_queue_ptr->assertType("OutPort"); code += indent_str(); code += m_out_queue_ptr->getVar()->getCode() + ".enqueue(" + m_in_queue_ptr->getVar()->getCode() + ".getMsgPtrCopy()"; if (getPairs().exist("latency")) { code += ", " + getPairs().lookup("latency"); } else { code += ", COPY_HEAD_LATENCY"; } code += ");\n"; }
void OutPortDeclAST::generate() { string code; Type* queue_type_ptr = m_var_expr_ptr->generate(code); if (!queue_type_ptr->isOutPort()) { error("Outport queues must be of a type that has the 'outport' attribute. The type '" + queue_type_ptr->toString() + "' does not have this attribute."); } Type* type_ptr = m_queue_type_ptr->lookupType(); g_sym_table.newTempSym(new Var(*m_ident_ptr, getLocation(), type_ptr, code, getPairs())); }
void MachineAST::findMachines() { // Add to MachineType enumeration Enum* enum_ptr = g_sym_table.getEnum("MachineType"); assert(enum_ptr != NULL); if (!enum_ptr->enumAdd(*m_ident_ptr, getPairs())) { error("Duplicate machine name: " + enum_ptr->toString() + ":" + *m_ident_ptr); } // Generate code for all the internal decls m_decl_list_ptr->findMachines(); }
void PDSS_IonsFromNeutral::constructPDSSXML(VPStandardStateTP* tp, size_t spindex, const XML_Node& speciesNode, const XML_Node& phaseNode, const std::string& id) { const XML_Node* tn = speciesNode.findByName("thermo"); if (!tn) { throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML", "no thermo Node for species " + speciesNode.name()); } if (lowercase(tn->attrib("model")) != "ionfromneutral") { throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML", "thermo model for species isn't IonsFromNeutral: " + speciesNode.name()); } const XML_Node* nsm = tn->findByName("neutralSpeciesMultipliers"); if (!nsm) { throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML", "no Thermo::neutralSpeciesMultipliers Node for species " + speciesNode.name()); } IonsFromNeutralVPSSTP* ionPhase = dynamic_cast<IonsFromNeutralVPSSTP*>(tp); if (!ionPhase) { throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML", "Dynamic cast failed"); } neutralMoleculePhase_ = ionPhase->neutralMoleculePhase_; std::vector<std::string> key; std::vector<std::string> val; numMult_ = getPairs(*nsm, key, val); idNeutralMoleculeVec.resize(numMult_); factorVec.resize(numMult_); tmpNM.resize(neutralMoleculePhase_->nSpecies()); for (size_t i = 0; i < numMult_; i++) { idNeutralMoleculeVec[i] = neutralMoleculePhase_->speciesIndex(key[i]); factorVec[i] = fpValueCheck(val[i]); } specialSpecies_ = 0; const XML_Node* ss = tn->findByName("specialSpecies"); if (ss) { specialSpecies_ = 1; } const XML_Node* sss = tn->findByName("secondSpecialSpecies"); if (sss) { specialSpecies_ = 2; } add2RTln2_ = true; if (specialSpecies_ == 1) { add2RTln2_ = false; } }
void TypeDeclAST::generate() { string machine_name; string id = m_type_ast_ptr->toString(); // Make the new type Type* new_type_ptr = new Type(id, getLocation(), getPairs(), g_sym_table.getStateMachine()); g_sym_table.newSym(new_type_ptr); // Add all of the fields of the type to it if (m_field_vec_ptr != NULL) { int size = m_field_vec_ptr->size(); for(int i=0; i<size; i++) { (*m_field_vec_ptr)[i]->generate(new_type_ptr); } } }
void TypeFieldMethodAST::generate(ExternType* extern_type_ptr) { // Lookup return type Type* return_type_ptr = m_return_type_ast_ptr->lookupType(); // Lookup parameter types Vector<Type*> type_vec; int size = m_type_ast_vec_ptr->size(); for(int i=0; i<size; i++) { Type* param_type_ptr = (*m_type_ast_vec_ptr)[i]->lookupType(); type_vec.insertAtBottom(param_type_ptr); } // Add method if (!extern_type_ptr->methodAdd(*m_ident_ptr, return_type_ptr, type_vec, getPairs())) { // Return false on error error("Duplicate method: " + extern_type_ptr->toString() + ":" + *m_ident_ptr + "()"); } }
void ofxTLVideoDepthAlignmentScrubber::draw(){ if(!ready()){ ofPushStyle(); ofSetColor(255, 100, 0, 30); ofRect(bounds); ofPopStyle(); return; } ofPushStyle(); vector<VideoDepthPair>& alignedFrames = getPairs(); for(int i = 0; i < alignedFrames.size(); i++){ // long vid; // if(depthSequence->doFramesHaveTimestamps()){ // float videoPercent = alignedFrames[i].videoMillis / (videoSequence->getPlayer()->getDuration()*1000.0); // videoFrame = videoPercent * videoSequence->getPlayer()->getTotalNumFrames(); // } // else{ // videoFrame = alignedFrames[i].videoMillis; // } // int screenX = millisToScreenX( alignedFrames[i].videoMillis ); if(i == selectedPairIndex){ ofSetColor(timeline->getColors().textColor); } else{ ofSetColor(timeline->getColors().keyColor); } ofLine(screenX, bounds.y, screenX, bounds.y+bounds.height); ofDrawBitmapString("video: " + ofToString(ofxTimecode::timecodeForMillis(alignedFrames[i].videoMillis)), ofPoint(screenX+10, bounds.y+15)); ofDrawBitmapString("depth: " + ofToString(ofxTimecode::timecodeForMillis(alignedFrames[i].depthMillis)), ofPoint(screenX+10, bounds.y+35)); } ofSetColor(0, 125, 255); int selectedScreenX = normalizedXtoScreenX(selectedPercent); ofLine(selectedScreenX, bounds.y, selectedScreenX, bounds.y+bounds.height); ofDrawBitmapString("sel.video: " + ofToString(selectedVideoMillis), ofPoint(selectedScreenX+10, bounds.y+55)); ofDrawBitmapString("sel.depth: " + ofToString(selectedDepthMillis), ofPoint(selectedScreenX+10, bounds.y+75)); ofPopStyle(); }
int main() { vi primes; primes.push_back(2); primes.push_back(3); primes.push_back(5); //get all primes less than 2^15 int i = 7; while(i <= MAXN) { addIfPrime(primes, i); i+=2; } //for(vi::iterator it = primes.begin(); it != primes.end(); it++) printf("%d ", *it); printf("\n"); //primes.insert(primes.begin(), 1); int num; while(scanf("%d\n", &num) != EOF && num != 0){ int p = getPairs(primes, num); printf("%d\n", p); } return 0; }
bool ColorHarmonizationEngineGlobal::Process() { const std::string vec_selectionMethod[ 3 ] = { "fullFrame", "matchedPoints", "KVLD" }; const std::string vec_harmonizeMethod[ 1 ] = { "quantifiedGainCompensation" }; const int harmonizeMethod = 0; //------------------- // Load data //------------------- if( !ReadInputData() ) return false; if( _map_Matches.size() == 0 ) { cout << endl << "Matches file is empty" << endl; return false; } //-- Remove EG with poor support: for (matching::PairWiseMatches::iterator iter = _map_Matches.begin(); iter != _map_Matches.end(); ++iter) { if (iter->second.size() < 120) { _map_Matches.erase(iter); iter = _map_Matches.begin(); } } { graph::indexedGraph putativeGraph(getPairs(_map_Matches)); // Save the graph before cleaning: graph::exportToGraphvizData( stlplus::create_filespec(_sOutDirectory, "input_graph_poor_supportRemoved"), putativeGraph.g); } //------------------- // Keep the largest CC in the image graph //------------------- if (!CleanGraph()) { std::cout << std::endl << "There is no largest CC in the graph" << std::endl; return false; } //------------------- //-- Color Harmonization //------------------- //Choose image reference if( _imgRef == -1 ) { do { cout << "Choose your reference image:\n"; for( int i = 0; i < _vec_fileNames.size(); ++i ) { cout << "id: " << i << "\t" << _vec_fileNames[ i ] << endl; } }while( !( cin >> _imgRef ) || _imgRef < 0 || _imgRef >= _vec_fileNames.size() ); } //Choose selection method if( _selectionMethod == -1 ) { cout << "Choose your selection method:\n" << "- FullFrame: 0\n" << "- Matched Points: 1\n" << "- VLD Segment: 2\n"; while( ! ( cin >> _selectionMethod ) || _selectionMethod < 0 || _selectionMethod > 2 ) { cout << _selectionMethod << " is not accepted.\nTo use: \n- FullFrame enter: 0\n- Matched Points enter: 1\n- VLD Segment enter: 2\n"; } }
void PeekStatementAST::generate(string& code, Type* return_type_ptr) const { code += indent_str() + "{\n"; // Start scope inc_indent(); g_sym_table.pushFrame(); Type* msg_type_ptr = m_type_ptr->lookupType(); // Add new local var to symbol table g_sym_table.newTempSym(new Var("in_msg", getLocation(), msg_type_ptr, "(*in_msg_ptr)", getPairs())); // Check the queue type m_queue_name_ptr->assertType("InPort"); // Declare the new "in_msg_ptr" variable code += indent_str() + "const " + msg_type_ptr->cIdent() + "* in_msg_ptr;\n"; // Declare message // code += indent_str() + "in_msg_ptr = static_cast<const "; code += indent_str() + "in_msg_ptr = dynamic_cast<const "; code += msg_type_ptr->cIdent() + "*>("; code += "(" + m_queue_name_ptr->getVar()->getCode() + ")"; code += "."; code += m_method; code += "());\n"; code += indent_str() + "assert(in_msg_ptr != NULL);\n"; // Check the cast result m_statementlist_ptr->generate(code, return_type_ptr); // The other statements dec_indent(); g_sym_table.popFrame(); code += indent_str() + "}\n"; // End scope }
void PairListAST::addPair(PairAST* pair_ptr) { getPairs().add(pair_ptr->key(), pair_ptr->value()); }
void PairListAST::print(ostream& out) const { out << "[PairListAST] " << getPairs(); }
void ObjDeclAST::generate() { bool machineComponentSym = false; getPairs().add("chip_object", "yes"); string c_code; if (getPairs().exist("hack")) { warning("'hack=' is now deprecated"); } if (getPairs().exist("network")) { if (!getPairs().exist("virtual_network")) { error("Network queues require a 'virtual_network' attribute."); } } Type* type_ptr = m_type_ptr->lookupType(); if (type_ptr->isBuffer()) { if (!getPairs().exist("ordered")) { error("Buffer object declarations require an 'ordered' attribute."); } } if (getPairs().exist("ordered")) { string value = getPairs().lookup("ordered"); if (value != "true" && value != "false") { error("The 'ordered' attribute must be 'true' or 'false'."); } } if (getPairs().exist("random")) { string value = getPairs().lookup("random"); if (value != "true" && value != "false") { error("The 'random' attribute must be 'true' or 'false'."); } } string machine; if (g_sym_table.getStateMachine() != NULL) { machine = g_sym_table.getStateMachine()->getIdent() + "_"; } // FIXME : should all use accessors here to avoid public member variables if (*m_ident_ptr == "id") { c_code = "m_chip_ptr->getID()"; } else if (*m_ident_ptr == "version") { c_code = "m_version"; } else if (*m_ident_ptr == "machineID") { c_code = "m_machineID"; } else if (*m_ident_ptr == "sequencer") { c_code = "*(dynamic_cast<"+m_type_ptr->toString()+"*>(m_chip_ptr->getSequencer(m_version)))"; machineComponentSym = true; } /*else if (*m_ident_ptr == "xfdr_record_mgr") { c_code = "*(dynamic_cast<"+m_type_ptr->toString()+"*>(m_chip_ptr->getXfdrManager(m_version)))"; machineComponentSym = true; } */else if (// getPairs().exist("network") || (m_type_ptr->lookupType()->existPair("cache")) // || (m_type_ptr->lookupType()->existPair("tbe")) || // (m_type_ptr->lookupType()->existPair("newtbe")) || // (m_type_ptr->lookupType()->existPair("timer")) || // (m_type_ptr->lookupType()->existPair("dir")) || // (m_type_ptr->lookupType()->existPair("persistent")) || // (m_type_ptr->lookupType()->existPair("filter")) || // (getPairs().exist("trigger_queue")) getPairs().exist("no_vector")) { c_code = "(*(m_chip_ptr->m_" + machine + *m_ident_ptr + "_ptr))"; machineComponentSym = true; } else { c_code = "(*(m_chip_ptr->m_" + machine + *m_ident_ptr + "_vec[m_version]))"; machineComponentSym = true; } Var* v = new Var(*m_ident_ptr, getLocation(), type_ptr, c_code, getPairs(), g_sym_table.getStateMachine()); g_sym_table.newSym(v); // used to cheat-- that is, access components in other machines if (machineComponentSym) { g_sym_table.newMachComponentSym(v); } }
QString PoiPolygonMerger::toString() const { QString s = hoot::toString(getPairs()); return QString("PoiPolygonMerger %1").arg(s); }
void TransitionDeclAST::generate() { Vector<string>& states = *m_state_list_ptr; Vector<string>& events = *m_event_list_ptr; StateMachine* machine_ptr = g_sym_table.getStateMachine(); if (machine_ptr == NULL) { error("Transition declaration not part of a machine."); } else if (m_next_state_ptr == NULL) { for (int i=0; i<states.size(); i++) { for (int j=0; j<events.size(); j++) { machine_ptr->addTransition(new Transition(states[i], events[j], states[i], *m_action_list_ptr, getLocation(), getPairs())); } } } else { for (int i=0; i<states.size(); i++) { for (int j=0; j<events.size(); j++) { machine_ptr->addTransition(new Transition(states[i], events[j], *m_next_state_ptr, *m_action_list_ptr, getLocation(), getPairs())); } } } }