Rect packIntoPlace(std::list<Vec2>& Skyline, const Vec2& r, std::list<Vec2>::iterator place) { float x = 0; auto width = r.width(); //Initialize x auto first = Skyline.begin(); auto last = Skyline.end(); while (first != last && first != place) { x += first->width(); first++; } auto newHeight = place->height() + r.height(); auto rectangle = newRect(Vec2(x, place->height()), r); while (place != last && width > 0) { if (width >= place->width()) { auto newPlace = Skyline.insert(std::next(place), Vec2(place->width(), newHeight)); Skyline.erase(place); place = newPlace; width -= place->width(); } else { //need to split skyline Skyline.insert(place, Vec2(width, newHeight)); auto newPlace1 = Skyline.insert(std::next(place), Vec2(place->width() - width, place->height())); Skyline.erase(place); place = newPlace1; width = 0; } place++; } return rectangle; }
static void getSourcesAndHeaders(const std::list<std::string> &paths, std::list<std::string> &headers, std::list<std::string> &sources) { std::list<std::string> exts; std::list<std::string> aux; std::cout << "Obteniendo Headers\n"; exts.push_back(".h"); headers.clear(); for(std::list<std::string>::const_iterator it = paths.begin(); it != paths.end(); ++it){ assert(FileManager::getInstance()->getAllFiles(*it, aux, exts)); headers.insert(headers.begin(), aux.begin(), aux.end()); } std::cout << "Obteniendo Sources\n"; exts.clear(); aux.clear(); exts.push_back(".cpp"); sources.clear(); for(std::list<std::string>::const_iterator it = paths.begin(); it != paths.end(); ++it){ assert(FileManager::getInstance()->getAllFiles(*it, aux, exts)); sources.insert(sources.begin(), aux.begin(), aux.end()); } }
void draw_previous_suggestions(std::vector<std::string> words, bool contextChange, const int starty, int startx) { static std::list< std::vector<std::string> > previousSuggestions; static std::vector< WINDOW* > windows; // clear out existing windows for (std::vector< WINDOW* >::iterator winit = windows.begin(); winit != windows.end(); winit++) { wclear(*winit); wrefresh(*winit); delwin(*winit); } windows.clear(); if (contextChange) { // insert a context change marker in the list of previous // suggestions // std::vector< std::string > marker; for (int i = 0; i < atoi(suggestions.c_str()); i++) { marker.push_back("|"); } previousSuggestions.insert(previousSuggestions.begin(), marker); } previousSuggestions.insert(previousSuggestions.begin(), words); for (std::list< std::vector<std::string> >::const_iterator listit = previousSuggestions.begin(); (listit != previousSuggestions.end() && startx < COLS); // don't draw window off the screen listit++) { int height = listit->size() + 2; int width = getGreatestSuggestionLength(*listit) + 2; WINDOW* win = newwin(height, width, starty, startx); wclear(win); box(win, 0, 0); int line = 1; for (std::vector<std::string>::const_iterator strit = listit->begin(); strit != listit->end(); strit++) { mvwprintw(win, line, 1, strit->c_str()); line++; } wrefresh(win); windows.push_back(win); startx += width + 2; } }
// заключить fig-объекты в составной объект. void fig_make_comp(std::list<fig_object> & objects){ if ((objects.size()<1) || (objects.begin()->size()<1)) return; iRect r = fig_range(objects); fig_object o; o.type=6; o.push_back(r.TLC()); o.push_back(r.BRC()); objects.insert(objects.begin(), o); o.type = -6; objects.insert(objects.end(), o); }
void insert(OnlineFileRequest* request) { if (request->resource.priority == Resource::Priority::Regular) { firstLowPriorityRequest = queue.insert(firstLowPriorityRequest, request); firstLowPriorityRequest++; } else { if (firstLowPriorityRequest == queue.end()) { firstLowPriorityRequest = queue.insert(queue.end(), request); } else { queue.insert(queue.end(), request); } } }
void VoronoiSeedsGenerator::insertIntoList(std::list<Seed>& list, Seed& seed) { /* * If the list is empty, just pushing back the new seed. * Otherwise, we have to determine the position to insert the seed to. * In order to do so, we simply iterate over the seeds, comparing the * distance to center of the one to insert with the latter's ones. * The last comparison needs extra care, since we may have to push * back the seed to insert if its distance to center is greater than * the one of the list's last seed. */ if (list.empty()) { list.push_back(seed); } else { auto current = list.begin(); auto last = list.end(); float distance = DIST_TO_CENTER(seed); while ((current != last) && (distance > DIST_TO_CENTER(*current))) { current++; } if (current != last) { list.insert(current, seed); } else { list.push_back(seed); } } }
DataStatus DataPointGFAL::List(std::list<FileInfo>& files, DataPointInfoType verb) { // Open the directory struct dirent *d; DIR *dir; { GFALEnvLocker gfal_lock(usercfg, lfc_host); dir = gfal_opendir(GFALUtils::GFALURL(url).c_str()); } if (!dir) { logger.msg(VERBOSE, "gfal_opendir failed: %s", StrError(gfal_posix_code_error())); int error_no = GFALUtils::HandleGFALError(logger); return DataStatus(DataStatus::ListError, error_no); } // Loop over the content of the directory while ((d = gfal_readdir (dir))) { // Create a new FileInfo object and add it to the list of files std::list<FileInfo>::iterator f = files.insert(files.end(), FileInfo(d->d_name)); // If information about times, type or access was also requested, do a stat if (verb & (INFO_TYPE_TIMES | INFO_TYPE_ACCESS | INFO_TYPE_TYPE)) { URL child_url = URL(url.plainstr() + '/' + d->d_name); logger.msg(DEBUG, "List will stat the URL %s", child_url.plainstr()); do_stat(child_url, *f); } } // Then close the dir if (gfal_closedir (dir) < 0) { logger.msg(WARNING, "gfal_closedir failed: %s", StrError(gfal_posix_code_error())); int error_no = GFALUtils::HandleGFALError(logger); return DataStatus(DataStatus::ListError, error_no); } return DataStatus::Success; }
/* * Adds the given item to the cache and opens it. * Returns the key. */ LRUKey add_open(T *data_ptr) { std::unique_lock<SpinLock> lock(slock); typename std::list<LRUPair<T>>::iterator it; LRUPair<T> data_pair; LRUKey key; do { key = next_key++; } while ((bool)(map.count(key)) || key == 0); byte_count += data_ptr->bytes(); // Remove last element(s) if necessary to make room while (byte_count >= max_bytes) { if (!erase_last()) break; } // Add the new data data_pair.key = key; data_pair.data_ptr = data_ptr; data_pair.active_readers = 1; it = elements.begin(); it = elements.insert(it, data_pair); // Log it in the map map[key] = it; return key; }
void heuristic_search(const cholmod_sparse* const NNE, std::list<int>& ordering, std::list<int>& MIS) { std::list<int> tempMIS; size_t to_check = static_cast<size_t>(std::sqrt(static_cast<long double>(NNE->ncol))) + 10000; if (to_check > NNE->ncol) { to_check = NNE->ncol; } // 1,2,3,4,5 // 2,1,3,4,5 // 1,3,2,4,5 // 3,2,4,1,5 // 2,4,1,5,3 // etc... std::list<int>::iterator insert_position = ordering.begin(); for (size_t i = 0; i < to_check; ++i) { ++insert_position; ordering.insert(insert_position, ordering.front()); ordering.pop_front(); findMIS_in_sp_order(NNE, ordering, tempMIS); if (tempMIS.size() > MIS.size()) { MIS.swap(tempMIS); } tempMIS.clear(); } }
void addToList( container &c ) { c.time = c.fixed_time; c.time += time_passed; if( time_passed > c.time ) { // reset time_passed for( auto &e : time_list ) { e.time -= time_passed; } time_passed = 0; } if( time_list.size() > 0 ) { // find place to insert bool found = false; for( auto it = time_list.begin(); it != time_list.end(); it++ ) { if( it->time > c.time ) { time_list.insert( it, c ); found = true; break; } } if( !found ) time_list.push_back( c ); } else { time_list.push_front( c ); } }
static void reorderList(GraphNodeIndex id_suc, DistanceType newdist, std::list<std::pair<GraphNodeIndex, DistanceType>>& nodeSet) { typedef std::pair<GraphNodeIndex, DistanceType> DijkstraElement; typename std::list<DijkstraElement>::iterator it; // Searching for the node "id_suc" in the list for (it = nodeSet.begin(); it != nodeSet.end(); it++) { if (it->first == id_suc) { break; } } // 'it' is in the right place... if (it != nodeSet.end()) { nodeSet.erase(it); } // Searching for the new position of "id_suc" for (it = nodeSet.begin(); (it != nodeSet.end()) && (it->second < newdist); it++) { // do nothing } nodeSet.insert(it, DijkstraElement(id_suc, newdist)); }
CVdMdlIfs* CNotFactory::create_model( char* name, char* in_cir_name ) { std::list<CNot*>::iterator inot_mdl; if( strcmp( pNotModelName, name )!= 0 ) { // TODO: Error message - unsupported model return 0; } for( inot_mdl=not_mdls.begin(); inot_mdl!=not_mdls.end(); inot_mdl++ ) { if((*inot_mdl)->name.compare( in_cir_name )== 0 ) { // TODO: Error msg - Already exists return 0; } } CNot* pNot = 0; pNot = new CNot(); pNot->name = in_cir_name; pNot->msgI = pMsgI; msg_info( "Subckt[%p] Model[%s] was created", pNot, name ); not_mdls.insert( not_mdls.end(), pNot ); return pNot; }
void sleep(uint32 seconds) { IBMRAS_DEBUG(fine,"in thread.cpp->sleep"); /* each sleep has its own mutex and condvar - the condvar will either be triggered by condBroadcast or it will timeout.*/ pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t c = PTHREAD_COND_INITIALIZER; IBMRAS_DEBUG(debug,"Updating condvar map"); // lock the condvar map for update pthread_mutex_lock(&condMapMux); std::list<pthread_cond_t>::iterator it = condMap.insert(condMap.end(),c); pthread_mutex_unlock(&condMapMux); pthread_mutex_lock(&m); struct timespec t; clock_gettime(CLOCK_REALTIME, &t); t.tv_sec += seconds; /* configure the sleep interval */ IBMRAS_DEBUG_1(finest,"Sleeping for %d seconds", seconds); pthread_cond_timedwait(&c, &m, &t); IBMRAS_DEBUG(finest,"Woke up"); pthread_mutex_unlock(&m); pthread_mutex_lock(&condMapMux); condMap.erase(it); pthread_mutex_unlock(&condMapMux); }
void ModuleManager::getSortedList(zAPI::IModule::Hook hook, zAPI::IModule::Event event, std::list<zAPI::IModuleInfo*>& nList) { std::list<RefCounter<zAPI::IModuleInfo*>*>::iterator it = this->_modules.back().ptr.hooks[hook].begin(); std::list<RefCounter<zAPI::IModuleInfo*>*>::iterator ite = this->_modules.back().ptr.hooks[hook].end(); for (; it != ite; ++it) { int prio = (*it)->ptr->getInstance()->getPriority(event); std::list<zAPI::IModuleInfo*>::iterator nIt = nList.begin(); std::list<zAPI::IModuleInfo*>::iterator nIte = nList.end(); bool inserted = false; if (nIt == nIte) nList.push_back((*it)->ptr); else { for (; nIt != nIte; ++nIt) { int nPrio = (*nIt)->getInstance()->getPriority(event); if (prio < nPrio) { nList.insert(nIt, (*it)->ptr); inserted = true; break; } } if (!inserted) nList.push_back((*it)->ptr); } } }
//Вспомогательная функция формирования текста статьи из Gumbo-дерева void makeText(GumboNode *a_entry, std::list<std::u32string> &a_lines) { assert(a_entry != nullptr); std::list<std::u32string> l_lines; Utility::Gumbo::traverse(a_entry, [&](GumboNode *a)->bool { if (a->type == GUMBO_NODE_ELEMENT && (a->v.element.tag == GUMBO_TAG_P || a->v.element.tag == GUMBO_TAG_H1 || a->v.element.tag == GUMBO_TAG_H2 || a->v.element.tag == GUMBO_TAG_H3 || a->v.element.tag == GUMBO_TAG_H4)) { l_lines.push_back(std::u32string()); l_lines.push_back(std::u32string()); } if (a->type != GUMBO_NODE_TEXT) return false; if (a->parent->v.element.tag != GUMBO_TAG_SCRIPT && a->parent->v.element.tag != GUMBO_TAG_STYLE && a->parent->v.element.tag != GUMBO_TAG_TEXTAREA) { const std::u32string l_utf32text(Encoding::utf8to32(a->v.text.text)); Text::format(l_lines, l_utf32text, 80); } if (a->parent->v.element.tag == GUMBO_TAG_A && a->index_within_parent + 1 == a->parent->v.element.children.length) { GumboAttribute *const l_href = ::gumbo_get_attribute(&a->parent->v.element.attributes, "href"); if (l_href != nullptr) { const std::string l_asText(std::string(" [") + l_href->value + "]"); Text::format(l_lines, Encoding::utf8to32(l_asText), 80); } } return false; }); a_lines.insert(a_lines.end(), l_lines.begin(), l_lines.end()); }
boost::shared_ptr<Shape> CompOperator::apply(boost::shared_ptr<Shape>& shape, const Grammar& grammar, std::list<boost::shared_ptr<Shape> >& stack) { std::vector<boost::shared_ptr<Shape> > shapes; shape->comp(name_map, shapes); stack.insert(stack.end(), shapes.begin(), shapes.end()); return boost::shared_ptr<Shape>(); }
/// Free the pointer and its memory to the list of free subblocks. void free_subblock(uint8_t* ptr__, size_t size__) { /* offset from the beginning of the memory buffer */ size_t offset = static_cast<size_t>(ptr__ - buffer_.get()); auto check_free_subblocks = [&]() { #ifndef NDEBUG if (free_subblocks_.size() <= 1) { return; } auto it = free_subblocks_.begin(); auto it1 = it; it1++; for (; it1 != free_subblocks_.end(); it1++) { /* if offse + size of the previous free block is larger than the offset of next block this is an error */ if (it->first + it->second > it1->first) { throw std::runtime_error("wrong order of free memory blocks"); } } #endif }; for (auto it = free_subblocks_.begin(); it != free_subblocks_.end(); it++) { /* check if we can attach released subblock before this subblock */ if (it->first == offset + size__) { it->first = offset; it->second += size__; check_free_subblocks(); return; } /* check if we can attach released subblock after this subblock */ if (it->first + it->second == offset) { it->second += size__; /* now check if we can attach this subblock to the top of the next one */ auto it1 = it; it1++; if (it1 != free_subblocks_.end()) { if (it->first + it->second == it1->first) { /* merge second block into first and erase it */ it->second += it1->second; free_subblocks_.erase(it1); } } check_free_subblocks(); return; } /* finally, check if the released subblock is before this subblock, but not touching it */ if (offset + size__ < it->first) { free_subblocks_.insert(it, std::make_pair(offset, size__)); check_free_subblocks(); return; } } /* otherwise this is the tail subblock */ free_subblocks_.push_back(std::make_pair(offset, size__)); check_free_subblocks(); }
void RDirNode::getFilesRecursive(std::list<RFile*>& files) const { //add this dirs files files.insert(files.begin(), this->files.begin(), this->files.end()); for(std::list<RDirNode*>::const_iterator it = children.begin(); it != children.end(); it++) { (*it)->getFilesRecursive(files); } }
void ShapesScenePrivate::insertNode(const NodePtr &node, int index) { auto it = m_nodes.begin(); while (index != 0) { --index; ++it; } m_nodes.insert(it, node); }
void addGroup (const gchar *name, const gchar *icon_path, const gchar *nick, const gchar *sort_key) { // calculate position int pos; { std::list <std::string>::iterator it; for (it = sort_keys.begin(), pos = 0; it != sort_keys.end(); it++, pos++) if (strcmp (it->c_str(), sort_key) >= 0) break; sort_keys.insert (it, sort_key); } // label widget GtkWidget *tab_label, *image, *label; GdkPixbuf *icon = NULL; if (icon_path) { GError *error = 0; std::string path = ICONS + std::string (icon_path) + ".png"; icon = gdk_pixbuf_new_from_file (path.c_str(), &error); if (!icon) g_warning ("Could not load icon: %s.\nReason: %s", icon_path, error->message); } tab_label = gtk_hbox_new (FALSE, 0); label = gtk_label_new (name); if (icon) image = gtk_image_new_from_pixbuf (icon); if (icon) gtk_box_pack_start (GTK_BOX (tab_label), image, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (tab_label), label, TRUE, TRUE, icon ? 6 : 0); // page widget GtkListStore *store = gtk_list_store_new (3, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING); m_stores [nick] = store; GtkWidget *icons_view; icons_view = gtk_icon_view_new_with_model (GTK_TREE_MODEL (store)); gtk_icon_view_set_text_column (GTK_ICON_VIEW (icons_view), 0); gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (icons_view), 1); g_signal_connect(G_OBJECT (icons_view), "item-activated", G_CALLBACK (executeCommand), this); GtkWidget *page; page = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (page), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (page), GTK_SHADOW_IN); gtk_container_add (GTK_CONTAINER (page), icons_view); // add those to the notebook gtk_widget_show_all (tab_label); gtk_notebook_insert_page_menu (GTK_NOTEBOOK (m_widget), page, tab_label, NULL, pos); }
void log_request(const std::list< boost::asio::const_buffer >& d, size_t sz, std::list< std::string >& session_extracts, std::list< boost::asio::const_buffer >& session_log, time_t session_time) { session_extracts.push_back(str( boost::format(">> %2% [%1%]:") % sz % (time(0) - session_time))); const std::string& s = session_extracts.back(); session_log.push_back( boost::asio::const_buffer(s.c_str(), s.size()) ); session_log.insert(session_log.end(), d.begin(), d.end()); }
void CCallback::OnMIDI(tuchar ucStatus, tuchar ucDB1, tuchar ucDB2) { // WindowPtr pFront = FrontWindow(); // WindowPtr pThisWindow = gpNexsynWindow; //if(window != FrontWindow()) // SelectWindow(gpNexsynWindow); // BeginUpdate(window); // SetPortWindowPort(window); // EndUpdate(window); CAutoLock Lock(mMutexAudio); // Timestamp the MIDI tuint32 uiTimeStamp = 0; if (mpAudioDevice) { uiTimeStamp = mpAudioDevice->GetTimeStamp(); // Just to be on the safe side if (uiTimeStamp >= mpAudioDevice->GetBufferSize()) { uiTimeStamp = mpAudioDevice->GetBufferSize(); } } // Create MIDI Event kspi::SMIDIEvent Event; Event.iTimeStamp = uiTimeStamp; Event.pcData[0] = ucStatus; Event.pcData[1] = ucDB1; Event.pcData[2] = ucDB2; Event.pcData[3] = 0; // The event is ready, but the timestamp may be off. // This is because there's an interval from the time the audio engine resets its "start-of-buffer-time" to the time the processing is actually started. // If a MIDI event occurs in this interval it will receive a very low timestamp (typically 0 I believe) because the audio engine believes it belongs to the next buffer // The most important thing is to avoid hanging notes, so what we do is to detect the case where hanging notes would occur, i.e. when a note-off would occur before a note-on // So, this means that if the current queue is empty we will accept the jitter, but if the queue is not empty we should be able to detect the hanging-notes case by comparing the timestamp of our last event in the buffer. // If the current timestamp is less than the timestamp of the last event we know this has occured, and hanging notes is a possibility. // What we do then is to give it the timestamp of the last event. // A better approach would be to keep a seperate event list for the next buffer. But at least we don't get hanging notes. std::list<kspi::SMIDIEvent>::iterator it = mMIDIEvents.end(); it--; if (it != mMIDIEvents.end()) { tuint32 uiTimeStampEvent = it->iTimeStamp; if (Event.iTimeStamp < uiTimeStampEvent) { Event.iTimeStamp = uiTimeStampEvent; } } // Put it in MIDI queue mMIDIEvents.insert(mMIDIEvents.end(), Event); }
void SwaptionHelper::addTimesTo(std::list<Time>& times) const { calculate(); Swaption::arguments args; swaption_->setupArguments(&args); std::vector<Time> swaptionTimes = DiscretizedSwaption(args, termStructure_->referenceDate(), termStructure_->dayCounter()).mandatoryTimes(); times.insert(times.end(), swaptionTimes.begin(), swaptionTimes.end()); }
void LoggerEngine::get_messages (std::list<MessageEntry>& messages) { if (log_updater == nullptr) return; log_updater->mutex.lock(); std::list<LogEntry>::iterator it; for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++) { messages.insert(messages.end(), it->entry_list.begin(), it->entry_list.end()); } log_updater->mutex.unlock(); }
void Identifier::algorithm_nearestFit(std::list<Frame> & frames) { Frame * current = &frames.front(); Frame * previous = &(*(++frames.begin())); static std::list<std::list<Error>> errorMapping; static std::vector<std::list<std::list<Error>::iterator>> errorMapIterators; errorMapping.clear(); errorMapIterators.clear(); float distanceError, areaError, error; std::list<Error>::iterator errorMapIteratorIterator; std::list<std::list<Error>>::iterator errorMapIterator; int pIndex; for(std::vector<Object>::iterator c = current->objects.begin(); c != current->objects.end(); c++) { errorMapIterator = errorMapping.insert(errorMapping.end(), std::list<Error>()); errorMapIterators.push_back(std::list<std::list<Error>::iterator>()); pIndex = 0; for(std::vector<Object>::iterator p = previous->objects.begin(); p != previous->objects.end(); p++) { distanceError = std::pow(c->x - p->x - p->dx, 2) + std::pow(c->y - p->y - p->dy, 2); error = distanceError; errorMapIteratorIterator = errorMapping.back().insert(errorMapping.back().end(),Error(&(*p), &(*c), pIndex, error)); errorMapIterators[pIndex].push_back(errorMapIteratorIterator); pIndex++; } errorMapping.back().sort(); } for(int i = 0; i < std::min(current->objects.size(), previous->objects.size()); i++) { errorMapping.sort(); errorMapping.front().front().current->id = errorMapping.front().front().previous->id; errorMapping.front().front().current->model = errorMapping.front().front().previous->model; errorMapping.front().front().current->isDecided = true; while(it != errorMapIterator->end()) .erase(it) } for(std::vector<Object>::iterator c = current->objects.begin(); c != current->objects.end(); c++) { if(!c->isDecided) c->id = newID(); } }
void merge(const binomial_heap& heap) { auto it1 = root_list.begin(); auto it2 = heap.root_list.begin(); while (it2 != heap.root_list.end()) //merge { if ((*it1)->get_size() >= (*it2)->get_size()) { root_list.insert(it1, *it2); ++it2; } ++it1; } auto it = root_list.begin(); while ((it != root_list.end()) && (++it != root_list.end())) { --it; if ((*it)->get_size() == (*(++it))->get_size()) { typename std::list<binomial_tree<T>*>::iterator add; if (++it != root_list.end()) { --it; if ((*it)-> get_size() == (*(++it))->get_size()) { add = it; } else { add = --it; } } else { add = --it; } --it; *it = (*it)->merge(**add); auto copy = it; ++it; root_list.erase(it); it = copy; } else { ++it; } } }
// copylist // copia una lista de Ini::IdList a una. // El tipo de la lista destino se especifica como Template template <class T> static copylist( const Ini::IdList &l, std::list<T> &lista2 ) { std::list<T>::const_iterator cursor ; lista2.insert (lista2.end(), l.begin(), l.end()); // descomentar para ver el resultado //for( cursor = lista2.begin() ; cursor != lista2.end() ; cursor ++ ) //{ // cout << '[' << (*cursor) << ']' << endl ; //} }
void add(T a) { if (root_list.size() != 0) { binomial_heap<T> new_heap(a); this->merge(new_heap); } else { binomial_tree<T>* tree = new binomial_tree<T>(a); root_list.insert(root_list.begin(), tree); } }
// ------------------------------------------------------------------------------------------------ // Updates the node graph - removes all nodes which have the "remove" flag set and the // "don't remove" flag not set. Nodes with meshes are never deleted. bool UpdateNodeGraph(aiNode* node,std::list<aiNode*>& childsOfParent,bool root) { bool b = false; std::list<aiNode*> mine; for (unsigned int i = 0; i < node->mNumChildren;++i) { if(UpdateNodeGraph(node->mChildren[i],mine,false)) b = true; } // somewhat tricky ... mNumMeshes must be originally 0 and MSB2 may not be set, // so we can do a simple comparison against MSB here if (!root && AI_RC_UINT_MSB == node->mNumMeshes ) { // this node needs to be removed if(node->mNumChildren) { childsOfParent.insert(childsOfParent.end(),mine.begin(),mine.end()); // set all children to NULL to make sure they are not deleted when we delete ourself for (unsigned int i = 0; i < node->mNumChildren;++i) node->mChildren[i] = NULL; } b = true; delete node; } else { AI_RC_UNMASK(node->mNumMeshes); childsOfParent.push_back(node); if (b) { // reallocate the array of our children here node->mNumChildren = (unsigned int)mine.size(); aiNode** const children = new aiNode*[mine.size()]; aiNode** ptr = children; for (std::list<aiNode*>::iterator it = mine.begin(), end = mine.end(); it != end; ++it) { *ptr++ = *it; } delete[] node->mChildren; node->mChildren = children; return false; } } return b; }
struct SersiProg* execute(const wchar_t* name, const wchar_t* progname, const wchar_t* progparam, const wchar_t* dirparam, bool autoRestart, bool dailyRestart) { wchar_t* l_progparam = (wchar_t*)progparam; wchar_t* l_dirparam = (wchar_t*)dirparam; if( l_progparam == NULL || l_progparam[0] == L'\0' ) l_progparam = NULL; if( l_dirparam == NULL || l_dirparam[0] == L'\0' ) l_dirparam = NULL; if( !check_config ) { SHELLEXECUTEINFOW* shi; shi = (SHELLEXECUTEINFOW*)malloc(sizeof(SHELLEXECUTEINFOW)); ZeroMemory(shi, sizeof(SHELLEXECUTEINFOW)); shi->cbSize = sizeof(SHELLEXECUTEINFOW); shi->fMask = SEE_MASK_NOCLOSEPROCESS; shi->hwnd = 0; shi->lpVerb = L"open"; shi->lpFile = progname; shi->lpParameters = l_progparam; shi->lpDirectory = l_dirparam; shi->nShow = 0; ShellExecuteEx( shi ); SersiProg* p = (SersiProg*)malloc(sizeof(SersiProg)); p->name = _wcsdup(name); p->process = shi; p->autoRestart = autoRestart; p->dailyRestart = dailyRestart; plist.insert( plist.end(), p ); return p; } else { #ifdef WINDOWMODE insertItem(name, progname, l_dirparam, l_progparam, autoRestart, dailyRestart); #else wprintf(L"Application %s\nOpen: %s\nParam: %s\nDir: %s\nAuto Restart: %s\nDailyRestart: %s\n\n", name, progname, progparam, dirparam, autoRestart?L"yes":L"no", dailyRestart?L"yes":L"no"); #endif return NULL; } }