11#ifndef __interface_factory_h
12#define __interface_factory_h
20namespace TextInterface
38 template<
typename T,
typename C>
39 T* factory (C& ptrs, std::string name_parse)
41 std::string name = stringtok (name_parse,
":");
43 DEBUG(
"TextInterface::factory name=" << name);
48 Reference::To<T> result;
58 for (
auto ptr=ptrs.begin(); ptr != ptrs.end(); ptr++)
60 Reference::To<T> candidate = *ptr;
61 Reference::To<TextInterface::Parser>
interface = candidate->get_interface();
65 message += interface->get_interface_name() +
"\t"
66 + interface->get_interface_description() +
"\n"
67 + interface->help (
true,
false,
" ");
69 else if (interface->get_interface_name() == name)
71 result = candidate->clone ();
83 DEBUG(
"TextInterface::factory throwing HelpMessage = " << message);
84 throw Error (HelpMessage, std::string(), message);
88 throw Error (InvalidState, std::string(),
89 "no instance named '" + name +
"'");
91 DEBUG(
"TextInterface::factory options=" << name_parse);
93 while (braced(name_parse))
95 DEBUG(
"TextInterface::factory removing brackets");
96 name_parse.erase (name_parse.begin());
97 name_parse.erase (name_parse.end()-1);
100 Reference::To<TextInterface::Parser>
interface = result->get_interface();
102 std::vector<std::string> options;
103 standard_separation (options, name_parse);
104 for (
unsigned i=0; i<options.size(); i++)
106 DEBUG(
"TextInterface::factory option["<<i<<
"]=" << options[i]);
108 interface->process (options[i]);
Type * release()
Return the pointer and unhook without deleting the object.
Definition ReferenceTo.h:263