/* vim: set sw=4 sts=4 et foldmethod=syntax : */ /* * Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011 Ciaran McCreesh * Copyright (c) 2006, 2007, 2008 Richard Brown * * This file is part of the Paludis package manager. Paludis is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef PALUDIS_GUARD_RUBY_RUBY_PALUDIS_RUBY_HH #define PALUDIS_GUARD_RUBY_RUBY_PALUDIS_RUBY_HH 1 #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define RUBY_FUNC_CAST(x) reinterpret_cast(x) #define RDOC_IS_STUPID(x, y) RUBY_FUNC_CAST((y)) #define FAKE_RDOC_METHOD(x) // namespace paludis { namespace ruby { /* general utilities */ void exception_to_ruby_exception(const std::exception &) PALUDIS_ATTRIBUTE((noreturn)); std::string value_case_to_RubyCase(const std::string & s); VALUE paludis_module(); /* constructors */ VALUE repository_to_value(std::shared_ptr); VALUE version_spec_to_value(const VersionSpec &); VALUE package_id_to_value(std::shared_ptr); VALUE qualified_package_name_to_value(const QualifiedPackageName &); VALUE contents_to_value(std::shared_ptr); VALUE metadata_key_to_value(std::shared_ptr m); VALUE fetch_action_failure_to_value(const FetchActionFailure &); VALUE generator_to_value(const Generator &); VALUE filter_to_value(const Filter &); VALUE filtered_generator_to_value(const FilteredGenerator &); template VALUE dep_tree_to_value(const std::shared_ptr &); template std::shared_ptr value_to_dep_tree(VALUE); VALUE package_dep_spec_to_value(const PackageDepSpec &); VALUE uri_label_to_value(const std::shared_ptr &); VALUE dependencies_label_to_value(const std::shared_ptr &); VALUE mask_to_value(std::shared_ptr); VALUE overridden_mask_to_value(std::shared_ptr); VALUE choices_to_value(const std::shared_ptr & c); VALUE choice_to_value(const std::shared_ptr & c); VALUE choice_value_to_value(const std::shared_ptr & c); VALUE match_package_options_to_value(const MatchPackageOptions & c); VALUE bool_to_value(bool b); VersionSpec value_to_version_spec(VALUE v); std::shared_ptr value_to_package_id(VALUE, bool nil_ok = false); std::shared_ptr value_to_package_dep_spec(VALUE v); std::shared_ptr value_to_dependencies_labels_dep_spec(VALUE v); std::shared_ptr value_to_dep_spec(VALUE v); QualifiedPackageName value_to_qualified_package_name(VALUE v); std::shared_ptr value_to_environment(VALUE v); std::shared_ptr value_to_repository(VALUE); std::shared_ptr value_to_supports_action_test_base(VALUE v); std::shared_ptr value_to_action(VALUE v); std::shared_ptr value_to_choices(VALUE v); std::shared_ptr value_to_choice(VALUE v); std::shared_ptr value_to_choice_value(VALUE v); std::shared_ptr value_to_dependencies_label(VALUE v); MatchPackageOptions value_to_match_package_options(VALUE v); bool value_to_bool(VALUE v); Filter value_to_filter(VALUE v); Selection value_to_selection(VALUE v); FilteredGenerator value_to_filtered_generator(VALUE v); Generator value_to_generator(VALUE v); VALUE * install_action_value_ptr(); VALUE * fetch_action_value_ptr(); VALUE * info_action_value_ptr(); VALUE * config_action_value_ptr(); VALUE * uninstall_action_value_ptr(); VALUE * pretend_action_value_ptr(); VALUE * pretend_fetch_action_value_ptr(); VALUE * dependencies_labels_dep_spec_value_ptr(); /* registration */ class RegisterRubyClass : public Singleton { friend class Singleton; private: Pimp _imp; RegisterRubyClass(); ~RegisterRubyClass(); public: class Register; friend class Register; void execute() const; }; class RegisterRubyClass::Register { public: Register(void (* func)()); }; template struct Common { static void free(void * p) { delete static_cast(p); } static VALUE compare(VALUE left, VALUE right) { T_ * left_ptr, * right_ptr; Data_Get_Struct(left, T_, left_ptr); Data_Get_Struct(right, T_, right_ptr); if (*left_ptr < *right_ptr) return INT2FIX(-1); if (*left_ptr > *right_ptr) return INT2FIX(1); return INT2FIX(0); } static VALUE equal(VALUE left, VALUE right) { T_ * left_ptr, * right_ptr; Data_Get_Struct(left, T_, left_ptr); Data_Get_Struct(right, T_, right_ptr); return (*left_ptr == *right_ptr) ? Qtrue : Qfalse; } static VALUE equal_via_ptr(VALUE left, VALUE right) { T_ * left_ptr, * right_ptr; Data_Get_Struct(left, T_, left_ptr); Data_Get_Struct(right, T_, right_ptr); return (**left_ptr == **right_ptr) ? Qtrue : Qfalse; } static VALUE to_s(VALUE self) { T_ * self_ptr; Data_Get_Struct(self, T_, self_ptr); return rb_str_new2(stringify(*self_ptr).c_str()); } static VALUE hash(VALUE self) { T_ * self_ptr; Data_Get_Struct(self, T_, self_ptr); return INT2FIX(Hash()(*self_ptr)); } static VALUE hash_via_ptr(VALUE self) { T_ * self_ptr; Data_Get_Struct(self, T_, self_ptr); return INT2FIX(Hash::type>()(**self_ptr)); } static VALUE to_s_via_ptr(VALUE self) { T_ * self_ptr; Data_Get_Struct(self, T_, self_ptr); return rb_str_new2(stringify(**self_ptr).c_str()); } }; void init(); } } #endif