thread::~thread() { join(); }
Network::~Network() { _tap.close(); join(); TRACE("network %llu (%s) closed",_id,_tap.deviceName().c_str()); }
virtual ~cserv() { stopped = true; if (started) pollthread.join(); }
run_server::~run_server() { join(); }
Thread::~Thread() { join(); }
void generic_reader_c::display_identification_results() { std::string format_file, format_track, format_attachment, format_att_description, format_att_file_name; if (g_identify_for_mmg) { format_file = "File '%1%': container: %2%"; format_track = "Track ID %1%: %2% (%3%)"; format_attachment = "Attachment ID %1%: type \"%2%\", size %3% bytes"; format_att_description = ", description \"%1%\""; format_att_file_name = ", file name \"%1%\""; } else { format_file = Y("File '%1%': container: %2%"); format_track = Y("Track ID %1%: %2% (%3%)"); format_attachment = Y("Attachment ID %1%: type '%2%', size %3% bytes"); format_att_description = Y(", description '%1%'"); format_att_file_name = Y(", file name '%1%'"); } mxinfo(boost::format(format_file) % m_ti.m_fname % m_id_results_container.info); if (g_identify_verbose && !m_id_results_container.verbose_info.empty()) mxinfo(boost::format(" [%1%]") % join(" ", m_id_results_container.verbose_info)); mxinfo("\n"); for (auto &result : m_id_results_tracks) { mxinfo(boost::format(format_track) % result.id % result.type % result.info); if (g_identify_verbose && !result.verbose_info.empty()) mxinfo(boost::format(" [%1%]") % join(" ", result.verbose_info)); mxinfo("\n"); } for (auto &result : m_id_results_attachments) { mxinfo(boost::format(format_attachment) % result.id % id_escape_string(result.type) % result.size); if (!result.description.empty()) mxinfo(boost::format(format_att_description) % id_escape_string(result.description)); if (!result.info.empty()) mxinfo(boost::format(format_att_file_name) % id_escape_string(result.info)); if (g_identify_verbose && !result.verbose_info.empty()) mxinfo(boost::format(" [%1%]") % join(" ", result.verbose_info)); mxinfo("\n"); } for (auto &result : m_id_results_chapters) { if (g_identify_for_mmg) mxinfo(boost::format("Chapters: %1% entries") % result.size); else mxinfo(boost::format(NY("Chapters: %1% entry", "Chapters: %1% entries", result.size)) % result.size); mxinfo("\n"); } for (auto &result : m_id_results_tags) { if (ID_RESULT_GLOBAL_TAGS_ID == result.id) { if (g_identify_for_mmg) mxinfo(boost::format("Global tags: %1% entries") % result.size); else mxinfo(boost::format(NY("Global tags: %1% entry", "Global tags: %1% entries", result.size)) % result.size); } else if (g_identify_for_mmg) mxinfo(boost::format("Tags for track ID %1%: %2% entries") % result.id % result.size); else mxinfo(boost::format(NY("Tags for track ID %1%: %2% entry", "Tags for track ID %1%: %2% entries", result.size)) % result.id % result.size); mxinfo("\n"); } }
void ServerThread::stop (void) { m_server.stopServer(); join(); }
void stop() { _exit_flag.store(true); _cond_var.notify_all(); join(); }
void PTAMWrapper::stopSystem() { keepRunning = false; new_frame_signal.notify_all(); join(); }
void SumProduct::assertSingleRoot() const { Require (roots.size(), "No root node in column %s tree %s", join(gappedCol,"").c_str(), tree.toString().c_str()); Require (roots.size() == 1, "Multiple root nodes (%s) in column %s tree %s", to_string_join(roots,",").c_str(), join(gappedCol,"").c_str(), tree.toString().c_str()); }
void SumProduct::fillUp() { colLogLike = -numeric_limits<double>::infinity(); for (int cpt = 0; cpt < components(); ++cpt) { LogThisAt(8,"Sending tip-to-root messages, component #" << cpt << " column " << join(gappedCol,"") << endl); cptLogLike[cpt] = 0; for (auto r : postorder) { logF[cpt][r] = 0; for (size_t nc = 0; nc < tree.nChildren(r); ++nc) logF[cpt][r] += logE[cpt][tree.getChild(r,nc)]; if (!isGap(r)) { const char c = gappedCol[r]; if (Alignment::isWildcard(c)) { double Fmax = 0; for (AlphTok i = 0; i < model.alphabetSize(); ++i) { double Fi = 1; for (size_t nc = 0; nc < tree.nChildren(r); ++nc) Fi *= E[cpt][tree.getChild(r,nc)][i]; F[cpt][r][i] = Fi; if (Fi > Fmax) Fmax = Fi; } if (Fmax < SUMPROD_RESCALE_THRESHOLD) { for (auto& Fi: F[cpt][r]) Fi /= Fmax; logF[cpt][r] += log (Fmax); } } else { // !isWild(r) const AlphTok tok = model.tokenize(c); double Ftok = 1; for (size_t nc = 0; nc < tree.nChildren(r); ++nc) Ftok *= E[cpt][tree.getChild(r,nc)][tok]; if (Ftok < SUMPROD_RESCALE_THRESHOLD) { logF[cpt][r] += log (Ftok); Ftok = 1; } for (AlphTok i = 0; i < model.alphabetSize(); ++i) F[cpt][r][i] = 0; F[cpt][r][tok] = Ftok; } LogThisAt(10,"Row " << setw(3) << r << " " << c << " " << cpt << " logF=" << setw(9) << setprecision(3) << logF[cpt][r] << " F=(" << to_string_join(F[cpt][r]," ",9,3) << ")" << endl); const TreeNodeIndex rp = tree.parentNode(r); if (rp < 0 || isGap(rp)) cptLogLike[cpt] += logF[cpt][r] + log (inner_product (F[cpt][r].begin(), F[cpt][r].end(), insProb[cpt].begin(), 0.)); else { logE[cpt][r] = logF[cpt][r]; for (AlphTok i = 0; i < model.alphabetSize(); ++i) { double Ei = 0; for (AlphTok j = 0; j < model.alphabetSize(); ++j) Ei += branchSubProb[cpt][r][i][j] * F[cpt][r][j]; E[cpt][r][i] = Ei; } } } } log_accum_exp (colLogLike, logCptWeight[cpt] + cptLogLike[cpt]); } }
void SumProduct::accumulateEigenCounts (vguard<vguard<double> >& rootCounts, vguard<vguard<vguard<gsl_complex> > >& eigenCounts, double weight) const { LogThisAt(8,"Accumulating eigencounts, column " << join(gappedCol,"") << ", weight " << weight << endl); accumulateRootCounts (rootCounts, weight); const auto rootNode = columnRoot(); const int A = model.alphabetSize(); vguard<double> U (A), D (A); vguard<gsl_complex> Ubasis (A), Dbasis (A); vguard<double> U0 (A), D0 (A); for (auto node : ungappedRows) if (node != rootNode) { LogThisAt(9,"Accumulating eigencounts, column " << join(gappedCol,"") << " node " << tree.seqName(node) << endl); const TreeNodeIndex parent = tree.parentNode(node); const TreeNodeIndex sibling = tree.getSibling(node); for (int cpt = 0; cpt < components(); ++cpt) { LogThisAt(9,"Accumulating eigencounts, column " << join(gappedCol,"") << " node " << tree.seqName(node) << " component #" << cpt << endl); const vguard<double>& U0 = F[cpt][node]; for (AlphTok i = 0; i < A; ++i) D0[i] = G[cpt][parent][i] * E[cpt][sibling][i]; const double maxU0 = *max_element (U0.begin(), U0.end()); const double maxD0 = *max_element (D0.begin(), D0.end()); const double norm = exp (colLogLike - logCptWeight[cpt] - logF[cpt][node] - logG[cpt][parent] - logE[cpt][sibling]) / (maxU0 * maxD0); // U[b] = U0[b] / maxU0; Ubasis[l] = sum_b U[b] * evecInv[l][b] for (AlphTok b = 0; b < A; ++b) U[b] = U0[b] / maxU0; for (AlphTok l = 0; l < A; ++l) { Ubasis[l] = gsl_complex_rect (0, 0); for (AlphTok b = 0; b < A; ++b) Ubasis[l] = gsl_complex_add (Ubasis[l], gsl_complex_mul_real (gsl_matrix_complex_get (eigen.evecInv[cpt], l, b), U[b])); } // D[a] = D0[a] / maxD0; Dbasis[k] = sum_a D[a] * evec[a][k] for (AlphTok a = 0; a < A; ++a) D[a] = D0[a] / maxD0; for (AlphTok k = 0; k < A; ++k) { Dbasis[k] = gsl_complex_rect (0, 0); for (AlphTok a = 0; a < A; ++a) Dbasis[k] = gsl_complex_add (Dbasis[k], gsl_complex_mul_real (gsl_matrix_complex_get (eigen.evec[cpt], a, k), D[a])); } // R = evec * evals * evecInv // exp(RT) = evec * exp(evals T) * evecInv // count(i,j|a,b,T) = Q / exp(RT)_ab // where... // Q = \sum_a \sum_b \int_{t=0}^T D_a exp(Rt)_ai R_ij exp(R(T-t))_jb U_b dt // = \sum_a \sum_b \int_{t=0}^T D_a (\sum_k evec_ak exp(eval_k t) evecInv_ki) R_ij (\sum_l evec_jl exp(eval_l (T-t)) evecInv_lb) U_b dt // = \sum_a \sum_b D_a \sum_k evec_ak evecInv_ki R_ij \sum_l evec_jl evecInv_lb U_b \int_{t=0}^T exp(eval_k t) exp(eval_l (T-t)) dt // = \sum_a \sum_b D_a \sum_k evec_ak evecInv_ki R_ij \sum_l evec_jl evecInv_lb U_b eigenSubCount(k,l,T) // = R_ij \sum_k evecInv_ki \sum_l evec_jl (\sum_a D_a evec_ak) (\sum_b U_b evecInv_lb) eigenSubCount(k,l,T) // = R_ij \sum_k evecInv_ki \sum_l evec_jl Dbasis_k Ubasis_l eigenSubCount(k,l,T) // eigenCounts[k][l] += Dbasis[k] * eigenSub[k][l] * Ubasis[l] / norm for (AlphTok k = 0; k < A; ++k) for (AlphTok l = 0; l < A; ++l) eigenCounts[cpt][k][l] = gsl_complex_add (eigenCounts[cpt][k][l], gsl_complex_mul_real (gsl_complex_mul (Dbasis[k], gsl_complex_mul (gsl_matrix_complex_get (branchEigenSubCount[cpt][node], k, l), Ubasis[l])), weight / norm)); // LogThisAt(9,"colLogLike=" << colLogLike << " logF[cpt][node]=" << logF[cpt][node] << " logG[cpt][parent]=" << logG[cpt][parent] << " logE[cpt][sibling]=" << logE[cpt][sibling] << " maxU0=" << maxU0 << " maxD0=" << maxD0 << endl); // LogThisAt(8,"Component #" << cpt << " eigencounts matrix (norm=" << norm << "):" << endl << complexMatrixToString(eigenCounts[cpt]) << endl); } } }
static CString GetPromptText() { CString s; { float fOld = GAMESTATE->m_fGlobalOffsetSecondsOriginal; float fNew = PREFSMAN->m_fGlobalOffsetSeconds; float fDelta = fNew - fOld; if( fabs(fDelta) > 0.00001 ) { s += ssprintf( "You have changed the Global Offset\nfrom %+.3f to %+.3f (change of %+.3f, notes %s).\n\n", fOld, fNew, fDelta, fDelta > 0 ? "earlier":"later" ); } } vector<CString> vsSongChanges; { float fOld = GAMESTATE->m_pTimingDataOriginal->m_fBeat0OffsetInSeconds; float fNew = GAMESTATE->m_pCurSong->m_Timing.m_fBeat0OffsetInSeconds; float fDelta = fNew - fOld; if( fabs(fDelta) > 0.00001 ) { vsSongChanges.push_back( ssprintf( "The song offset changed from %+.3f to %+.3f (change of %+.3f, notes %s).\n\n", fOld, fNew, fDelta, fDelta > 0 ? "earlier":"later" ) ); } } for( unsigned i=0; i<GAMESTATE->m_pCurSong->m_Timing.m_BPMSegments.size(); i++ ) { float fOld = GAMESTATE->m_pTimingDataOriginal->m_BPMSegments[i].m_fBPS; float fNew = GAMESTATE->m_pCurSong->m_Timing.m_BPMSegments[i].m_fBPS; float fDelta = fNew - fOld; if( fabs(fDelta) > 0.00001 ) { vsSongChanges.push_back( ssprintf( "The %s BPM segment changed from %+.3f BPS to %+.3f BPS (change of %+.3f).\n\n", FormatNumberAndSuffix(i+1).c_str(), fOld, fNew, fDelta ) ); } } for( unsigned i=0; i<GAMESTATE->m_pCurSong->m_Timing.m_StopSegments.size(); i++ ) { float fOld = GAMESTATE->m_pTimingDataOriginal->m_StopSegments[i].m_fStopSeconds; float fNew = GAMESTATE->m_pCurSong->m_Timing.m_StopSegments[i].m_fStopSeconds; float fDelta = fNew - fOld; if( fabs(fDelta) > 0.00001 ) { vsSongChanges.push_back( ssprintf( "The %s Stop segment changed from %+.3f seconds to %+.3f seconds (change of %+.3f).\n\n", FormatNumberAndSuffix(i+1).c_str(), fOld, fNew, fDelta ) ); } } if( !vsSongChanges.empty() ) { s += ssprintf( "You have changed the timing of\n" "%s:\n" "\n", GAMESTATE->m_pCurSong->GetDisplayFullTitle().c_str() ); s += join( "\n", vsSongChanges ); } s +="\n\n" "Would you like to save these changes to the song file?\n" "Choosing NO will discard your changes."; return s; }
/** join a wireless network */ bool JPWiFly::join(uint16_t timeout) { String ssid; getSSID(ssid); return join(ssid.c_str(), timeout); }
void splay(node **root, unsigned long long value) { if (!*root) { return; } node *target, *temp; target = find(*root, value); while (target->parent) { if (target->parent->parent) { // zig zig or zig zag unsigned long long direction, grandparentD; direction = target->parent->value < target->value; grandparentD = target->parent->parent->value < target->parent->value; node *x, *y, *z, *a, *b, *c, *d; if (direction == grandparentD) { // zig zig x = target; y = target->parent; z = target->parent->parent; a = target->child[direction]; b = target->child[!direction]; c = target->parent->child[!direction]; d = target->parent->parent->child[!direction]; if (z->parent) { z->parent->child[z->parent->value < z->value] = x; } x->parent = z->parent; join(!direction, &x, &y); join(direction, &y, &b); join(!direction, &y, &z); join(direction, &z, &c); } else { // zig zag x = target; y = target->parent; z = target->parent->parent; a = target->parent->child[!direction]; b = target->child[!direction]; c = target->child[direction]; d = target->parent->parent->child[direction]; if (z->parent) { z->parent->child[z->parent->value < z->value] = x; } x->parent = z->parent; join(direction, &x, &z); join(!direction, &x, &y); join(direction, &y, &b); join(!direction, &y, &a); join(direction, &z, &d); join(!direction, &z, &c); } treeCalcSum(&z); treeCalcSum(&y); treeCalcSum(&x); } else { // zig unsigned long long direction = target->parent->value < target->value; temp = target->child[!direction]; join(!direction, &target, &target->parent); target->parent = 0; join(direction, &target->child[!direction], &temp); treeCalcSum(&target->child[!direction]); treeCalcSum(&target); } } *root = target; }
uint8_t REDFLY::join(char *ssid, uint8_t net, uint8_t chn) { return join(ssid, 0, net, chn, 0xFF); //IBSS_CREATOR }
threadpool::~threadpool() { shutdown(); join(); }
uint8_t REDFLY::join(char *ssid, uint8_t net) { return join(ssid, 0, net, 0, 0xFF); //INFRASTRUCTURE or IBSS_JOINER }
int main(int argc, char *argv[]) { int i; if (strcmp(COLORTEXT, "YES") == 0 || strcmp(COLORTEXT, "yes") == 0) { if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-H") == 0)) { printf("[31mUsage: parmjoin -p[0m parm file -input \n" "[31m -m[0m frcmod file \n" "[31m -o[0m parm file - output\n"); exit(0); } if (argc != 7 && argc != 5) { printf("[31mUsage: parmjoin -p[0m parm file -input \n" "[31m -m[0m frcmod file \n" "[31m -o[0m parm file - output\n"); exit(0); } } else { if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-H") == 0)) { printf("Usage: parmjoin -p parm file - input \n"); printf(" -m frcmod file\n"); printf(" -o parm file - output\n"); exit(0); } if (argc != 7) { printf("Usage: parmjoin -p parm file - input \n"); printf(" -m frcmod file\n"); printf(" -o parm file - output\n"); exit(0); } } for (i = 1; i < argc; i += 2) { if (strcmp(argv[i], "-p") == 0) strcpy(pfilename, argv[i + 1]); if (strcmp(argv[i], "-m") == 0) strcpy(mfilename, argv[i + 1]); if (strcmp(argv[i], "-o") == 0) strcpy(ofilename, argv[i + 1]); } /* allocate memory using calloc*/ maxatomtype = MAX_FF_ATOMTYPE; maxvdwparm = MAX_FF_VDW; maxbondparm = MAX_FF_BOND; maxangleparm = MAX_FF_ANGLE; maxtorsionparm = MAX_FF_TORSION; maximproperparm = MAX_FF_IMPROPER; atomtype = (ATOMTYPE *) calloc(maxatomtype, sizeof(ATOMTYPE)); if (atomtype == NULL) { fprintf(stderr, "memory allocation error for *atomtype\n"); exit(0); } bondparm = (BOND_FF *) calloc(maxbondparm, sizeof(BOND_FF)); if (bondparm == NULL) { fprintf(stderr, "memory allocation error for *bondparm\n"); exit(0); } angleparm = (ANGLE *) calloc(maxangleparm, sizeof(ANGLE)); if (angleparm == NULL) { fprintf(stderr, "memory allocation error for *angleparm\n"); exit(0); } torsionparm = (TORSION *) calloc(maxtorsionparm, sizeof(TORSION)); if (torsionparm == NULL) { fprintf(stderr, "memory allocation error for *torsionparm\n"); exit(0); } improperparm = (IMPROPER *) calloc(maximproperparm, sizeof(IMPROPER)); if (improperparm == NULL) { fprintf(stderr, "memory allocation error for *improperparm\n"); exit(0); } vdwparm = (VDW *) calloc(maxvdwparm, sizeof(VDW)); if (vdwparm == NULL) { fprintf(stderr, "memory allocation error for *vdwparm\n"); exit(0); } readfrcmod(mfilename); /*frcmod */ atomtypeindex = (int *) calloc(atomtypenum, sizeof(int)); if (atomtypeindex == NULL) { fprintf(stderr, "memory allocation error for *atomtypeindex\n"); exit(0); } bondparmindex = (int *) calloc(bondparmnum, sizeof(int)); if (bondparmindex == NULL) { fprintf(stderr, "memory allocation error for *bondparmindex\n"); exit(0); } angleparmindex = (int *) calloc(angleparmnum, sizeof(int)); if (angleparmindex == NULL) { fprintf(stderr, "memory allocation error for *angleparmindex\n"); exit(0); } torsionparmindex = (int *) calloc(torsionparmnum, sizeof(int)); if (torsionparmindex == NULL) { fprintf(stderr, "memory allocation error for *torsionparmindex\n"); exit(0); } improperparmindex = (int *) calloc(improperparmnum, sizeof(int)); if (improperparmindex == NULL) { fprintf(stderr, "memory allocation error for *improperparmindex\n"); exit(0); } vdwparmindex = (int *) calloc(vdwparmnum, sizeof(int)); if (vdwparmindex == NULL) { fprintf(stderr, "memory allocation error for *vdwparmindex\n"); exit(0); } for (i = 0; i < atomtypenum; i++) atomtypeindex[i] = 0; for (i = 0; i < vdwparmnum; i++) vdwparmindex[i] = 0; for (i = 0; i < torsionparmnum; i++) torsionparmindex[i] = 0; for (i = 0; i < improperparmnum; i++) improperparmindex[i] = 0; for (i = 0; i < bondparmnum; i++) bondparmindex[i] = 0; for (i = 0; i < angleparmnum; i++) angleparmindex[i] = 0; check(pfilename); /*check if the parameters from mfilename already exist in pfilename */ join(pfilename, ofilename); /*append the unduplicated parameters in mfilename to pfilename */ /* free(atomtypeindex); free(bondparmindex); free(angleparmindex); free(torsionparmindex); free(improperparmindex); free(vdwparmindex); free(atomtype); free(bondparm); free(angleparm); free(torsionparm); free(improperparm); free(vdwparm); */ return (0); }
uint8_t REDFLY::join(char *ssid) { return join(ssid, 0, INFRASTRUCTURE, 0, 0xFF); //INFRASTRUCTURE }
int main(int argc, char *argv[]) { unsigned long long ofsize, factr, spval; char spfactr[3]; int i; if(argc<2 || strcmp(argv[1],"--help")==0) { help(); exit(1); } else if(strcmp(argv[1],"--version")==0) { version(); exit(0); } else if(argc==2) { join(argv[1]); exit(1); } else if(argc==4 && strcmp(argv[1],"-split")==0) { /* Copy the last two charaters into some other character array */ strcpy(spfactr, (argv[2]+strlen(argv[2])-2)); /* Generate number from the string form in argument. */ i=0; spval = 0; while(argv[2][i]) { if(argv[2][i]<'0' || argv[2][i]>'9') break; spval = (10 * spval) + (argv[2][i] - '0'); i++; } if(i != strlen(argv[2])-2) { fprintf(stderr, "Invalid split size.\n"); } /* Check the factor. */ for(i=0; i<2; i++) spfactr[i] = toupper(spfactr[i]); if(strcmp(spfactr, "KB")==0) factr = 1024; else if(strcmp(spfactr, "MB")==0) factr = 1024 * 1024; else if(strcmp(spfactr, "GB")==0) factr = 1024 * 1024 * 1024; else { fprintf(stdout, "Invalid split size.\n"); } /*calcuate the size of each file. */ ofsize=0; ofsize = spval * factr; /****************temp********************/ fprintf(stdout, "factr = %lld, spval = %lld, ofsize = %lld\n",factr, spval, ofsize); /****************************************/ /* Call the function to split the file. */ split(argv[3], ofsize); } return 0; }
std::string DottedVersion::ToString(void) const { return join(parts_.begin(), parts_.end(), "."); }
static data_t make(mesh_t const &m, target_shape_t shape, aux_t ml) { data_t A(join(m.size_of_components(), shape), ml); A() = 0; return A; }
/** * \brief Node Function * Arguments: * - my id * - the id of a guy I know in the system (except for the first node) * - the time to sleep before I join (except for the first node) * - the deadline time */ static int node(int argc, char *argv[]) { double init_time = MSG_get_clock(); msg_task_t task_received = NULL; int join_success = 0; double deadline; xbt_assert(argc == 3 || argc == 5, "Wrong number of arguments for this node"); s_node_t node = {0}; node.id = xbt_str_parse_int(argv[1], "Invalid ID: %s"); node.known_id = -1; node.ready = -1; node.pending_tasks = xbt_fifo_new(); get_mailbox(node.id, node.mailbox); XBT_DEBUG("New node with id %s (%08x)", node.mailbox, node.id); int i,j,d; for (i=0; i<LEVELS_COUNT; i++){ d = domain(node.id, i); for (j=0; j<LEVEL_SIZE; j++) node.routing_table[i][j] = (d==j) ? node.id : -1; } for (i=0; i<NEIGHBORHOOD_SIZE; i++) node.neighborhood_set[i] = -1; for (i=0; i<NAMESPACE_SIZE; i++) node.namespace_set[i] = -1; if (argc == 3) { // first ring XBT_DEBUG("Hey! Let's create the system."); deadline = xbt_str_parse_double(argv[2], "Invalid deadline: %s"); create(&node); join_success = 1; } else { node.known_id = xbt_str_parse_int(argv[2], "Invalid known ID: %s"); double sleep_time = xbt_str_parse_double(argv[3], "Invalid sleep time: %s"); deadline = xbt_str_parse_double(argv[4], "Invalid deadline: %s"); // sleep before starting XBT_DEBUG("Let's sleep during %f", sleep_time); MSG_process_sleep(sleep_time); XBT_DEBUG("Hey! Let's join the system."); join_success = join(&node); } if (join_success) { XBT_DEBUG("Waiting …."); while (MSG_get_clock() < init_time + deadline // && MSG_get_clock() < node.last_change_date + 1000 && MSG_get_clock() < max_simulation_time) { if (node.comm_receive == NULL) { task_received = NULL; node.comm_receive = MSG_task_irecv(&task_received, node.mailbox); // FIXME: do not make MSG_task_irecv() calls from several functions } if (!MSG_comm_test(node.comm_receive)) { MSG_process_sleep(5); } else { // a transfer has occurred msg_error_t status = MSG_comm_get_status(node.comm_receive); if (status != MSG_OK) { XBT_DEBUG("Failed to receive a task. Nevermind."); MSG_comm_destroy(node.comm_receive); node.comm_receive = NULL; } else { // the task was successfully received MSG_comm_destroy(node.comm_receive); node.comm_receive = NULL; handle_task(&node, task_received); } } } print_node(&node); } return 1; }
QString DiscName::joinDVD(int title, const QString & device, bool use_dvdnav) { return join(use_dvdnav ? DVDNAV : DVD, title, device); }
else if((data.type() == QVariant::List) || (data.type() == QVariant::StringList)) // variant is a list? { QList<QByteArray> values; const QVariantList list = data.toList(); Q_FOREACH(const QVariant& v, list) { QByteArray serializedValue = serialize(v); if(serializedValue.isNull()) { success = false; break; } values << serializedValue; } str = "[ " + join( values, ", " ) + " ]"; } else if(data.type() == QVariant::Hash) // variant is a hash? { const QVariantHash vhash = data.toHash(); QHashIterator<QString, QVariant> it( vhash ); str = "{ "; QList<QByteArray> pairs; while(it.hasNext()) { it.next(); QByteArray serializedValue = serialize(it.value()); if(serializedValue.isNull()) {
string Task::toString() { storeCommonAttribs(); storeCustomAttribs(); return join(persistentAttribs, ITEM_SEPARATOR); }
ECode CxxSourceCrcTask::operator()() { const auto& path = apply_visitor(doim::vst::path(), cxxSource()); defer(LOGEX(tags(), "{} for {} is {:x}", depth() == EDepth::kOne ? "Crc" : "Deep Crc", path, mCrcsum)); auto origin = apply_visitor([](auto const& element) { return element->origin(); }, cxxSource()); if (!apply_visitor(vst::isNullptr, origin)) { if (origin.type() == typeid(doim::ProtobufFileSPtr)) { auto originTask = ProtobufFileCrcTask::valid(boost::get<doim::ProtobufFileSPtr>(origin)); gTPool->ensureScheduled(originTask); EHTest(originTask->join()); mCrcsum = originTask->crc(); } else ASSERT(false); EHEnd; } if (depth() == EDepth::kOne) { EHTest(one()); EHEnd; } auto crcTask = valid(EDepth::kOne, cxxSource(), currentIncludeDirectory()); gTPool->ensureScheduled(crcTask); auto headersTask = CxxSourceHeadersTask::valid(CxxSourceHeadersTask::EDepth::kAll, cxxSource(), currentIncludeDirectory()); gTPool->ensureScheduled(headersTask); EHTest(headersTask->join()); const auto& headersInfo = headersTask->headersInfo(); std::vector<CxxSourceCrcTaskSPtr> tasks; tasks.reserve(headersInfo.size() + 1); tasks.push_back(crcTask); for (const auto& headerInfo : headersInfo) { if (headerInfo.mHeader->type() == doim::CxxHeader::EType::kSystem) continue; auto task = CxxSourceCrcTask::valid(CxxSourceCrcTask::EDepth::kOne, headerInfo.mHeader, headerInfo.mIncludeDirectory); task::gTPool->ensureScheduled(task); tasks.push_back(task); } auto group = tpool::TaskGroup::make(task::gTPool, 0, tasks); task::gTPool->ensureScheduled(group); EHTest(group->join()); unordered_set<math::Crcsum> crcs; math::Crcsum x = 0; for (const auto& task : tasks) { auto n = task->crc(); if (n == 0) { mCrcsum = 0; EHEnd; } auto unique = crcs.insert(n).second; if (!unique) EHBan(kTooMany, "There are at least two items with the same crc"); x ^= n; } mCrcsum = math::obfuscate(x); EHEnd; }
SkRect OsmAnd::TextRasterizer_P::positionText( QVector<LinePaint>& paints, const SkScalar maxLineWidth, const Style::TextAlignment textAlignment) const { auto textArea = SkRect::MakeEmpty(); SkScalar verticalOffset = 0; for (auto& linePaint : paints) { SkScalar horizontalOffset = 0; const auto widthDelta = maxLineWidth - linePaint.width; switch (textAlignment) { case Style::TextAlignment::Center: horizontalOffset += widthDelta / 2.0f; break; case Style::TextAlignment::Right: horizontalOffset += widthDelta; break; case Style::TextAlignment::Left: default: // Do nothing here break; } for (auto& textPaint : linePaint.textPaints) { textPaint.positionedBounds = textPaint.bounds; // Position horizontally textPaint.positionedBounds.offset(-2.0f*textPaint.bounds.left(), 0); textPaint.positionedBounds.offset(horizontalOffset, 0); horizontalOffset += textPaint.width; // Position vertically textPaint.positionedBounds.offset(0, -2.0f*textPaint.bounds.top()); textPaint.positionedBounds.offset(0, linePaint.maxBoundsTop + textPaint.bounds.top()); textPaint.positionedBounds.offset(0, verticalOffset); // Include into text area textArea.join(textPaint.positionedBounds); } verticalOffset += linePaint.maxFontHeight; //// Calculate text area and move bounds vertically //auto textArea = linesNormalizedBounds.first(); //auto linesHeightSum = textArea.height(); //auto citPrevLineBounds = linesBounds.cbegin(); //auto citLineBounds = citPrevLineBounds + 1; //for (auto itNormalizedLineBounds = linesNormalizedBounds.begin() + 1, itEnd = linesNormalizedBounds.end(); // itNormalizedLineBounds != itEnd; // ++itNormalizedLineBounds, citPrevLineBounds = citLineBounds, ++citLineBounds) //{ // auto& lineNormalizedBounds = *itNormalizedLineBounds; // const auto& prevLineBounds = *citPrevLineBounds; // const auto& lineBounds = *citLineBounds; // // Include gap between previous line and it's font-end // const auto extraPrevGapHeight = qMax(0.0f, fontMaxBottom - prevLineBounds.fBottom); // textArea.fBottom += extraPrevGapHeight; // linesHeightSum += extraPrevGapHeight; // // Include line spacing // textArea.fBottom += lineSpacing; // linesHeightSum += lineSpacing; // // Include gap between current line and it's font-start // const auto extraGapHeight = qMax(0.0f, fontMaxTop - (-lineBounds.fTop)); // textArea.fBottom += extraGapHeight; // linesHeightSum += extraGapHeight; // // Move current line baseline // lineNormalizedBounds.offset(0.0f, linesHeightSum); // // Include height of current line // const auto& lineHeight = lineNormalizedBounds.height(); // textArea.fBottom += lineHeight; // linesHeightSum += lineHeight; // // This will expand left-right bounds to get proper area width // textArea.fLeft = qMin(textArea.fLeft, lineNormalizedBounds.fLeft); // textArea.fRight = qMax(textArea.fRight, lineNormalizedBounds.fRight); //} } return textArea; }
std::string Json::serialize(const Variant &data, bool &success, const std::string& tab) { std::string str; success = true; if( !data.isValid() ) // invalid or null? { str = "null"; } else if( (data.type() == Variant::List) || (data.type() == Variant::NStringArray) ) // variant is a list? { StringArray values; const VariantList rlist = data.toList(); for( VariantList::const_iterator it = rlist.begin(); it != rlist.end(); it++) { std::string serializedValue = serialize( *it, "" ); if( serializedValue.empty() ) { success = false; break; } values.push_back( serializedValue ); } str = "[ " + join( values, ", " ) + " ]"; } // else if(data.type() == Variant::Hash) // variant is a hash? // { // const VariantHash vhash = data.toHash(); // QHashIterator<std::string, Variant> it( vhash ); // str = "{ "; // QList<QByteArray> pairs; // // while(it.hasNext()) // { // it.next(); // QByteArray serializedValue = serialize(it.value(), ""); // // if(serializedValue.isNull()) // { // success = false; // break; // } // // pairs << tab.toAscii() + sanitizeString(it.key()).toUtf8() + " : " + serializedValue; // } // // str += join(pairs, ", "); // str += " }"; // } else if(data.type() == Variant::Map) // variant is a map? { VariantMap vmap = data.toMap(); str = "{ \n"; StringArray pairs; for( VariantMap::iterator it = vmap.begin(); it != vmap.end(); it++ ) { std::string serializedValue = serialize( it->second, tab + " "); if( serializedValue.empty()) { //success = false; pairs.push_back( tab + sanitizeString( it->first ) + std::string( " : \"nonSerializableValue\"" ) ); continue; } pairs.push_back( tab + sanitizeString( it->first ) + " : " + serializedValue ); } str += join(pairs, ",\n"); std::string rtab( tab ); rtab.resize( std::max<int>( 0, tab.size() - 2 ) ); str += std::string( "\n" ) + rtab + "}"; } else if((data.type() == Variant::String) || (data.type() == Variant::NByteArray)) // a string or a byte array? { str = sanitizeString( data.toString() ); } else if(data.type() == Variant::Double || data.type() == Variant::Float) // double? { str = StringHelper::format( 0xff, "\"%f\"", data.toDouble() ); if( str.find(".") == std::string::npos && str.find("e") == std::string::npos ) { str += ".0"; } } else if( data.type() == Variant::NTilePos) { TilePos pos = data.toTilePos(); str = StringHelper::format( 0xff, "[ %d, %d ]", pos.getI(), pos.getJ() ); } else if( data.type() == Variant::NSize) { Size size = data.toSize(); str = StringHelper::format( 0xff, "[ %d, %d ]", size.getWidth(), size.getHeight() ); } else if( data.type() == Variant::NPoint) { Point pos = data.toPoint(); str = StringHelper::format( 0xff, "[ %d, %d ]", pos.getX(), pos.getY() ); } else if( data.type() == Variant::NPointF) { PointF pos = data.toPointF(); str = StringHelper::format( 0xff, "[ \"%f\", \"%f\" ]", pos.getX(), pos.getY() ); } else if (data.type() == Variant::Bool) // boolean value? { str = data.toBool() ? "true" : "false"; } else if (data.type() == Variant::ULongLong) // large unsigned number? { str = StringHelper::format( 0xff, "%u", data.toULongLong() ); } else if ( data.canConvert( Variant::LongLong ) ) // any signed number? { str = StringHelper::format( 0xff, "%d", data.toLongLong() ); } else if (data.canConvert( Variant::Long )) { str = StringHelper::format( 0xff, "%d", data.toLongLong() ); } else if (data.canConvert( Variant::String ) ) // can value be converted to string? { // this will catch Date, DateTime, Url, ... str = sanitizeString( data.toString() ); } else { success = false; } if (success) { return str; } else { return std::string(); } }