#include <paludis/paludis.hh>
#include <iostream>
#include <iomanip>
#include <set>
#include <cstdlib>
using namespace examples;
using std::cout;
using std::endl;
using std::left;
using std::setw;
namespace
{
void show_key(
const MetadataKey & key,
const std::string & indent =
"");
std::string stringify_string_pair(const std::pair<const std::string, std::string> & s)
{
if (s.first.empty())
return s.second;
else
return s.first + "=" + s.second;
}
class MetadataKeyInformationVisitor
{
private:
std::string indent;
public:
MetadataKeyInformationVisitor(const std::string & i = "") :
indent(i)
{
}
{
cout << indent << left << setw(30) << " Class:" << " " << "MetadataValueKey<std::string>" << endl;
cout << indent << left << setw(30) << " Value:" << " " << key.parse_value() << endl;
}
{
cout << indent << left << setw(30) << " Class:" << " " << "MetadataValueKey<SlotName>" << endl;
cout << indent << left << setw(30) << " Value:" << " " << key.parse_value().raw_value() << endl;
}
{
cout << indent << left << setw(30) << " Class:" << " " << "MetadataValueKey<long>" << endl;
cout << indent << left << setw(30) << " Value:" << " " << key.parse_value() << endl;
}
{
cout << indent << left << setw(30) << " Class:" << " " << "MetadataValueKey<bool>" << endl;
cout << indent << left << setw(30) << " Value:" << " " << key.parse_value() << endl;
}
{
cout << indent << left << setw(30) << " Class:" << " " << "MetadataValueKey<FSPath>" << endl;
cout << indent << left << setw(30) << " Value:" << " " << key.parse_value() << endl;
}
{
cout << indent << left << setw(30) << " Class:" << " " <<
"MetadataValueKey<std::shared_ptr<const PackageID> >" << endl;
cout << indent << left << setw(30) << " Value:" << " " << *key.parse_value() << endl;
}
{
cout << indent << left << setw(30) << " Class:" << " " << "MetadataTimeKey" << endl;
cout << indent << left << setw(30) <<
" Value:" <<
" " <<
pretty_print_time(key.parse_value().seconds()) << endl;
}
{
cout << indent << left << setw(30) << " Class:" << " " <<
"MetadataValueKey<std::shared_ptr<const Choices> > " << endl;
}
{
cout << indent << left << setw(30) << " Class:" << " " << "MetadataSpecTreeKey<PlainTextSpecTree>" << endl;
cout << indent << left << setw(30) <<
" Value:" <<
" " << key.pretty_print_value(
UnformattedPrettyPrinter(), { }) << endl;
}
{
cout << indent << left << setw(30) << " Class:" << " " << "MetadataSpecTreeKey<RequiredUseSpecTree>" << endl;
cout << indent << left << setw(30) <<
" Value:" <<
" " << key.pretty_print_value(
UnformattedPrettyPrinter(), { }) << endl;
}
{
cout << indent << left << setw(30) << " Class:" << " " << "MetadataSpecTreeKey<LicenseSpecTree>" << endl;
cout << indent << left << setw(30) <<
" Value:" <<
" " << key.pretty_print_value(
UnformattedPrettyPrinter(), { }) << endl;
}
{
cout << indent << left << setw(30) << " Class:" << " " << "MetadataSpecTreeKey<SimpleURISpecTree>" << endl;
cout << indent << left << setw(30) <<
" Value:" <<
" " << key.pretty_print_value(
UnformattedPrettyPrinter(), { }) << endl;
}
{
cout << indent << left << setw(30) << " Class:" << " " << "MetadataSpecTreeKey<DependencySpecTree>" << endl;
cout << indent << left << setw(30) <<
" Value:" <<
" " << key.pretty_print_value(
UnformattedPrettyPrinter(), { }) << endl;
}
{
cout << indent << left << setw(30) << " Class:" << " " << "MetadataSpecTreeKey<FetchableURISpecTree>" << endl;
cout << indent << left << setw(30) <<
" Value:" <<
" " << key.pretty_print_value(
UnformattedPrettyPrinter(), { }) << endl;
cout << indent << left << setw(30) << " Initial label:" << " " << key.initial_label()->text() << endl;
}
{
cout << indent << left << setw(30) << " Class:" << " " << "MetadataCollectionKey<KeywordNameSet>" << endl;
cout << indent << left << setw(30) <<
" Value:" <<
" " << key.pretty_print_value(
UnformattedPrettyPrinter(), { }) << endl;
}
{
auto value(key.parse_value());
cout << indent << left << setw(30) << " Class:" << " " << "MetadataCollectionKey<Set<std::string> >" << endl;
cout << indent << left << setw(30) <<
" Value:" <<
" " <<
join(value->begin(), value->end(),
" ") << endl;
}
{
auto value(key.parse_value());
cout << indent << left << setw(30) << " Class:" << " " << "MetadataCollectionKey<Map<std::string, std::string> >" << endl;
cout << indent << left << setw(30) <<
" Value:" <<
" " <<
join(value->begin(), value->end(),
" ", stringify_string_pair) << endl;
}
{
auto value(key.parse_value());
cout << indent << left << setw(30) << " Class:" << " " << "MetadataCollectionKey<Sequence<std::string> >" << endl;
cout << indent << left << setw(30) <<
" Value:" <<
" " <<
join(value->begin(), value->end(),
" ") << endl;
}
{
auto value(key.parse_value());
cout << indent << left << setw(30) << " Class:" << " " << "MetadataCollectionKey<Maintainers>" << endl;
cout << indent << left << setw(30) <<
" Value:" <<
" " <<
join(value->begin(), value->end(),
" ") << endl;
}
{
auto value(key.parse_value());
cout << indent << left << setw(30) << " Class:" << " " << "MetadataCollectionKey<FSPathSequence>" << endl;
cout << indent << left << setw(30) <<
" Value:" <<
" " <<
join(value->begin(), value->end(),
" ") << endl;
}
{
auto value(key.parse_value());
cout << indent << left << setw(30) << " Class:" << " " << "MetadataCollectionKey<PackageIDSequence>" << endl;
}
{
cout << indent << left << setw(30) << " Class:" << " " << "MetadataSectionKey" << endl;
cout << indent << left << setw(30) << " Keys:" << endl;
for (const auto & section_key : key.metadata())
{
show_key(*section_key, indent + " ");
cout << endl;
}
}
};
void show_key(
const MetadataKey & key,
const std::string & indent)
{
cout << indent << left << setw(30) << " Raw name:" << " " << key.raw_name() << endl;
cout << indent << left << setw(30) << " Human name:" << " " << key.human_name() << endl;
cout << indent << left << setw(30) << " Type:" << " " << key.type() << endl;
MetadataKeyInformationVisitor v(indent);
key.accept(v);
}
}
int main(int argc, char * argv[])
{
int exit_status(0);
try
{
"example_metadata_key", "EXAMPLE_METADATA_KEY_OPTIONS", "EXAMPLE_METADATA_KEY_CMDLINE");
for (const auto & id : *ids)
{
cout << *id << ":" << endl;
for (const auto & key : id->metadata())
{
show_key(*key);
cout << endl;
}
cout << endl;
}
for (const auto & repository : env->repositories())
{
cout << repository->name() << ":" << endl;
for (const auto & key : repository->metadata())
{
show_key(*key);
cout << endl;
}
cout << endl;
}
}
{
cout << endl;
cout << "Unhandled exception:" << endl
return EXIT_FAILURE;
}
catch (const std::exception & e)
{
cout << endl;
cout << "Unhandled exception:" << endl
<< " * " << e.what() << endl;
return EXIT_FAILURE;
}
catch (...)
{
cout << endl;
cout << "Unhandled exception:" << endl
<< " * Unknown exception type. Ouch..." << endl;
return EXIT_FAILURE;
}
return exit_status;
}
Definition exception.hh:77
std::string backtrace(const std::string &delim) const
const char * what() const noexcept override
const std::string & message() const noexcept
Definition sequence.hh:51
static CommandLine * get_instance() PALUDIS_ATTRIBUTE((warn_unused_result))
Definition generator.hh:179
Definition selection.hh:172
IndirectIterator< Iter_ > indirect_iterator(const Iter_ &)
T_ join(I_ i, I_ end, const T_ &joiner)
Definition join.hh:45
Definition about_metadata-fwd.hh:24
std::string pretty_print_time(const time_t &t) PALUDIS_VISIBLE