17#ifndef NAME_FACTORY_GUARD
18#define NAME_FACTORY_GUARD
32template<
class AbstractProduct>
69template<
class ConcreteProduct,
class AbstractProduct>
75template<
class AbstractProduct>
88template<
class AbstractProduct>
97template<
class AbstractProduct>
106template<
class AbstractProduct>
112 "Unknown " + getAbstractProductName() +
" \"" +
name +
"\".");
116template<
class AbstractProduct>
122template<
class AbstractProduct>
126 if (
it->first.compare(0, prefix.size(), prefix) == 0)
131template<
class AbstractProduct>
133 return _pairs.empty();
136template<
class AbstractProduct>
138 return _abstractName;
141template<
class ConcreteProduct,
class AbstractProduct>
148 factory.registerProduct(ConcreteProduct::staticGetName(),
149 HoldsFunction::createConcreteProduct);
152template<
class AbstractProduct>
158template<
class AbstractProduct>
161 vector<string>
names;
166 names.push_back(prefix);
171 (
"No " +
factory.getAbstractProductName() +
172 " has the prefix \"" + prefix +
"\".");
175 if (
names.size() >= 2) {
176 string errorMsg =
"More than one " +
factory.getAbstractProductName() +
177 " has prefix \"" + prefix +
"\":\n ";
void product(Matrix &prod, const Matrix &a, const Matrix &b)
Sets prod to a * b.
auto_ptr< AbstractProduct > createWithPrefix(const NameFactory< AbstractProduct > &factory, const string &prefix)
Creates the unique product that has the indicated prefix, or create the actual product that has name ...
void nameFactoryRegister(NameFactory< AbstractProduct > &factory)
Registers the string returned by ConcreteProduct::getStaticName() to a function that default-construc...
string getUniqueNameWithPrefix(const NameFactory< AbstractProduct > &factory, const string &prefix)
Returns the unique product name that has the indicated prefix, or return prefix itself if it is the a...
A NameFactory takes a name and then creates an instance of a class that has been previously registere...
pair< string, FactoryFunction > Pair
NameFactory(const char *abstractName)
vector< Pair >::const_iterator const_iterator
string getAbstractProductName() const
auto_ptr< AbstractProduct > createNoThrow(const string &name) const
Calls the function registered to the parameter name and returns the result.
auto_ptr< AbstractProduct >(* FactoryFunction)()
const string _abstractName
bool empty() const
Returns true if no names have been registered.
void getNamesWithPrefix(const string &prefix, vector< string > &names) const
Inserts into names all registered names that have the indicated prefix in lexicographic increasing or...
void registerProduct(const string &name, FactoryFunction function)
auto_ptr< AbstractProduct > create(const string &name) const
Calls the function registered to the parameter name and returns the result.