aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-24 07:40:20 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-24 07:40:20 +0000
commit1fe17ec766f9c911f4eeaa6c8bba77e9714a55df (patch)
tree3e75e0fdc92cb0974d2f9ac5e5c4a78fb72bfdbc
parent01f3f805648f436ae8ee3526375252bc496129e7 (diff)
downloadpaludis-1fe17ec766f9c911f4eeaa6c8bba77e9714a55df.tar.gz
paludis-1fe17ec766f9c911f4eeaa6c8bba77e9714a55df.tar.xz
Replace make_qualified_package_name with a constructor.
-rw-r--r--paludis/dep_atom_dumper_TEST.cc6
-rw-r--r--paludis/environment.cc4
-rw-r--r--paludis/package_database_TEST.cc8
-rw-r--r--paludis/package_dep_atom.cc4
-rw-r--r--paludis/portage_repository.cc4
-rw-r--r--paludis/qualified_package_name.cc34
-rw-r--r--paludis/qualified_package_name.hh35
-rw-r--r--paludis/qualified_package_name_TEST.cc16
-rw-r--r--paludis/version_metadata.cc7
9 files changed, 64 insertions, 54 deletions
diff --git a/paludis/dep_atom_dumper_TEST.cc b/paludis/dep_atom_dumper_TEST.cc
index 71819c1..5e9adc4 100644
--- a/paludis/dep_atom_dumper_TEST.cc
+++ b/paludis/dep_atom_dumper_TEST.cc
@@ -52,10 +52,10 @@ namespace test_cases
std::stringstream s;
DepAtomDumper d(&s);
AllDepAtom::Pointer all(new AllDepAtom);
- PackageDepAtom::Pointer p1(new PackageDepAtom(make_qualified_package_name("one/one")));
+ PackageDepAtom::Pointer p1(new PackageDepAtom("one/one"));
AnyDepAtom::Pointer any(new AnyDepAtom);
- PackageDepAtom::Pointer p2(new PackageDepAtom(make_qualified_package_name("two/two")));
- PackageDepAtom::Pointer p3(new PackageDepAtom(make_qualified_package_name("three/three")));
+ PackageDepAtom::Pointer p2(new PackageDepAtom("two/two"));
+ PackageDepAtom::Pointer p3(new PackageDepAtom("three/three"));
all->add_child(p1);
all->add_child(any);
any->add_child(p2);
diff --git a/paludis/environment.cc b/paludis/environment.cc
index 4337cb5..79c51e0 100644
--- a/paludis/environment.cc
+++ b/paludis/environment.cc
@@ -54,7 +54,7 @@ Environment::mask_reasons(const PackageDatabaseEntry & e) const
if (! metadata->get(vmk_virtual).empty())
{
- QualifiedPackageName n(make_qualified_package_name(metadata->get(vmk_virtual)));
+ QualifiedPackageName n(metadata->get(vmk_virtual));
PackageDatabaseEntry ee(n, e.get<pde_version>(), e.get<pde_repository>());
for (VersionMetadata::KeywordIterator k(metadata->begin_keywords()),
@@ -81,7 +81,7 @@ Environment::mask_reasons(const PackageDatabaseEntry & e) const
if (! metadata->get(vmk_virtual).empty())
{
- QualifiedPackageName n(make_qualified_package_name(metadata->get(vmk_virtual)));
+ QualifiedPackageName n(metadata->get(vmk_virtual));
if (package_database()->fetch_repository(e.get<pde_repository>())->query_profile_masks(n,
e.get<pde_version>()))
diff --git a/paludis/package_database_TEST.cc b/paludis/package_database_TEST.cc
index 8250029..a0d2a93 100644
--- a/paludis/package_database_TEST.cc
+++ b/paludis/package_database_TEST.cc
@@ -180,10 +180,10 @@ namespace test_cases
p.add_repository(r2);
TEST_CHECK(true);
- TEST_CHECK_EQUAL(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-one")),
- make_qualified_package_name("cat-one/pkg-one"));
- TEST_CHECK_EQUAL(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-four")),
- make_qualified_package_name("cat-three/pkg-four"));
+ TEST_CHECK_STRINGIFY_EQUAL(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-one")),
+ "cat-one/pkg-one");
+ TEST_CHECK_STRINGIFY_EQUAL(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-four")),
+ "cat-three/pkg-four");
TEST_CHECK_THROWS(p.fetch_unique_qualified_package_name(PackageNamePart("pkg-two")),
AmbiguousPackageNameError);
diff --git a/paludis/package_dep_atom.cc b/paludis/package_dep_atom.cc
index 7516c5b..86ba431 100644
--- a/paludis/package_dep_atom.cc
+++ b/paludis/package_dep_atom.cc
@@ -78,7 +78,7 @@ PackageDepAtom::PackageDepAtom(const std::string & s) :
if (s.at(q) >= '0' && s.at(q) <= '9')
break;
}
- _package = QualifiedPackageName(make_qualified_package_name(s.substr(p, q - p - 1)));
+ _package = QualifiedPackageName(s.substr(p, q - p - 1));
if ('*' == s.at(s.length() - 1))
{
@@ -93,7 +93,7 @@ PackageDepAtom::PackageDepAtom(const std::string & s) :
new VersionSpec(s.substr(q)));
}
else
- _package = make_qualified_package_name(s);
+ _package = QualifiedPackageName(s);
}
catch (Exception &)
{
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index 3a4a46d..36eed47 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -188,8 +188,8 @@ Implementation<PortageRepository>::add_profile(const FSEntry & f) const
tokeniser.tokenise(*line, std::back_inserter(tokens));
if (tokens.size() < 2)
continue;
- virtuals_map.erase(make_qualified_package_name(tokens[0]));
- virtuals_map.insert(std::make_pair(make_qualified_package_name(tokens[0]),
+ virtuals_map.erase(QualifiedPackageName(tokens[0]));
+ virtuals_map.insert(std::make_pair(QualifiedPackageName(tokens[0]),
PackageDepAtom::Pointer(new PackageDepAtom(tokens[1]))));
}
}
diff --git a/paludis/qualified_package_name.cc b/paludis/qualified_package_name.cc
index e9ce157..e58b270 100644
--- a/paludis/qualified_package_name.cc
+++ b/paludis/qualified_package_name.cc
@@ -27,37 +27,25 @@ QualifiedPackageNameError::QualifiedPackageNameError(const std::string & s) thro
{
}
-std::string get_category_name(const std::string & s)
+std::ostream &
+paludis::operator<< (std::ostream & s, const QualifiedPackageName & q)
{
- Context c("When splitting out category name from '" + s + "':");
-
- std::string::size_type p(s.find('/'));
- if (std::string::npos == p)
- throw QualifiedPackageNameError(s);
- return s.substr(0, p);
+ s << q.get<qpn_category>() << "/" << q.get<qpn_package>();
+ return s;
}
-std::string get_package_name(const std::string & s)
+MakeSmartRecord<QualifiedPackageNameTag>::Type
+QualifiedPackageName::_make_parent(
+ const std::string & s)
{
- Context c("When splitting out package name from '" + s + "':");
+ Context c("When splitting out category and package names from '" + s + "':");
std::string::size_type p(s.find('/'));
if (std::string::npos == p)
throw QualifiedPackageNameError(s);
- return s.substr(p + 1);
-}
-std::ostream &
-paludis::operator<< (std::ostream & s, const QualifiedPackageName & q)
-{
- s << q.get<qpn_category>() << "/" << q.get<qpn_package>();
- return s;
-}
-
-QualifiedPackageName
-paludis::make_qualified_package_name(const std::string & s)
-{
- return QualifiedPackageName(CategoryNamePart(get_category_name(s)),
- PackageNamePart(get_package_name(s)));
+ return MakeSmartRecord<QualifiedPackageNameTag>::Type(
+ CategoryNamePart(s.substr(0, p)),
+ PackageNamePart(s.substr(p + 1)));
}
diff --git a/paludis/qualified_package_name.hh b/paludis/qualified_package_name.hh
index 846cd2b..9528f77 100644
--- a/paludis/qualified_package_name.hh
+++ b/paludis/qualified_package_name.hh
@@ -54,7 +54,35 @@ namespace paludis
* A QualifiedPackageName instance holds a CategoryNamePart and
* a PackageNamePart.
*/
- typedef MakeSmartRecord<QualifiedPackageNameTag>::Type QualifiedPackageName;
+ class QualifiedPackageName :
+ public MakeSmartRecord<QualifiedPackageNameTag>::Type
+ {
+ private:
+ static MakeSmartRecord<QualifiedPackageNameTag>::Type _make_parent(
+ const std::string & s);
+
+ public:
+ QualifiedPackageName(const CategoryNamePart & c, const PackageNamePart & p) :
+ MakeSmartRecord<QualifiedPackageNameTag>::Type(c, p)
+ {
+ }
+
+ QualifiedPackageName(const QualifiedPackageName & other) :
+ MakeSmartRecord<QualifiedPackageNameTag>::Type(other)
+ {
+ }
+
+ explicit QualifiedPackageName(const std::string & s) :
+ MakeSmartRecord<QualifiedPackageNameTag>::Type(_make_parent(s))
+ {
+ }
+
+ const QualifiedPackageName & operator= (const QualifiedPackageName & other)
+ {
+ MakeSmartRecord<QualifiedPackageNameTag>::Type::operator= (other);
+ return *this;
+ }
+ };
/**
* Output a QualifiedPackageName to a stream.
@@ -62,11 +90,6 @@ namespace paludis
std::ostream & operator<< (std::ostream &, const QualifiedPackageName &);
/**
- * Create a QualifiedPackageName from a string.
- */
- QualifiedPackageName make_qualified_package_name(const std::string &);
-
- /**
* Holds a collection of QualifiedPackageName instances.
*/
typedef SortedCollection<QualifiedPackageName> QualifiedPackageNameCollection;
diff --git a/paludis/qualified_package_name_TEST.cc b/paludis/qualified_package_name_TEST.cc
index 83a14db..50e5011 100644
--- a/paludis/qualified_package_name_TEST.cc
+++ b/paludis/qualified_package_name_TEST.cc
@@ -44,7 +44,7 @@ namespace test_cases
void run()
{
- QualifiedPackageName a(make_qualified_package_name("foo/bar1"));
+ QualifiedPackageName a("foo/bar1");
TEST_CHECK(true);
}
} test_qualified_package_name;
@@ -60,10 +60,10 @@ namespace test_cases
void run()
{
- QualifiedPackageName a(make_qualified_package_name("foo/bar"));
- TEST_CHECK_THROWS(a = QualifiedPackageName(make_qualified_package_name("moo")), NameError);
- TEST_CHECK_THROWS(a = QualifiedPackageName(make_qualified_package_name("foo/bar!")), NameError);
- TEST_CHECK_THROWS(a = QualifiedPackageName(make_qualified_package_name("foo/bar/baz")), NameError);
+ QualifiedPackageName a("foo/bar");
+ TEST_CHECK_THROWS(a = QualifiedPackageName("moo"), NameError);
+ TEST_CHECK_THROWS(a = QualifiedPackageName("foo/bar!"), NameError);
+ TEST_CHECK_THROWS(a = QualifiedPackageName("foo/bar/baz"), NameError);
}
} test_qualified_package_name_validate;
@@ -78,9 +78,9 @@ namespace test_cases
void run()
{
- QualifiedPackageName foo1_bar1(make_qualified_package_name("foo1/bar1"));
- QualifiedPackageName foo1_bar2(make_qualified_package_name("foo1/bar2"));
- QualifiedPackageName foo2_bar1(make_qualified_package_name("foo2/bar1"));
+ QualifiedPackageName foo1_bar1("foo1/bar1");
+ QualifiedPackageName foo1_bar2("foo1/bar2");
+ QualifiedPackageName foo2_bar1("foo2/bar1");
TEST_CHECK( (foo1_bar1 < foo1_bar2));
TEST_CHECK( (foo1_bar1 <= foo1_bar2));
diff --git a/paludis/version_metadata.cc b/paludis/version_metadata.cc
index e8ffd81..cc22137 100644
--- a/paludis/version_metadata.cc
+++ b/paludis/version_metadata.cc
@@ -20,7 +20,7 @@
#include "version_metadata.hh"
#include "create_insert_iterator.hh"
#include "tokeniser.hh"
-#include "transform_insert_iterator.hh"
+#include "create_insert_iterator.hh"
#include <vector>
using namespace paludis;
@@ -133,9 +133,8 @@ VersionMetadata::begin_provide() const
{
Tokeniser<delim_kind::AnyOfTag, delim_mode::DelimiterTag> tokeniser(" \t\n");
tokeniser.tokenise(get(vmk_provide),
- transform_inserter(
- std::inserter(_implementation->provide, _implementation->provide.begin()),
- std::ptr_fun(&make_qualified_package_name)));
+ create_inserter<QualifiedPackageName>(
+ std::inserter(_implementation->provide, _implementation->provide.begin())));
}
return _implementation->provide.begin();