TEST(FirstPass, has_label) { char a[] = "Y: .data 202"; char b[] = "HABRAHABR .data 205"; char c[] = "HABRAHABR.:data 205"; EXPECT_TRUE(has_label(a)); EXPECT_FALSE(has_label(b)); EXPECT_FALSE(has_label(c)); }
bool LabelManager::add_label(const std::string& name) { // Make sure that a label with the specified name does not already exist. if(has_label(name)) return false; // Make sure that we're not trying to exceed the maximum number of labels. if(get_label_count() == get_max_label_count()) return false; // Add the new label. SpaintVoxel::Label label = static_cast<SpaintVoxel::Label>(m_labelAllocator.allocate()); m_labelProperties.insert(std::make_pair(label, std::make_pair(name, colours[label]))); m_labelsByName.insert(std::make_pair(name, label)); return true; }
void grid_segment::grow(std::function<grid_segment::ptr(grid_cell_base::label)> segments_accessor) { vector<grid_cell::ptr> tovisit; tovisit.push_back(*cells_.begin()); set_visited(tovisit.front()); grid_cell_base::label label = tovisit.front()->get_label(); while(!tovisit.empty()) { grid_cell::ptr c = tovisit.back(); tovisit.pop_back(); c->set_label(label); cells_.insert(c); for(size_t i=0; i<4; i++) { auto nc = grid_.get_neighbour_cell_4(c,i); if(nc) { if(nc->has_label()) { if(nc->get_label() != label && !nc->is_ignored()) { add_edge(std::static_pointer_cast<graph_node>(segments_accessor(label)), std::static_pointer_cast<graph_node>(segments_accessor(nc->get_label()))); } continue; } if(nc->is_target() && !nc->is_ignored() && nc->is_covered() && !is_visited(nc)) { set_visited(nc); tovisit.push_back(nc); } } } } }
/* Find the entry (SPEC,FILE) in fstab */ struct mntentchn * getfsspecfile (const char *spec, const char *file) { struct mntentchn *mc, *mc0; mc0 = fstab_head(); /* first attempt: names occur precisely as given */ for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt) if (streq(mc->m.mnt_dir, file) && streq(mc->m.mnt_fsname, spec)) return mc; /* second attempt: names found after symlink resolution */ for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt) if ((streq(mc->m.mnt_dir, file) || streq(canonicalize(mc->m.mnt_dir), file)) && (streq(mc->m.mnt_fsname, spec) || streq(canonicalize(mc->m.mnt_fsname), spec))) return mc; /* third attempt: names found after LABEL= or UUID= resolution */ for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt) { if (!strncmp (mc->m.mnt_fsname, "LABEL=", 6) && (streq(mc->m.mnt_dir, file) || streq(canonicalize(mc->m.mnt_dir), file))) { if (has_label(spec, mc->m.mnt_fsname+6)) return mc; } if (!strncmp (mc->m.mnt_fsname, "UUID=", 5) && (streq(mc->m.mnt_dir, file) || streq(canonicalize(mc->m.mnt_dir), file))) { if (has_uuid(spec, mc->m.mnt_fsname+5)) return mc; } } return NULL; }