27 void help(std::string argv0) {
28 std::cout <<
"Usage: " << argv0 <<
" [option] library1 [library2 ...]\n"
29 "\n list the component factories present in the given libraries\n\n"
31 " -h, --help show this help message and exit\n"
32 " -o OUTPUT, --output OUTPUT\n"
33 " write the list of factories on the file OUTPUT, use - for\n"
34 " standard output (default)\n"
39 std::cout <<
"Usage: " << argv0 <<
" [option] library1 [library2 ...]\n"
40 "Try `" << argv0 <<
" -h' for more information.\n"
50 std::map<key_type, std::string> loaded;
54 for (std::set<key_type>::const_iterator f = base.begin(); f != base.end(); ++f)
56 loaded.insert(std::make_pair(*f, std::string(
"<preloaded>")));
61 std::list<char*> libs;
62 std::string output_opt(
"-");
64 std::string argv0(argv[0]);
66 auto i = argv0.rfind(
'/');
67 if (
i != std::string::npos)
68 argv0 = argv0.substr(
i+1);
73 const std::string arg(argv[i]);
74 if (arg ==
"-o" || arg ==
"--output") {
78 std::cerr <<
"ERROR: missing argument for option " << arg << std::endl;
79 std::cerr <<
"See `" << argv0 <<
" -h' for more details." << std::endl;
82 }
else if (arg ==
"-h" || arg ==
"--help") {
86 libs.push_back(argv[i]);
97 std::unique_ptr<std::ostream> output_file;
98 if (output_opt !=
"-") {
99 output_file = std::unique_ptr<std::ostream>(
new std::ofstream(output_opt.c_str()));
101 std::ostream &output = (output_file ? *output_file : std::cout);
104 for (
char* lib: libs) {
106 if (dlopen(lib, RTLD_LAZY | RTLD_LOCAL)) {
109 std::set<key_type>::const_iterator f;
110 for (f = factories.begin(); f != factories.end(); ++f) {
111 if (loaded.find(*f) == loaded.end())
113 output << lib <<
":" << *f << std::endl;
117 std::cerr <<
"WARNING: factory '" << *f
118 <<
"' already found in " << loaded[*f]
123 std::cerr <<
"ERROR: failed to load " << lib << std::endl;
GAUDI_API long argc()
Number of arguments passed to the commandline (==numCmdLineArgs()); just to match argv call...
void usage(std::string argv0)
std::set< KeyType > loadedFactories() const
Return a list of all the known and loaded factories.
int main(int argc, char *argv[])
void help(std::string argv0)
static Registry & instance()
Retrieve the singleton instance of Registry.
In-memory database of the loaded factories.