Example #1
0
		void TestSceneGraph()
		{
			auto t1 = SceneGraph<int>();
			t1.insert(nullptr, 0);
			t1.insert(nullptr, (const int)1);
			auto n3 = t1.emplace(nullptr, 1729);
			auto n1 = t1.find(0);
			t1.find(1);
			t1.emplace(n3, 1);
			t1.emplace(n3, 2);
			t1.emplace(n1, 1);
			t1.emplace(n1, 2);
			auto n4 = t1.emplace(n1, 3);
			t1.insert(n4, 0);
			t1.insert(n4, 1);
			t1.insert(n4, 3);
			t1.insert(n4, 4);
			t1.find(1);
			t1.find(42);
			t1.find_child(n3, 2);
			t1.find_child(n1, 0);
			std::vector<SceneNode<int>*> nodes;
			t1.find_all_cached(0, std::equal_to<>(), nodes);
			nodes.clear();
			t1.find_all_children(n1, 0, std::equal_to<>());
			nodes.clear();
			n3 = t1.parent_to(n4, n3);
			t1.remove(t1.find(1729), false);
			t1.remove(n1);
		}
Example #2
0
int
ct_path_set_find_all(struct ct_path_set *path_set)
{
    if (!path_set) {
        errno = EINVAL;
        return -1;
    }
    return find_all_children(path_set, path_set->root_dir);
}
Example #3
0
static int
find_all_children(struct ct_path_set *path_set, struct ct_path const *path)
{
    DIR *dir = opendir(path->abs_path);
    if (!dir) return -1;

    struct dirent *entry;
    errno = 0;
    while ((entry = readdir(dir))) {
        if (0 == strcmp(".", entry->d_name)) continue;
        if (0 == strcmp("..", entry->d_name)) continue;

        struct ct_path *child = ct_path_alloc(path->abs_path, entry->d_name);
        if (!child) {
            closedir(dir);
            return -1;
        }

        enum ct_path_set_error error;
        int result = ct_path_set_add_path(path_set, child, &error);
        if (-1 == result) {
            ct_path_free(child);
            closedir(dir);
            return -1;
        }

        if (DT_DIR == entry->d_type) {
            int result = find_all_children(path_set, child);
            if (-1 == result) {
                ct_path_free(child);
                closedir(dir);
                return -1;
            }
        } else if (DT_LNK == entry->d_type) {
            // TODO: handle symlinks
            ct_path_free(child);
            closedir(dir);
            return -1;
        }

        ct_path_free(child);
    }
    closedir(dir);
    return 0;
}