class Paludis::Generator::Intersection

Generate packages from the intersection of two other Generator instances.

Public Class Methods

new(p1, p2) click to toggle source
VALUE
    generator_intersection_new(VALUE self, VALUE f1_v, VALUE f2_v)
    {
        Generator * ptr(0);
        try
        {
            Generator f1(value_to_generator(f1_v));
            Generator f2(value_to_generator(f2_v));
            ptr = new generator::Intersection(f1, f2);
            VALUE data(Data_Wrap_Struct(self, 0, &Common<Generator>::free, ptr));
            rb_obj_call_init(data, 2, &f1_v);
            return data;
        }
        catch (const std::exception & e)
        {
            delete ptr;
            exception_to_ruby_exception(e);
        }
    }

    /*
     * call-seq:
     *     new(class) -> Filter
     *
     * Create a Generator that accepts packages that might support the
     * specified Action subclass.
     */
    VALUE
    generator_some_ids_might_support_action_new(VALUE self, VALUE action_class)
    {
        Generator * ptr(0);
        try
        {
            if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, install_action_value_ptr()))
                ptr = new generator::SomeIDsMightSupportAction<InstallAction>();
            else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, pretend_action_value_ptr()))
                ptr = new generator::SomeIDsMightSupportAction<PretendAction>();
            else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, config_action_value_ptr()))
                ptr = new generator::SomeIDsMightSupportAction<ConfigAction>();
            else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, fetch_action_value_ptr()))
                ptr = new generator::SomeIDsMightSupportAction<FetchAction>();
            else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, info_action_value_ptr()))
                ptr = new generator::SomeIDsMightSupportAction<InfoAction>();
            else if (Qtrue == rb_funcall2(action_class, rb_intern("<="), 1, pretend_fetch_action_value_ptr()))
                ptr = new generator::SomeIDsMightSupportAction<PretendFetchAction>();
            else
                rb_raise(rb_eTypeError, "Can't convert %s into an Action subclass", rb_obj_classname(action_class));

            VALUE data(Data_Wrap_Struct(self, 0, &Common<Generator>::free, ptr));
            rb_obj_call_init(data, 1, &action_class);
            return data;
        }
        catch (const std::exception & e)
        {
            delete ptr;
            exception_to_ruby_exception(e);
        }
    }

    void do_register_generator()
    {
        /*
         * Document-module: Paludis::Generator
         *
         * Collection of classes that produce results for an
         * Environment selection.
         */
        c_generator_module = rb_define_module_under(c_paludis_module, "Generator");

        /*
         * Document-class: Paludis::Generator::Generator
         *
         * Generator for an Environment selection.
         */
        c_generator = rb_define_class_under(c_generator_module, "Generator", rb_cObject);
        rb_funcall(c_generator, rb_intern("private_class_method"), 1, rb_str_new2("new"));
        rb_define_method(c_generator, "initialize", generator_init, -1);
        rb_define_method(c_generator, "to_s", template_methods, 0);
        rb_define_method(c_generator, "", generator_ampersand, 1);
        rb_define_method(c_generator, "|", generator_bar, 1);

        /*
         * Document-class: Paludis::Generator::All
         *
         * Generate all packages.
         */
        c_generator_all = rb_define_class_under(c_generator_module, "All", c_generator);
        rb_define_singleton_method(c_generator_all, "new", generator_all_new, 0);

        /*
         * Document-class: Paludis::Generator::Matches
         *
         * Generate matching packages.
         */
        c_generator_matches = rb_define_class_under(c_generator_module, "Matches", c_generator);
        rb_define_singleton_method(c_generator_matches, "new", generator_matches_new, 3);

        /*
         * Document-class: Paludis::Generator::Intersection
         *
         * Generate packages from the intersection of two other Generator instances.
         */
        c_generator_intersection = rb_define_class_under(c_generator_module, "Intersection", c_generator);
        rb_define_singleton_method(c_generator_intersection, "new", generator_intersection_new, 2);

        /*
         * Document-class: Paludis::Generator::Package
         *
         * Generate all named packages.
         */
        c_generator_package = rb_define_class_under(c_generator_module, "Package", c_generator);
        rb_define_singleton_method(c_generator_package, "new", generator_package_new, 1);

        /*
         * Document-class: Paludis::Generator::Category
         *
         * Generate all packages in a given category.
         */
        c_generator_category = rb_define_class_under(c_generator_module, "Category", c_generator);
        rb_define_singleton_method(c_generator_category, "new", generator_category_new, 1);

        /*
         * Document-class: Paludis::Generator::InRepository
         *
         * Generate all packages in a given repository.
         */
        c_generator_in_repository = rb_define_class_under(c_generator_module, "InRepository", c_generator);
        rb_define_singleton_method(c_generator_in_repository, "new", generator_in_repository_new, 1);

        /*
         * Document-class: Paludis::Generator::FromRepository
         *
         * Generate all packages originally from a given repository.
         */
        c_generator_from_repository = rb_define_class_under(c_generator_module, "FromRepository", c_generator);
        rb_define_singleton_method(c_generator_from_repository, "new", generator_from_repository_new, 1);

        /*
         * Document-class: Paludis::Generator::SomeIDsMightSupportAction
         *
         * Generate all packages that might support a particular action.
         */
        c_generator_some_ids_might_support_action = rb_define_class_under(c_generator_module, "SomeIDsMightSupportAction", c_generator);
        rb_define_singleton_method(c_generator_some_ids_might_support_action, "new", generator_some_ids_might_support_action_new, 1);
    }
}