class Paludis::QualifiedPackageName

Represents a category plus package name. Includes Comparable

Public Class Methods

new(category_and_package_string) → QualifiedPackageName click to toggle source
new(category_name, package_name) → QualifiedPackageName

Creates a new QualifiedPackageName.

VALUE
    qualified_package_name_new(int argc, VALUE *argv, VALUE self)
    {
        QualifiedPackageName * ptr(0);
        try
        {
            if (1 == argc)
            {
                ptr = new QualifiedPackageName(StringValuePtr(argv[0]));
            }
            else if (2 == argc)
            {
                ptr = new QualifiedPackageName(CategoryNamePart(StringValuePtr(argv[0])), PackageNamePart(StringValuePtr(argv[1])));
            }
            else
            {
                rb_raise(rb_eArgError, "QualifiedPackageName expects one or two arguments, but got %d",argc);
            }
            VALUE tdata(Data_Wrap_Struct(self, 0, &Common<QualifiedPackageName>::free, ptr));
            rb_obj_call_init(tdata,argc, argv);
            return tdata;
        }
        catch (const std::exception & e)
        {
            delete ptr;
            exception_to_ruby_exception(e);
        }
    }

    /*
     * Document-method: category
     *
     * call-seq:
     *     category -> String
     *
     * Fetch the category part of the QualifiedPackageName.
     */
    /*
     * Document-method: package
     *
     * call-seq:
     *     package -> String
     *
     * Fetch the package name part of the QualifiedPackageName.
     */
    template <typename T_, typename M_, const M_ (QualifiedPackageName::* m_)() const>
    struct QPNMember
    {
        static VALUE
        fetch(VALUE self)
        {
            QualifiedPackageName * p;
            Data_Get_Struct(self, QualifiedPackageName, p);
            return rb_str_new2(stringify((p->*m_)()).c_str());
        }

        static VALUE
        set(VALUE self, VALUE str)
        {
            try
            {
                QualifiedPackageName * p;
                Data_Get_Struct(self, QualifiedPackageName, p);
                (p->*m_)() =  T_ ((StringValuePtr(str)));
                return self;
            }
            catch (const std::exception & e)
            {
                exception_to_ruby_exception(e);
            }
        }
    };

    VALUE
    qualified_package_name_compare(VALUE left, VALUE right)
    {
        try
        {
            QualifiedPackageName l = value_to_qualified_package_name(left);
            QualifiedPackageName r = value_to_qualified_package_name(right);
            if (l < r)
                return INT2FIX(-1);
            if (l > r)
                return INT2FIX(1);
            return INT2FIX(0);
        }
        catch (const std::exception & e)
        {
            exception_to_ruby_exception(e);
        }
    }

    void do_register_qualified_package_name()
    {
        /*
         * Document-class: Paludis::QualifiedPackageName
         *
         * Represents a category plus package name. Includes
         * Comparable[http://www.ruby-doc.org/core/classes/Comparable.html]
         */
        c_qualified_package_name = rb_define_class_under(c_paludis_module, "QualifiedPackageName", rb_cObject);
        rb_define_singleton_method(c_qualified_package_name, "new", qualified_package_name_new, -1);
        rb_define_method(c_qualified_package_name, "initialize", qualified_package_name_init, -1);
        rb_define_method(c_qualified_package_name, "<=>", qualified_package_name_compare, 1);
        rb_include_module(c_qualified_package_name, rb_mComparable);
        rb_define_method(c_qualified_package_name, "to_s", template_methods, 0);
        rb_define_alias(c_qualified_package_name, "to_str", "to_s");
        rb_define_method(c_qualified_package_name, "hash", template_methods, 0);
        rb_define_method(c_qualified_package_name, "eql?", template_methods, 1);
        rb_define_method(c_qualified_package_name, "category",                template_methods, 0);
        rb_define_method(c_qualified_package_name, "package",                template_methods, 0);
    }
}

Public Instance Methods

<=>(p1) click to toggle source
VALUE
    qualified_package_name_compare(VALUE left, VALUE right)
    {
        try
        {
            QualifiedPackageName l = value_to_qualified_package_name(left);
            QualifiedPackageName r = value_to_qualified_package_name(right);
            if (l < r)
                return INT2FIX(-1);
            if (l > r)
                return INT2FIX(1);
            return INT2FIX(0);
        }
        catch (const std::exception & e)
        {
            exception_to_ruby_exception(e);
        }
    }

    void do_register_qualified_package_name()
    {
        /*
         * Document-class: Paludis::QualifiedPackageName
         *
         * Represents a category plus package name. Includes
         * Comparable[http://www.ruby-doc.org/core/classes/Comparable.html]
         */
        c_qualified_package_name = rb_define_class_under(c_paludis_module, "QualifiedPackageName", rb_cObject);
        rb_define_singleton_method(c_qualified_package_name, "new", qualified_package_name_new, -1);
        rb_define_method(c_qualified_package_name, "initialize", qualified_package_name_init, -1);
        rb_define_method(c_qualified_package_name, "<=>", qualified_package_name_compare, 1);
        rb_include_module(c_qualified_package_name, rb_mComparable);
        rb_define_method(c_qualified_package_name, "to_s", template_methods, 0);
        rb_define_alias(c_qualified_package_name, "to_str", "to_s");
        rb_define_method(c_qualified_package_name, "hash", template_methods, 0);
        rb_define_method(c_qualified_package_name, "eql?", template_methods, 1);
        rb_define_method(c_qualified_package_name, "category",                template_methods, 0);
        rb_define_method(c_qualified_package_name, "package",                template_methods, 0);
    }
}
category → String

Fetch the category part of the QualifiedPackageName.

package → String

Fetch the package name part of the QualifiedPackageName.