summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Hartwig <mandyke@gmail.com>2012-03-27 15:46:15 +0800
committerDaniel Hartwig <mandyke@gmail.com>2012-03-27 15:47:42 +0800
commit2b991acae3c5c90fd119871f1b0a543c47d4dcc4 (patch)
treec597242284fa4497c327861c168a979319d8be7a /src
parent5b7df4ea4f72bbd96022e0bc6b35128fe3246157 (diff)
downloadaptitude-2b991acae3c5c90fd119871f1b0a543c47d4dcc4.tar.gz
Add architecture grouping policy
Diffstat (limited to 'src')
-rw-r--r--src/load_grouppolicy.cc12
-rw-r--r--src/pkg_grouppolicy.cc68
-rw-r--r--src/pkg_grouppolicy.h14
3 files changed, 94 insertions, 0 deletions
diff --git a/src/load_grouppolicy.cc b/src/load_grouppolicy.cc
index 3189e827..c8aad707 100644
--- a/src/load_grouppolicy.cc
+++ b/src/load_grouppolicy.cc
@@ -758,6 +758,17 @@ class pattern_policy_parser : public group_policy_parser
}
};
+class arch_policy_parser : public string_policy_parser
+{
+ group_policy_parse_node *create_node(const vector<string> &args)
+ {
+ if(args.size()!=0)
+ throw GroupParseException(_("Grouping policy '%s' takes no arguments"), "architecture");
+
+ return new policy_node0<pkg_grouppolicy_arch_factory>;
+ }
+};
+
static void init_parse_types()
{
static bool initted_parse_types=false;
@@ -770,6 +781,7 @@ static void init_parse_types()
parse_types["filter"]=new filter_policy_parser;
parse_types["firstchar"]=new firstchar_policy_parser;
parse_types["source"]=new source_policy_parser;
+ parse_types["architecture"]=new arch_policy_parser;
parse_types["versions"]=new ver_policy_parser;
parse_types["deps"]=new dep_policy_parser;
diff --git a/src/pkg_grouppolicy.cc b/src/pkg_grouppolicy.cc
index 76b8b2f0..66588138 100644
--- a/src/pkg_grouppolicy.cc
+++ b/src/pkg_grouppolicy.cc
@@ -1765,3 +1765,71 @@ pkg_grouppolicy *pkg_grouppolicy_source_factory::instantiate(pkg_signal *sig,
{
return new pkg_grouppolicy_source(chain, sig, desc_sig);
}
+
+/*****************************************************************************/
+
+// Groups packages by architecture
+class pkg_grouppolicy_arch:public pkg_grouppolicy
+{
+ typedef map<string,
+ pair<pkg_grouppolicy *, pkg_subtree *> > childmap;
+
+ childmap children;
+ pkg_grouppolicy_factory *chain;
+
+ pkg_grouppolicy *spillover;
+
+public:
+ pkg_grouppolicy_arch(pkg_grouppolicy_factory *_chain,
+ pkg_signal *_sig, desc_signal *_desc_sig)
+ :pkg_grouppolicy(_sig, _desc_sig),
+ chain(_chain),
+ spillover(_chain->instantiate(get_sig(), get_desc_sig()))
+ {
+ }
+
+ ~pkg_grouppolicy_arch()
+ {
+ for(childmap::iterator i=children.begin(); i!=children.end(); i++)
+ delete i->second.first;
+ }
+
+ void add_package(const pkgCache::PkgIterator &pkg, pkg_subtree *root)
+ {
+ string arch;
+
+ if(!pkg.VersionList().end())
+ {
+ arch=pkg.VersionList().Arch();
+ }
+ else
+ {
+ arch=_("virtual");
+ }
+
+ childmap::iterator found=children.find(arch);
+
+ if(found!=children.end())
+ found->second.first->add_package(pkg, found->second.second);
+ else
+ {
+ pkg_subtree *newtree=new pkg_subtree(cw::util::transcode(arch),
+ L"",
+ get_desc_sig());
+ pkg_grouppolicy *newchild=chain->instantiate(get_sig(),
+ get_desc_sig());
+ children[arch].first=newchild;
+ children[arch].second=newtree;
+ root->add_child(newtree);
+ newtree->set_num_packages_parent(root);
+
+ newchild->add_package(pkg, newtree);
+ }
+ }
+};
+
+pkg_grouppolicy *pkg_grouppolicy_arch_factory::instantiate(pkg_signal *sig,
+ desc_signal *desc_sig)
+{
+ return new pkg_grouppolicy_arch(chain, sig, desc_sig);
+}
diff --git a/src/pkg_grouppolicy.h b/src/pkg_grouppolicy.h
index f9169e21..33d3d860 100644
--- a/src/pkg_grouppolicy.h
+++ b/src/pkg_grouppolicy.h
@@ -391,4 +391,18 @@ public:
{delete chain;}
};
+// Groups by architecture
+class pkg_grouppolicy_arch_factory:public pkg_grouppolicy_factory
+{
+ pkg_grouppolicy_factory *chain;
+public:
+ pkg_grouppolicy_arch_factory(pkg_grouppolicy_factory *_chain):chain(_chain) {}
+
+ pkg_grouppolicy *instantiate(pkg_signal *_sig,
+ desc_signal *_desc_sig);
+
+ virtual ~pkg_grouppolicy_arch_factory()
+ {delete chain;}
+};
+
#endif