void ExecutableImage::_Helper :: createTape(_Memory& tape, Project* project, bool withNewConsole) { MemoryWriter data(&tape); // write tape // USE_VM_MESSAGE_ID path, package writeTapeRecord(data, USE_VM_MESSAGE_ID, project->StrSetting(opNamespace), project->StrSetting(opOutputPath)); // LOAD_VM_MESSAGE_ID name writeTapeRecord(data, LOAD_VM_MESSAGE_ID, project->StrSetting(opTemplate)); // { MAP_VM_MESSAGE_ID fwrd, ref }* ForwardIterator it = project->getForwardIt(); while (!it.Eof()) { writeTapeRecord(data, MAP_VM_MESSAGE_ID, it.key(), *it); it++; } if (withNewConsole) { writeTapeRecord(data, OPEN_VM_CONSOLE); } // START_VM_MESSAGE_ID debugMode ?? writeTapeRecord(data, START_VM_MESSAGE_ID); // CALL_TAPE_MESSAGE_ID 'program writeTapeRecord(data, CALL_TAPE_MESSAGE_ID, PROGRAM_ENTRY, true); data.writeDWord(0); }
void wait_all(ForwardIterator first, ForwardIterator last) { typedef typename std::iterator_traits<ForwardIterator>::difference_type difference_type; using std::distance; difference_type num_outstanding_requests = distance(first, last); std::vector<bool> completed(num_outstanding_requests); while (num_outstanding_requests > 0) { bool all_trivial_requests = true; difference_type idx = 0; for (ForwardIterator current = first; current != last; ++current, ++idx) { if (!completed[idx]) { if (optional<status> stat = current->test()) { // This outstanding request has been completed. completed[idx] = true; --num_outstanding_requests; all_trivial_requests = false; } else { // Check if this request (and all others before it) are "trivial" // requests, e.g., they can be represented with a single // MPI_Request. all_trivial_requests = all_trivial_requests && !current->m_handler && current->m_requests[1] == MPI_REQUEST_NULL; } } } // If we have yet to fulfill any requests and all of the requests // are trivial (i.e., require only a single MPI_Request to be // fulfilled), call MPI_Waitall directly. if (all_trivial_requests && num_outstanding_requests == (difference_type)completed.size()) { std::vector<MPI_Request> requests; requests.reserve(num_outstanding_requests); for (ForwardIterator current = first; current != last; ++current) requests.push_back(current->m_requests[0]); // Let MPI wait until all of these operations completes. BOOST_MPI_CHECK_RESULT(MPI_Waitall, (num_outstanding_requests, &requests[0], MPI_STATUSES_IGNORE)); // Signal completion num_outstanding_requests = 0; } } }
void produce_html(ForwardIterator first,ForwardIterator last,OutputIterator out) { html_context context; while(first!=last){ if(first->get().context!=context){ change_context(context,first->get().context,out); context=first->get().context; } *out++=(first++)->get().code; } change_context(context,html_context(),out); /* close remaining context */ }
optional<std::pair<status, ForwardIterator> > test_any(ForwardIterator first, ForwardIterator last) { for (ForwardIterator current = first; first != last; ++first) { // Check if we have found a completed request. If so, return it. if (optional<status> result = current->test()) return std::make_pair(*result, current); } // We found nothing return optional<std::pair<status, ForwardIterator> >(); }
inline StringClass replace_all_occurrences_with_wildcards( StringClass str, ForwardIterator it_string_to_find, ForwardIterator it_string_to_find_end, ForwardIterator it_string_to_replace, ForwardIterator it_string_to_replace_end) { for(; it_string_to_find != it_string_to_find_end && it_string_to_replace != it_string_to_replace_end; ++it_string_to_find, ++ it_string_to_replace) { std::size_t wildcard_pos = it_string_to_find->find("*"); if(wildcard_pos == StringClass::npos) { ForwardIterator it_to_find_current_end(it_string_to_find); ForwardIterator it_to_replace_current_end(it_string_to_replace); str = replace_all_occurrences_of( str, it_string_to_find, ++it_to_find_current_end, it_string_to_replace, ++it_to_replace_current_end); continue; } std::size_t wildcard_pos_replace = it_string_to_replace->find("*"); std::size_t found_begin = str.find( it_string_to_find->substr(0, wildcard_pos) ); while( found_begin != StringClass::npos ) { std::size_t found_end = str.find(it_string_to_find->substr(wildcard_pos+1), found_begin + wildcard_pos + 1); // to simplify if( found_end != StringClass::npos ) { if( wildcard_pos_replace == StringClass::npos ) { StringClass replace_content = *it_string_to_replace; str.replace( found_begin, found_end + (it_string_to_find->size() - wildcard_pos - 1 ) - found_begin, replace_content); } else { StringClass replace_content = it_string_to_replace->substr(0, wildcard_pos_replace) + str.substr(found_begin + wildcard_pos, found_end - found_begin - wildcard_pos) + it_string_to_replace->substr(wildcard_pos_replace+1) ; str.replace( found_begin, found_end + (it_string_to_find->size() - wildcard_pos - 1 ) - found_begin, replace_content); } } // may adapt the restart to the replacement and be more efficient found_begin = str.find( it_string_to_find->substr(0, wildcard_pos), found_begin + 1 ); } } return str; }
inline StringClass replace_all_occurrences_of( StringClass str, ForwardIterator first1, ForwardIterator last1, ForwardIterator first2, ForwardIterator last2) { for(; first1 != last1 && first2 != last2; ++first1, ++first2) { std::size_t found = str.find( *first1 ); while( found != StringClass::npos ) { str.replace(found, first1->size(), *first2 ); found = str.find( *first1, found + first2->size() ); } } return str; }
bool update_row(ForwardIterator first, ForwardIterator last, entry & row) const { std::size_t old_size = row.m_terminals.size(); bool epsilon = true; for (; epsilon && first != last; ++first) { if (first->which() == 0) { row.m_terminals |= boost::get<terminal_set_type>(*first); epsilon = false; } else { entry const & other_entry = (*this)(boost::get<nonterminal_type>(*first)); row.m_terminals |= other_entry.m_terminals; epsilon = other_entry.m_epsilon; } } if (epsilon && !row.m_epsilon) { row.m_epsilon = true; return true; } return row.m_terminals.size() != old_size; }
/*------------------------------------------------------------------------------ * Get the first element of an iterator. * @param iter Iterator * @return First node or NULL if empty. ----------------------------------------------------------------------------*/ ContainerNode ForwardIterator_GetFirst (ForwardIterator iter) { if (iter) { iter->currentNode = iter->getFirst(iter); return iter->currentNode; } else return NULL; }
Layer_servo_system_sampler< RandNumberGenerator, ComputeLayerIndex >:: Layer_servo_system_sampler( const CategNonParamCdf& target, double constraint, ForwardIterator first, ForwardIterator last, const RandNumberGenerator& rand, const ComputeLayerIndex& getLayerIndex ) : gen_(rand), getLayerIndex_(getLayerIndex) { // constraint can vary from 0 to 1 mu_ = constraint / ( 1.00001 - constraint); nb_of_categories_ = target[0].size(); for (int i=0; i<target.size(); i++) { vector<double> local_pdf( target[i].p_begin(), target[i].p_end() ); target_pdf_.push_back( local_pdf ); vector<double> prob; nb_of_data_.push_back(0); for (int j=0; j<target[0].size(); j++) prob.push_back(0); current_histogram_.push_back(prob); } int z; // Compute the pdf of range [first, last) for( ; first != last ; ++first) { if( ! first->is_informed() ) continue; z = getLayerIndex_( *first ); current_histogram_[z][ int( first->property_value() ) ] ++; nb_of_data_[z] ++; } }
ForwardIterator scan_keyword(InputIterator& b, InputIterator e, ForwardIterator kb, ForwardIterator ke, std::ios_base::iostate& err ) { typedef typename std::iterator_traits<InputIterator>::value_type CharT; size_t nkw = std::distance(kb, ke); const unsigned char doesnt_match = '\0'; const unsigned char might_match = '\1'; const unsigned char does_match = '\2'; unsigned char statbuf[100]; unsigned char* status = statbuf; // Change free by free_aux to avoid // Error: Could not find a match for boost::interprocess::unique_ptr<unsigned char, void(*)(void*)>::unique_ptr(int, extern "C" void(void*)) unique_ptr<unsigned char, void(*)(void*)> stat_hold(0, free_aux); if (nkw > sizeof(statbuf)) { status = (unsigned char*)malloc(nkw); if (status == 0) throw_exception(std::bad_alloc()); stat_hold.reset(status); } size_t n_might_match = nkw; // At this point, any keyword might match size_t n_does_match = 0; // but none of them definitely do // Initialize all statuses to might_match, except for "" keywords are does_match unsigned char* st = status; for (ForwardIterator ky = kb; ky != ke; ++ky, ++st) { if (!ky->empty()) *st = might_match; else { *st = does_match; --n_might_match; ++n_does_match; } } // While there might be a match, test keywords against the next CharT for (size_t indx = 0; b != e && n_might_match > 0; ++indx) { // Peek at the next CharT but don't consume it CharT c = *b; bool consume = false; // For each keyword which might match, see if the indx character is c // If a match if found, consume c // If a match is found, and that is the last character in the keyword, // then that keyword matches. // If the keyword doesn't match this character, then change the keyword // to doesn't match st = status; for (ForwardIterator ky = kb; ky != ke; ++ky, ++st) { if (*st == might_match) { CharT kc = (*ky)[indx]; if (c == kc) { consume = true; if (ky->size() == indx+1) { *st = does_match; --n_might_match; ++n_does_match; } } else { *st = doesnt_match; --n_might_match; } } } // consume if we matched a character if (consume) { ++b; // If we consumed a character and there might be a matched keyword that // was marked matched on a previous iteration, then such keywords // which are now marked as not matching. if (n_might_match + n_does_match > 1) { st = status; for (ForwardIterator ky = kb; ky != ke; ++ky, ++st) { if (*st == does_match && ky->size() != indx+1) { *st = doesnt_match; --n_does_match; } } } } } // We've exited the loop because we hit eof and/or we have no more "might matches". if (b == e) err |= std::ios_base::eofbit; // Return the first matching result for (st = status; kb != ke; ++kb, ++st) if (*st == does_match) break; if (kb == ke) err |= std::ios_base::failbit; return kb; }
std::pair<status, ForwardIterator> wait_any(ForwardIterator first, ForwardIterator last) { using std::advance; BOOST_ASSERT(first != last); typedef typename std::iterator_traits<ForwardIterator>::difference_type difference_type; bool all_trivial_requests = true; difference_type n = 0; ForwardIterator current = first; while (true) { // Check if we have found a completed request. If so, return it. if (current->m_requests[0] != MPI_REQUEST_NULL && (current->m_requests[1] != MPI_REQUEST_NULL || current->m_handler)) { if (optional<status> result = current->test()) return std::make_pair(*result, current); } // Check if this request (and all others before it) are "trivial" // requests, e.g., they can be represented with a single // MPI_Request. all_trivial_requests = all_trivial_requests && !current->m_handler && current->m_requests[1] == MPI_REQUEST_NULL; // Move to the next request. ++n; if (++current == last) { // We have reached the end of the list. If all requests thus far // have been trivial, we can call MPI_Waitany directly, because // it may be more efficient than our busy-wait semantics. if (all_trivial_requests) { std::vector<MPI_Request> requests; requests.reserve(n); for (current = first; current != last; ++current) requests.push_back(current->m_requests[0]); // Let MPI wait until one of these operations completes. int index; status stat; BOOST_MPI_CHECK_RESULT(MPI_Waitany, (n, &requests[0], &index, &stat.m_status)); // We don't have a notion of empty requests or status objects, // so this is an error. if (index == MPI_UNDEFINED) boost::throw_exception(exception("MPI_Waitany", MPI_ERR_REQUEST)); // Find the iterator corresponding to the completed request. current = first; advance(current, index); current->m_requests[0] = requests[index]; return std::make_pair(stat, current); } // There are some nontrivial requests, so we must continue our // busy waiting loop. n = 0; current = first; all_trivial_requests = true; } } // We cannot ever get here BOOST_ASSERT(false); }
OutputIterator wait_all(ForwardIterator first, ForwardIterator last, OutputIterator out) { typedef typename std::iterator_traits<ForwardIterator>::difference_type difference_type; using std::distance; difference_type num_outstanding_requests = distance(first, last); std::vector<status> results(num_outstanding_requests); std::vector<bool> completed(num_outstanding_requests); while (num_outstanding_requests > 0) { bool all_trivial_requests = true; difference_type idx = 0; for (ForwardIterator current = first; current != last; ++current, ++idx) { if (!completed[idx]) { if (optional<status> stat = current->test()) { // This outstanding request has been completed. We're done. results[idx] = *stat; completed[idx] = true; --num_outstanding_requests; all_trivial_requests = false; } else { // Check if this request (and all others before it) are "trivial" // requests, e.g., they can be represented with a single // MPI_Request. all_trivial_requests = all_trivial_requests && !current->m_handler && current->m_requests[1] == MPI_REQUEST_NULL; } } } // If we have yet to fulfill any requests and all of the requests // are trivial (i.e., require only a single MPI_Request to be // fulfilled), call MPI_Waitall directly. if (all_trivial_requests && num_outstanding_requests == (difference_type)results.size()) { std::vector<MPI_Request> requests; requests.reserve(num_outstanding_requests); for (ForwardIterator current = first; current != last; ++current) requests.push_back(current->m_requests[0]); // Let MPI wait until all of these operations completes. std::vector<MPI_Status> stats(num_outstanding_requests); BOOST_MPI_CHECK_RESULT(MPI_Waitall, (num_outstanding_requests, &requests[0], &stats[0])); for (std::vector<MPI_Status>::iterator i = stats.begin(); i != stats.end(); ++i, ++out) { status stat; stat.m_status = *i; *out = stat; } return out; } all_trivial_requests = false; } return std::copy(results.begin(), results.end(), out); }