aboutsummaryrefslogtreecommitdiff
path: root/paludis/repositories/fake
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-09-22 09:26:29 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-09-22 09:26:29 +0000
commit538756fb3236428ab50d027176e757c5dd2e3d1e (patch)
tree3cb68fd08fbd696e4d826c2882ab8ffa5057e52f /paludis/repositories/fake
parent0f48cefea53ccd11d68255c5d52cf620b121303b (diff)
downloadpaludis-538756fb3236428ab50d027176e757c5dd2e3d1e.tar.gz
paludis-538756fb3236428ab50d027176e757c5dd2e3d1e.tar.xz
Formatters
Diffstat (limited to 'paludis/repositories/fake')
-rw-r--r--paludis/repositories/fake/fake_package_id.cc140
-rw-r--r--paludis/repositories/fake/fake_package_id.hh26
2 files changed, 148 insertions, 18 deletions
diff --git a/paludis/repositories/fake/fake_package_id.cc b/paludis/repositories/fake/fake_package_id.cc
index ece447696..40d3c6ada 100644
--- a/paludis/repositories/fake/fake_package_id.cc
+++ b/paludis/repositories/fake/fake_package_id.cc
@@ -25,6 +25,7 @@
#include <paludis/action.hh>
#include <paludis/environment.hh>
#include <paludis/version_spec.hh>
+#include <paludis/formatter.hh>
#include <paludis/dep_spec.hh>
#include <paludis/hashed_containers.hh>
#include <paludis/util/stringify.hh>
@@ -52,14 +53,23 @@ namespace paludis
struct Implementation<FakeMetadataSetKey<C_> >
{
tr1::shared_ptr<C_> collection;
+ const PackageID * const id;
+ const Environment * const env;
+
+ Implementation(const PackageID * const i, const Environment * const e) :
+ id(i),
+ env(e)
+ {
+ }
};
}
template <typename C_>
FakeMetadataSetKey<C_>::FakeMetadataSetKey(
- const std::string & r, const std::string & h, const MetadataKeyType t) :
+ const std::string & r, const std::string & h, const MetadataKeyType t, const PackageID * const i,
+ const Environment * const e) :
MetadataSetKey<C_>(r, h, t),
- PrivateImplementationPattern<FakeMetadataSetKey<C_> >(new Implementation<FakeMetadataSetKey<C_> >),
+ PrivateImplementationPattern<FakeMetadataSetKey<C_> >(new Implementation<FakeMetadataSetKey<C_> >(i, e)),
_imp(PrivateImplementationPattern<FakeMetadataSetKey<C_> >::_imp.get())
{
}
@@ -77,8 +87,9 @@ FakeMetadataSetKey<C_>::value() const
}
FakeMetadataKeywordSetKey::FakeMetadataKeywordSetKey(const std::string & r,
- const std::string & h, const std::string & v, const MetadataKeyType t) :
- FakeMetadataSetKey<KeywordNameSet>(r, h, t)
+ const std::string & h, const std::string & v, const MetadataKeyType t,
+ const PackageID * const i, const Environment * const e) :
+ FakeMetadataSetKey<KeywordNameSet>(r, h, t, i, e)
{
set_from_string(v);
}
@@ -91,8 +102,9 @@ FakeMetadataKeywordSetKey::set_from_string(const std::string & s)
}
FakeMetadataIUseSetKey::FakeMetadataIUseSetKey(const std::string & r,
- const std::string & h, const std::string & v, const IUseFlagParseMode m, const MetadataKeyType t) :
- FakeMetadataSetKey<IUseFlagSet>(r, h, t)
+ const std::string & h, const std::string & v, const IUseFlagParseMode m, const MetadataKeyType t,
+ const PackageID * const i, const Environment * const e) :
+ FakeMetadataSetKey<IUseFlagSet>(r, h, t, i, e)
{
set_from_string(v, m);
}
@@ -105,7 +117,7 @@ FakeMetadataIUseSetKey::set_from_string(const std::string & s, const IUseFlagPar
WhitespaceTokeniser::get_instance()->tokenise(s, std::back_inserter(tokens));
for (std::list<std::string>::const_iterator t(tokens.begin()), t_end(tokens.end()) ;
t != t_end ; ++t)
- _imp->collection->insert(IUseFlag(*t, m));
+ _imp->collection->insert(IUseFlag(*t, m, std::string::npos));
}
namespace paludis
@@ -157,14 +169,14 @@ FakeMetadataSpecTreeKey<C_>::value() const
template <typename C_>
std::string
-FakeMetadataSpecTreeKey<C_>::pretty_print() const
+FakeMetadataSpecTreeKey<C_>::pretty_print(const typename C_::Formatter &) const
{
return _imp->string_value;
}
template <typename C_>
std::string
-FakeMetadataSpecTreeKey<C_>::pretty_print_flat() const
+FakeMetadataSpecTreeKey<C_>::pretty_print_flat(const typename C_::Formatter &) const
{
return _imp->string_value;
}
@@ -275,14 +287,14 @@ namespace paludis
mutable bool has_masks;
Implementation(const Environment * const e, const tr1::shared_ptr<const FakeRepositoryBase> & r,
- const QualifiedPackageName & q, const VersionSpec & v) :
+ const QualifiedPackageName & q, const VersionSpec & v, const PackageID * const id) :
env(e),
repository(r),
name(q),
version(v),
slot("0"),
- keywords(new FakeMetadataKeywordSetKey("KEYWORDS", "Keywords", "test", mkt_normal)),
- iuse(new FakeMetadataIUseSetKey("IUSE", "Used USE flags", "", iuse_pm_permissive, mkt_normal)),
+ keywords(new FakeMetadataKeywordSetKey("KEYWORDS", "Keywords", "test", mkt_normal, id, env)),
+ iuse(new FakeMetadataIUseSetKey("IUSE", "Used USE flags", "", iuse_pm_permissive, mkt_normal, id, env)),
license(new FakeMetadataSpecTreeKey<LicenseSpecTree>("LICENSE", "Licenses",
"", tr1::bind(&erepository::parse_license, _1,
*erepository::EAPIData::get_instance()->eapi_from_string("0")), mkt_normal)),
@@ -312,7 +324,7 @@ namespace paludis
FakePackageID::FakePackageID(const Environment * const e, const tr1::shared_ptr<const FakeRepositoryBase> & r,
const QualifiedPackageName & q, const VersionSpec & v) :
- PrivateImplementationPattern<FakePackageID>(new Implementation<FakePackageID>(e, r, q, v)),
+ PrivateImplementationPattern<FakePackageID>(new Implementation<FakePackageID>(e, r, q, v, this)),
_imp(PrivateImplementationPattern<FakePackageID>::_imp.get())
{
add_metadata_key(_imp->keywords);
@@ -760,6 +772,108 @@ FakePackageID::fs_location_key() const
return tr1::shared_ptr<const MetadataFSEntryKey>();
}
+std::string
+FakeMetadataIUseSetKey::pretty_print_flat(const Formatter<IUseFlag> & f) const
+{
+ std::string result;
+ for (IUseFlagSet::Iterator i(value()->begin()), i_end(value()->end()) ;
+ i != i_end ; ++i)
+ {
+ if (! result.empty())
+ result.append(" ");
+
+ if (_imp->id->repository()->use_interface && _imp->id->repository()->use_interface->query_use_mask(i->flag, *_imp->id))
+ result.append(f.format(*i, format::Masked()));
+ else if (_imp->id->repository()->use_interface && _imp->id->repository()->use_interface->query_use_force(i->flag, *_imp->id))
+ result.append(f.format(*i, format::Forced()));
+ else if (_imp->env->query_use(i->flag, *_imp->id))
+ result.append(f.format(*i, format::Enabled()));
+ else
+ result.append(f.format(*i, format::Disabled()));
+ }
+
+ return result;
+}
+
+std::string
+FakeMetadataIUseSetKey::pretty_print_flat_with_comparison(
+ const Environment * const env,
+ const tr1::shared_ptr<const PackageID> & id,
+ const Formatter<IUseFlag> & f) const
+{
+ std::string result;
+ for (IUseFlagSet::Iterator i(value()->begin()), i_end(value()->end()) ;
+ i != i_end ; ++i)
+ {
+ if (! result.empty())
+ result.append(" ");
+
+ std::string l;
+ bool n;
+
+ if (_imp->id->repository()->use_interface && _imp->id->repository()->use_interface->query_use_mask(i->flag, *_imp->id))
+ {
+ l = f.format(*i, format::Masked());
+ n = false;
+ }
+ else if (_imp->id->repository()->use_interface && _imp->id->repository()->use_interface->query_use_force(i->flag, *_imp->id))
+ {
+ l = f.format(*i, format::Forced());
+ n = true;
+ }
+ else if (_imp->env->query_use(i->flag, *_imp->id))
+ {
+ l = f.format(*i, format::Enabled());
+ n = true;
+ }
+ else
+ {
+ l = f.format(*i, format::Disabled());
+ n = true;
+ }
+
+ if (! id->iuse_key())
+ l = f.decorate(*i, l, format::Added());
+ else
+ {
+ using namespace tr1::placeholders;
+ IUseFlagSet::Iterator p(std::find_if(id->iuse_key()->value()->begin(), id->iuse_key()->value()->end(),
+ tr1::bind(std::equal_to<UseFlagName>(), i->flag, tr1::bind<const UseFlagName>(&IUseFlag::flag, _1))));
+
+ if (p == id->iuse_key()->value()->end())
+ l = f.decorate(*i, l, format::Added());
+ else if (n != env->query_use(i->flag, *id))
+ l = f.decorate(*i, l, format::Changed());
+ }
+
+ result.append(l);
+ }
+
+ return result;
+}
+
+
+std::string
+FakeMetadataKeywordSetKey::pretty_print_flat(const Formatter<KeywordName> & f) const
+{
+ std::string result;
+ for (KeywordNameSet::Iterator i(value()->begin()), i_end(value()->end()) ;
+ i != i_end ; ++i)
+ {
+ if (! result.empty())
+ result.append(" ");
+
+ tr1::shared_ptr<KeywordNameSet> k(new KeywordNameSet);
+ k->insert(*i);
+ if (_imp->env->accept_keywords(k, *_imp->id))
+ result.append(f.format(*i, format::Accepted()));
+ else
+ result.append(f.format(*i, format::Unaccepted()));
+ }
+
+ return result;
+}
+
template class FakeMetadataSpecTreeKey<LicenseSpecTree>;
template class FakeMetadataSpecTreeKey<ProvideSpecTree>;
template class FakeMetadataSpecTreeKey<DependencySpecTree>;
diff --git a/paludis/repositories/fake/fake_package_id.hh b/paludis/repositories/fake/fake_package_id.hh
index a9bd7cd5f..20739ce9c 100644
--- a/paludis/repositories/fake/fake_package_id.hh
+++ b/paludis/repositories/fake/fake_package_id.hh
@@ -24,6 +24,7 @@
#include <paludis/metadata_key.hh>
#include <paludis/mask.hh>
#include <paludis/util/tr1_functional.hh>
+#include <paludis/util/set.hh>
namespace paludis
{
@@ -37,7 +38,8 @@ namespace paludis
protected:
Implementation<FakeMetadataSetKey> * const _imp;
- FakeMetadataSetKey(const std::string &, const std::string &, const MetadataKeyType);
+ FakeMetadataSetKey(const std::string &, const std::string &, const MetadataKeyType,
+ const PackageID * const, const Environment * const);
public:
~FakeMetadataSetKey();
@@ -49,9 +51,13 @@ namespace paludis
public FakeMetadataSetKey<KeywordNameSet>
{
public:
- FakeMetadataKeywordSetKey(const std::string &, const std::string &, const std::string &, const MetadataKeyType);
+ FakeMetadataKeywordSetKey(const std::string &, const std::string &, const std::string &, const MetadataKeyType,
+ const PackageID * const, const Environment * const);
void set_from_string(const std::string &);
+
+ virtual std::string pretty_print_flat(const Formatter<KeywordName> &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
};
class PALUDIS_VISIBLE FakeMetadataIUseSetKey :
@@ -59,9 +65,19 @@ namespace paludis
{
public:
FakeMetadataIUseSetKey(const std::string &, const std::string &, const std::string &, const IUseFlagParseMode,
- const MetadataKeyType);
+ const MetadataKeyType, const PackageID * const, const Environment * const);
void set_from_string(const std::string &, const IUseFlagParseMode);
+
+ virtual std::string pretty_print_flat(const Formatter<IUseFlag> &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual std::string pretty_print_flat_with_comparison(
+ const Environment * const,
+ const tr1::shared_ptr<const PackageID> &,
+ const Formatter<IUseFlag> &
+ ) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
};
template <typename C_>
@@ -82,10 +98,10 @@ namespace paludis
void set_from_string(const std::string &);
- virtual std::string pretty_print() const
+ virtual std::string pretty_print(const typename C_::Formatter &) const
PALUDIS_ATTRIBUTE((warn_unused_result));
- virtual std::string pretty_print_flat() const
+ virtual std::string pretty_print_flat(const typename C_::Formatter &) const
PALUDIS_ATTRIBUTE((warn_unused_result));
};