TreeNode * TreeNode::child(int rowNumber) { TreeNode * child = nullptr; if( is_not_null(m_node) ) { // if the TreeNode corresponding to this child has already been created, // it is returned... if (rowNumber >= 0 && rowNumber < child_count()) child = m_child_nodes.at(rowNumber); // ...otherwise, if the index is valid, it is created and returned... if(child == nullptr && rowNumber>= 0 && rowNumber < child_count()) { Handle< CNode > childNode; childNode = m_node->child(rowNumber); child = new TreeNode(childNode, this, rowNumber); m_child_nodes.replace(rowNumber, child); } } // ...if the index is not valid, return a nullptr pointer return child; }
TabWidget::TabWidget(Widget* parent) : Widget(parent), m_header(new TabHeader(nullptr)), m_content(new StackedWidget(nullptr)) { // since TabWidget::addChild is going to throw an exception to prevent // mis-use of this class, add the children directly Widget::add_child(child_count(), m_header); Widget::add_child(child_count(), m_content); m_header->set_callback([this](int i) { m_content->set_selected_index(i); if (m_callback) m_callback(i); }); }
static int test_rfork1(int idx, struct bproc_test_info_t *inf) { int err, i; #if 0 int cc, ncc, lw; /* ACTUAL values */ int c_cc, c_ncc, c_lw; /* CORRECT values */ #endif printf(" ppid=%d(%d)", getpid(), bproc_currnode()); fflush(stdout); for (i=1; i < inf->nprocs; i++) { inf->pid[i] = bproc_rfork(inf->node[i]); if (inf->pid[i] < 0) { fprintf(stderr, "bproc_rfork(%d): %s\n", inf->pid[i], bproc_strerror(errno)); exit(1); } if (inf->pid[i] == 0) { /* CHILD */ exit(0); } printf(" pid=%d", inf->pid[i]); fflush(stdout); } #if 0 /* This sanity check is broken */ /* Sanity check our process tree */ cc = child_count(); ncc = nlchild_count(); lw = local_wait(0); c_cc = 2; c_ncc = (inf->pid[0] == inf->pid[1] || inf->pid[0] == -1) ? 0 : 2; c_lw = (inf->pid[0] == inf->pid[1] || inf->pid[0] == -1) ? 1 : 0; if ((cc != c_cc) || (ncc != c_ncc) || (lw != c_lw)) { printf("\nProcess State:\n"); printf(" kern mine\n"); printf(" child_count = %-4d %d%s\n", cc, c_cc, cc != c_cc ? " ** MISMATCH **":""); printf(" nlchild_count = %-4d %d%s\n", ncc, c_ncc, ncc != c_ncc ? " ** MISMATCH **":""); printf(" local_wait = %-4d %d%s\n", lw, c_lw, lw != c_lw ? " ** MISMATCH **":""); for (i=1; i < inf->nprocs; i++) printf(" ch[%d]=%d(%s)", i, inf->pid[i], proc_str(proc_arr(inf->arr,i))); printf("\n"); } #endif err = 0; for (i=1; i < inf->nprocs; i++) { if (wait(0) < 0) { printf("wait: %s", strerror(errno)); err = 1; } } exit(err); }
int test_clone1(int idx, struct bproc_test_info_t *inf) { int pid; int err = 0, i; int cc, ncc, lw; /* ACTUAL values */ int c_cc, c_ncc, c_lw; /* CORRECT values */ pid = bproc_rfork(inf->node[1]); if (pid < 0) { perror("bproc_rfork"); exit(1); } if (pid == 0) { void *stack; /* Child #1 */ stack = malloc(8192); pid = clone(cfunc, stack+4096, CLONE_PARENT|SIGCHLD, 0); if (pid < 0) { fprintf(stderr, "clone: %s", bproc_strerror(errno)); exit(1); } usleep(DELAY); exit(0); } usleep(DELAY); /* Sanity check our process tree */ cc = child_count(); ncc = nlchild_count(); lw = local_wait(0); c_cc = 2; c_ncc = (inf->node[0] == inf->node[1] || inf->node[0] == -1) ? 0 : 2; c_lw = (inf->node[0] == inf->node[1] || inf->node[0] == -1) ? 1 : 0; /* Print status */ printf("%d%c %d%c %c%c ", cc, cc == c_cc ? ' ':'!', ncc, ncc== c_ncc? ' ':'!', lw ? 'L':'R', lw == c_lw ? ' ':'!'); fflush(stdout); /* Parent */ /* Two waits */ for (i=0; i < 2; i++) { if (wait(0) < 0) { printf("wait: %s", strerror(errno)); err = 1; } } if (err) exit(err); err = (cc != c_cc) || (ncc != c_ncc) || (lw != c_lw); if (err) { printf("mypid=%d", getpid()); fflush(stdout); sleep(1000); } exit(err); }
/* Обработка уведомления о запросе ассоциации */ void znet_assoc_indication( zcall_t *zc ) { neighbor_t *child_ptr; zargs_passoc_t *arg = (zargs_passoc_t *)(zc->args); bool_t alloc_addr; /* Логический флаг - выделять ли короткий адрес */ if( nwkMaxChildren <= child_count() ) goto assoc_denied; /* Достигнут максимальный порог числа детей. Больше детей заводить нельзя. */ child_ptr = nbr_place_by_eaddr( &(arg->dev_addr) ); /* Ищем место в таблице соседей */ if( !IN_TABLE( child_ptr) ) goto assoc_denied; /* Не удалось найти место в таблице соседей */ alloc_addr = TRUE; if( child_ptr->ext_addr == arg->dev_addr ) { /* Уже есть запись об узле в таблице соседей */ if( ( child_ptr->relationship == NWK_PARENT )||( child_ptr->relationship == NWK_SIBLING ) ) goto assoc_denied; /* Родителя и братьев не присоединяем */ if( ( child_ptr->relationship == NWK_CHILD ) ||( ( child_ptr->relationship == NWK_PREVIOUS_CHILD )&&( child_ptr->net_addr != 0xFFFF ) ) ) alloc_addr = FALSE; /* Не выделяем короткий адрес детям, у которых он уже есть */ } if( alloc_addr == TRUE ) { arg->assoc_addr = znet_addr_alloc( arg->cap_info.dev_type ); if( child_ptr->net_addr == 0xFFFF ) { /* Не удалось выделить короткий адрес */ bcn_cap_off( arg->cap_info.dev_type ); /* Сбрасываем флаг разрешения присоединения для данного типа устройств */ child_ptr->busy = 0; /* Запись не очень важная. Можно и удалить. */ goto assoc_denied; } } /* Заносим в таблицу соседей информацию о новом дочернем узле */ child_ptr->rx_on_when_idle = arg->cap_info.rx_on_when_idle; child_ptr->potential_parent = 0; child_ptr->permit_joining = 0; child_ptr->dev_type = ( arg->cap_info.dev_type == FFD )? ZIGBEE_ROUTER : ZIGBEE_ENDDEV; child_ptr->relationship = NWK_CHILD; child_ptr->channel = nwkExtraAttr.channel; child_ptr->beacon_order = macBeaconOrder; child_ptr->depth = nwkExtraAttr.depth+1; child_ptr->ext_addr = arg->dev_addr; child_ptr->net_addr = arg->assoc_addr; child_ptr->e_panid = nwkExtendedPANID; /* Отправляем положительный ответ узлу */ ZCALL_INIT( zc, ZCALL_MLME_ASSOC_PARENT, znet_pjoin_done ); arg->status = SUCCESS; if( IS_ERROR(zcall_invoke( zc )) ) zcall_del( zc ); return; assoc_denied: /* Присоединить узел не получилось. Отправляем узлу отрицательный ответ. */ arg->assoc_addr = 0xFFFF; arg->status = MAC_PAN_ACCESS_DENIED; ZCALL_INIT( zc, ZCALL_MLME_ASSOC_PARENT, 0 ); /* Подтверждение нам не нужно */ if( IS_ERROR(zcall_invoke( zc )) ) zcall_del( zc ); return; }
// Overridden from view::View: virtual void Layout() { views::View::Layout(); for(int i=0; i<child_count(); ++i) { AppView* child = static_cast<AppView*>(child_at(i)); child->SaveBounds(); } }
void config::merge_children(const std::string& key) { check_valid(); if (child_count(key) < 2) return; config merged_children; BOOST_FOREACH(const config &cfg, child_range(key)) { merged_children.append(cfg); }
// Overridden from view::BoundsAnimatorObserver: virtual void OnBoundsAnimatorDone(views::BoundsAnimator* animator) { DCHECK(animator == &bounds_animator_); if(show_) { for(int i=0; i<child_count(); ++i) { AppView* child = static_cast<AppView*>(child_at(i)); child->SaveBounds(); } } }
void config::merge_children(const std::string& key) { check_valid(); if (child_count(key) < 2) return; config merged_children; for (const config &cfg : child_range(key)) { merged_children.append(cfg); } clear_children(key); add_child(key,merged_children); }
static char *readline_path_generator(const char *text, int state) { static int current = 0; static char **children = NULL; static int nchildren = 0; if (state == 0) { char *end = strrchr(text, SEP); char *path; if (end == NULL) { if ((path = strdup("/*")) == NULL) return NULL; } else { end += 1; path = xcalloc(1, end - text + 2); if (path == NULL) return NULL; strncpy(path, text, end - text); strcat(path, "*"); } for (;current < nchildren; current++) free((void *) children[current]); free((void *) children); nchildren = rpmaugMatch(NULL, path, &children); current = 0; free(path); } while (current < nchildren) { char *child = children[current]; current += 1; if (!strncmp(child, text, strlen(text))) { if (child_count(child) > 0) { char *c = realloc(child, strlen(child)+2); if (c == NULL) return NULL; child = c; strcat(child, "/"); } rl_filename_completion_desired = 1; rl_completion_append_character = '\0'; return child; } else { free(child); } } return NULL; }
PandaAssembler panda_mux_create_assembler_kmer( PandaMux mux, size_t num_kmers) { PandaAssembler assembler; struct mux_data *data = malloc(sizeof(struct mux_data)); data->mux = panda_mux_ref(mux); assembler = panda_assembler_new_kmer((PandaNextSeq) mux_next, data, (PandaDestroy) mux_free, mux->logger, num_kmers); if (assembler != NULL) { char buffer[MAX_LEN]; panda_assembler_set_fail_alignment(assembler, (PandaFailAlign) mux_fail_algn, mux, NULL); sprintf(buffer, "%p:%zd", (void *) mux, child_count(mux)); panda_assembler_set_name(assembler, buffer); } return assembler; }
void config::merge_children_by_attribute(const std::string& key, const std::string& attribute) { check_valid(); if (child_count(key) < 2) return; typedef std::map<std::string, config> config_map; config_map merged_children_map; for (const config &cfg : child_range(key)) { merged_children_map[cfg[attribute]].append(cfg); } clear_children(key); for (const config_map::value_type &i : merged_children_map) { add_child(key,i.second); } }
TreeNode * TreeNode::child_by_name(const QString & name) { TreeNode * treeNode = nullptr; bool found = false; /// @todo find a better algorithm !!! for(int i = 0 ; i < child_count() && !found ; i++) { treeNode = this->child(i); if(treeNode != nullptr) found = treeNode->node_name() == name; } if(!found) treeNode = nullptr; return treeNode; }
/* Обработка уведомления об отправке ответа новому дочернему узлу */ void znet_pjoin_done( zcall_t *zc ) { neighbor_t *child_ptr; zargs_passoc_t *arg = (zargs_passoc_t *)(zc->args); if( arg->status == SUCCESS ) { /* Ответ успешно отправлен */ if( nwkMaxChildren <= child_count() ) { /* Достигнут порог для числа детей. Обновим информацию в нашем кадре-маяке */ bcn_all_cap_off(); } /* Уведомляем вышележащий уровень о новом дочернем узле. */ ZCALL_INIT( zc, ZCALL_NLME_JOIN_INDICATION, 0 ); if( IS_OK(zcall_invoke(zc)) ) return; } /* Произошла какая-то ошибка. Ищем запись узла в таблице соседей и удаляем её. */ child_ptr = child_by_eaddr( arg->dev_addr ); if( IN_TABLE( child_ptr ) ) child_ptr->busy = 0; zcall_del(zc); return; }
// If n has a single child, cuts out n and splices its child c to its parent (or if n was the root, sets c to be the new root), then returns (c, true) // Otherwise, returns (null_vertex(), false) t_vert_bool cut_and_splice(node_descriptor n) { // Can only cut and splice a node with exactly 1 child if(child_count(n) != 1) { return t_vert_bool(null_vertex(), false); } // Get a descriptor for the only child node_descriptor c = get_nth_child(n, 0).first; // And having gotten this, we can now disconnect it and its subbranch from n n->children.clear(); // Get n's parent, p, if it exists bool has_parent; node_descriptor p; boost::tie(p, has_parent) = get_parent(n); if(has_parent) { // Replace the vertex descriptor for n in p's children list with c child_list_t::iterator c_it = child_it_from_node_descriptor(n); *c_it = c; // Set c's parent to be p c->parent = p; } else { // Must be root node, just set c to be the new root m_root = static_cast< node_t* >(c); c->parent = null_vertex(); } // Now n is disconnected we can safely delete it delete static_cast< node_t* >(n); return t_vert_bool(c, true); }
void config::merge_children_by_attribute(const std::string& key, const std::string& attribute) { check_valid(); if (child_count(key) < 2) return; typedef std::map<std::string, config> config_map; config_map merged_children_map; for (const config &cfg : child_range(key)) { const std::string &value = cfg[attribute]; config_map::iterator m = merged_children_map.find(value); if ( m!=merged_children_map.end() ) { m->second.append(cfg); } else { merged_children_map.insert(make_pair(value, cfg)); } } clear_children(key); for (const config_map::value_type &i : merged_children_map) { add_child(key,i.second); } }
void AppContainer::DoAnimate() { show_ = !show_; for(int i=0; i<child_count(); ++i) { AppView* child = static_cast<AppView*>(child_at(i)); if(show_) { bounds_animator_.AnimateViewTo(child, child->GetSaveBounds()); } else { gfx::Point target_orign(-child->width(), -child->height()); gfx::Rect layout_rect = child->bounds(); gfx::Point app_view_center = layout_rect.CenterPoint(); gfx::Point view_center = GetLocalBounds().CenterPoint(); if(app_view_center.x() >= view_center.x() && app_view_center.y() <= view_center.y()) { target_orign.set_x(GetLocalBounds().right()); } else if(app_view_center.x() <= view_center.x() && app_view_center.y() >= view_center.y()) { target_orign.set_y(GetLocalBounds().bottom()); } else if(app_view_center.x() >= view_center.x() && app_view_center.y() >= view_center.y()) { target_orign.set_x(GetLocalBounds().right()); target_orign.set_y(GetLocalBounds().bottom()); } bounds_animator_.AnimateViewTo(child, gfx::Rect(target_orign, child->size())); } } }
// Repositions a node relative to its siblings, into (0-based) position new_pos, or at the end if new_pos == -1 // Returns true if the node was relocated from its original position bool reposition_node(node_descriptor n, size_t new_pos = last_child_pos) { node_descriptor p; bool has_parent; boost::tie(p, has_parent) = get_parent(n); int total_children; if(!has_parent || (total_children = child_count(p)) == 1 || new_pos != last_child_pos && new_pos >= total_children) { return false; } if(new_pos == last_child_pos) { new_pos = total_children - 1; } child_list_t::iterator c_it = child_it_from_node_descriptor(n); size_t cur_pos = c_it - p->children.begin(); if(new_pos < cur_pos) { // Moving to the left std::rotate(p->children.begin() + new_pos, c_it, c_it + 1); return true; } else if(new_pos > cur_pos) { // Moving to the right std::rotate(c_it, c_it + 1, p->children.begin() + new_pos + 1); return true; } else { // Already in desired position return false; } }
static char *readline_path_generator(const char *text, int state) { static int current = 0; static char **children = NULL; static int nchildren = 0; static char *ctx = NULL; char *end = strrchr(text, SEP); if (end != NULL) end += 1; if (state == 0) { char *path; if (end == NULL) { if ((path = strdup("*")) == NULL) return NULL; } else { CALLOC(path, end - text + 2); if (path == NULL) return NULL; strncpy(path, text, end - text); strcat(path, "*"); } for (;current < nchildren; current++) free((void *) children[current]); free((void *) children); nchildren = aug_match(aug, path, &children); current = 0; ctx = NULL; if (path[0] != SEP) aug_get(aug, AUGEAS_CONTEXT, (const char **) &ctx); free(path); } if (end == NULL) end = (char *) text; while (current < nchildren) { char *child = children[current]; current += 1; char *chend = strrchr(child, SEP) + 1; if (STREQLEN(chend, end, strlen(end))) { if (child_count(child) > 0) { char *c = realloc(child, strlen(child)+2); if (c == NULL) return NULL; child = c; strcat(child, "/"); } /* strip off context if the user didn't give it */ if (ctx != NULL) { char *c = realloc(child, strlen(child)-strlen(ctx)+1); if (c == NULL) return NULL; int ctxidx = strlen(ctx); if (child[ctxidx] == SEP) ctxidx++; strcpy(c, &child[ctxidx]); child = c; } rl_filename_completion_desired = 1; rl_completion_append_character = '\0'; return child; } else { free(child); } } return NULL; }
bool sync_object::has_children() const { if (child_count() > 0) { return true; } return false; }
static void wait_data_check(struct bproc_test_info_t *info, int wpid) { int i, err, a; int ccount, nlcount, lwait; int knlcount, kccount, klwait; int retry=0; a = proc_arr(info->arr,0); /* If parent is not on front end, do a bunch of process tree checking */ if (a != proc_fe) { try_again: ccount = 0; nlcount = 0; lwait = 1; /* Check up on BProc's book keeping of our children... */ for (i=1; i < info->nprocs; i++) { if (info->pid[i]) { a = proc_arr(info->arr,i); if (proc_isdetach(a) && !(info->scratch & (1<<i))) continue; ccount++; if (!proc_samenode(a,proc_arr(info->arr,0))) { nlcount++; if (info->pid[i] == wpid || wpid == -1) lwait = 0; } } } /* Ask the kernel for the same info */ knlcount = nlchild_count(); kccount = child_count(); klwait = local_wait(wpid); err = kccount != ccount || knlcount != nlcount || klwait != lwait; if (err) { /* It is possible that we'll end up looking at these * values a bit too soon - before something has finished * moving or before a masq process has finished cleaning * itself up. In that case, our child_count should still * be correct but the others may be off. If that's the * case, retry a few times. Really, the debug stuff * should be fixed to atomically return all of that. */ if (kccount == ccount && retry < MAX_RETRY/RETRY_DELAY ) { usleep(RETRY_DELAY); retry ++; goto try_again; } printf("\nProcess State:\n"); printf(" kern mine\n"); printf(" child_count = %-4d %d%s\n", kccount, ccount, kccount != ccount ? " ** MISMATCH **":""); printf(" nlchild_count = %-4d %d%s\n", knlcount, nlcount, knlcount != nlcount ? " ** MISMATCH **":""); printf(" local_wait = %-4d %d%s\n", klwait, lwait, klwait != lwait ? " ** MISMATCH **":""); printf(" wpid=%d mynode=%s", wpid, proc_str(proc_arr(info->arr,0))); for (i=1; i < info->nprocs; i++) printf(" ch[%d]=%d(%s)", i, info->pid[i], proc_str(proc_arr(info->arr,i))); printf("\n"); if (err) sleep(10000); } } check_tree(); }