aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-01-18 10:51:03 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-01-18 10:51:03 +0000
commitb73479ebccd7e4bc0d2a0f4b60ba08d0b97fc637 (patch)
treeed9746faeea0609e69c9f6ca284366b97b30de3a
parentb02bc1d7187a7cfe186595604ea0acc12cb7e8ee (diff)
downloadpaludis-b73479ebccd7e4bc0d2a0f4b60ba08d0b97fc637.tar.gz
paludis-b73479ebccd7e4bc0d2a0f4b60ba08d0b97fc637.tar.xz
Improve ruby repository classes.
-rw-r--r--ruby/environment.cc2
-rw-r--r--ruby/paludis_ruby.hh1
-rw-r--r--ruby/repository.cc27
3 files changed, 11 insertions, 19 deletions
diff --git a/ruby/environment.cc b/ruby/environment.cc
index e9463bd..2d571ab 100644
--- a/ruby/environment.cc
+++ b/ruby/environment.cc
@@ -367,7 +367,7 @@ namespace
{
try
{
- return portage_repository_to_value(value_to_no_config_environment(self)->portage_repository());
+ return repository_to_value(value_to_no_config_environment(self)->portage_repository());
}
catch (const std::exception & e)
{
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index 4a44e56..b8a7d90 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -82,7 +82,6 @@ namespace paludis
VALUE package_database_to_value(PackageDatabase::Pointer);
VALUE package_database_entry_to_value(const PackageDatabaseEntry &);
VALUE repository_to_value(Repository::ConstPointer);
- VALUE portage_repository_to_value(PortageRepository::ConstPointer);
VALUE version_spec_to_value(const VersionSpec &);
VALUE version_metadata_to_value(VersionMetadata::ConstPointer);
VALUE dep_atom_to_value(DepAtom::ConstPointer);
diff --git a/ruby/repository.cc b/ruby/repository.cc
index 925f06c..a1c8e75 100644
--- a/ruby/repository.cc
+++ b/ruby/repository.cc
@@ -930,14 +930,14 @@ namespace
}
}
-VALUE
-paludis::ruby::repository_to_value(Repository::ConstPointer m)
+template <typename T_>
+VALUE repo_to_value(T_ m, VALUE * klass)
{
- Repository::ConstPointer * m_ptr(0);
+ T_ * m_ptr(0);
try
{
- m_ptr = new Repository::ConstPointer(m);
- return Data_Wrap_Struct(c_repository, 0, &Common<Repository::ConstPointer>::free, m_ptr);
+ m_ptr = new T_(m);
+ return Data_Wrap_Struct(*klass, 0, &Common<T_>::free, m_ptr);
}
catch (const std::exception & e)
{
@@ -947,19 +947,12 @@ paludis::ruby::repository_to_value(Repository::ConstPointer m)
}
VALUE
-paludis::ruby::portage_repository_to_value(PortageRepository::ConstPointer m)
+paludis::ruby::repository_to_value(Repository::ConstPointer m)
{
- PortageRepository::ConstPointer * m_ptr(0);
- try
- {
- m_ptr = new PortageRepository::ConstPointer(m);
- return Data_Wrap_Struct(c_portage_repository, 0, &Common<PortageRepository::ConstPointer>::free, m_ptr);
- }
- catch (const std::exception & e)
- {
- delete m_ptr;
- exception_to_ruby_exception(e);
- }
+ if (0 != dynamic_cast<const PortageRepository *>(m.raw_pointer()))
+ return repo_to_value<PortageRepository::ConstPointer>(m, &c_portage_repository);
+ else
+ return repo_to_value<Repository::ConstPointer>(m, &c_repository);
}
VALUE