This example demonstrates how to use contents. It displays details about the files installed by 'sys-apps/paludis'.
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdlib>
using namespace paludis;
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
{
CommandLine::get_instance()->run(argc, argv,
"example_contents", "EXAMPLE_CONTENTS_OPTIONS", "EXAMPLE_CONTENTS_CMDLINE");
CommandLine::get_instance()->a_environment.argument()));
i != i_end ; ++i)
{
auto contents((*i)->contents());
if (! contents)
{
cout << "ID '" << **i << "' does not provide a contents key." << endl;
}
else
{
cout << "ID '" << **i << "' 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;
}