// Takes text and tags // Removes the tags from the start and end of the text // Returns a string string trim(read r, read t1, read t2, read t3) { // Copy the text into a string string s = r; // Remove the tags from the start of the string until gone while (true) { if (starts(s, t1)) s = clip(s, length(t1), -1); else if (starts(s, t2)) s = clip(s, length(t2), -1); else if (starts(s, t3)) s = clip(s, length(t3), -1); else break; } // Remove the tags from the end of the string until gone while (true) { if (trails(s, t1)) s = clip(s, 0, length(s) - length(t1)); else if (trails(s, t2)) s = clip(s, 0, length(s) - length(t2)); else if (trails(s, t3)) s = clip(s, 0, length(s) - length(t3)); else break; } // Return the string return s; }
// Takes text and tag, and direction and matching // Confirms the text starts or ends with the tag, inserting it if necessary // Returns a string string on(read r, read t, direction d, matching m) { string s = r; if (d == Forward) { if (!starts(s, t, m)) s = t + s; } // Confirm the text starts with the tag else { if (!trails(s, t, m)) s = s + t; } // Confirm the text ends with the tag return s; }
// Takes text and tag, and direction and matching // Confirms the text does not start or end with the tag, removing multiple instances of it if necessary // Returns a string string off(read r, read t, direction d, matching m) { string s = r; if (d == Forward) { while(starts(s, t, m)) s = clip(s, length(t), -1); } // Remove the tag from the start of the string else { while(trails(s, t, m)) s = clip(s, 0, length(s) - length(t)); } // Remove the tag from the end of the string return s; }
void AgentEngine::run(Communicator *comm, PointMap *pointmap) { __time64_t atime = 0; if (comm) { qtimer( atime, 0 ); comm->CommPostMessage( Communicator::NUM_RECORDS, m_timesteps ); } AttributeTable& table = pointmap->getAttributeTable(); int displaycol = table.insertColumn(g_col_total_counts); int output_mode = Agent::OUTPUT_COUNTS; if (m_gatelayer != -1) { output_mode |= Agent::OUTPUT_GATE_COUNTS; } // remove any agent trails that are left from a previous run for (int k = 0; k < MAX_TRAILS; k++) { g_trails[k].clear(); } int trail_num = -1; if (m_record_trails) { if (m_trail_count < 1) { m_trail_count = 1; } if (m_trail_count > MAX_TRAILS) { m_trail_count = MAX_TRAILS; } trail_num = 0; } // remove any agents that are left from a previous run for (size_t j = 0; j < size(); j++) { at(j).clear(); } for (int i = 0; i < m_timesteps; i++) { size_t j; for (j = 0; j < size(); j++) { int q = invcumpoisson(prandomr(),at(j).m_release_rate); int length = at(j).size(); int k; for (k = 0; k < q; k++) { at(j).push_back(Agent(&(at(j)),pointmap,output_mode)); } for (k = 0; k < q; k++) { at(j).init(length+k,trail_num); if (trail_num != -1) { trail_num++; // after trail count, stop recording: if (trail_num == m_trail_count) { trail_num = -1; } } } } for (j = 0; j < size(); j++) { at(j).move(); } if (comm) { if (qtimer( atime, 500 )) { if (comm->IsCancelled()) { throw Communicator::CancelledException(); } comm->CommPostMessage( Communicator::CURRENT_RECORD, i ); } } } // output agent trails to file: if (m_record_trails) { // just dump in local file... ofstream trails("trails.cat"); trails << "CAT" << endl; for (int i = 0; i < m_trail_count; i++) { trails << "Begin Polyline" << endl; for (size_t j = 0; j < g_trails[i].size(); j++) { trails << g_trails[i][j].x << " " << g_trails[i][j].y << endl; } trails << "End Polyline" << endl; } } // actually, no, do this from the pointmap->overrideDisplayedAttribute(-2); pointmap->setDisplayedAttribute(displaycol); }