This example demonstrates how to use contents. It displays details about the files installed by 'sys-apps/paludis'.
#include <paludis/paludis.hh>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdlib>
using namespace examples;
using std::cout;
using std::endl;
using std::left;
using std::setw;
namespace
{
class ContentsPrinter
{
public:
{
cout << left << setw(10) <<
"file" << d.
location_key()->parse_value() << endl;
}
{
cout << left << setw(10) <<
"dir" << d.
location_key()->parse_value() << endl;
}
{
cout << left << setw(10) <<
"sym" << d.
location_key()->parse_value()
<<
" -> " << d.
target_key()->parse_value() << endl;
}
{
cout << left << setw(10) <<
"other" << d.
location_key()->parse_value() << endl;
}
};
}
int main(int argc, char * argv[])
{
int exit_status(0);
try
{
"example_contents", "EXAMPLE_CONTENTS_OPTIONS", "EXAMPLE_CONTENTS_CMDLINE");
for (const auto & id : *ids)
{
auto contents(id->contents());
if (! contents)
{
cout << "ID '" << *id << "' does not provide a contents key." << endl;
}
else
{
cout << "ID '" << *id << "' provides contents key:" << endl;
ContentsPrinter p;
std::for_each(
}
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 contents.hh:138
const std::shared_ptr< const MetadataValueKey< FSPath > > location_key() const
Definition contents.hh:107
Definition contents.hh:158
Definition contents.hh:177
const std::shared_ptr< const MetadataValueKey< std::string > > target_key() const
Definition exception.hh:77
std::string backtrace(const std::string &delim) const
const char * what() const noexcept override
const std::string & message() const noexcept
static CommandLine * get_instance() PALUDIS_ATTRIBUTE((warn_unused_result))
Definition generator.hh:179
Definition selection.hh:172
IndirectIterator< Iter_ > indirect_iterator(const Iter_ &)
AcceptVisitor< Visitor_ > PALUDIS_VISIBLE accept_visitor(Visitor_ &v)
Definition visitor.hh:100
Definition about_metadata-fwd.hh:24