Refactor extra generator registration to use factories

This will allow additional information about the availability
and capabilities of extra generators to be queried without
actually creating them.

Instead of a static NewFactory() method like the main generator
factories have, use a static GetFactory() method to get a pointer to a
statically allocated extra generator factory.  This simplifies memory
management.
This commit is contained in:
Tobias Hunger
2016-07-20 18:28:39 +02:00
committed by Brad King
parent fd59f9ad51
commit a354f60ce0
16 changed files with 282 additions and 241 deletions
+48 -7
View File
@@ -35,11 +35,6 @@ class cmExternalMakefileProjectGenerator
public:
virtual ~cmExternalMakefileProjectGenerator() {}
///! Get the name for this generator.
virtual std::string GetName() const = 0;
/** Get the documentation entry for this generator. */
virtual void GetDocumentation(cmDocumentationEntry& entry,
const std::string& fullName) const = 0;
virtual void EnableLanguage(std::vector<std::string> const& languages,
cmMakefile*, bool optional);
@@ -55,8 +50,6 @@ public:
return this->SupportedGlobalGenerators;
}
///! Get the name of the global generator for the given full name
std::string GetGlobalGeneratorName(const std::string& fullName);
/** Create a full name from the given global generator name and the
* extra generator name
*/
@@ -66,11 +59,59 @@ public:
///! Generate the project files, the Makefiles have already been generated
virtual void Generate() = 0;
void SetName(const std::string& n) { Name = n; }
std::string GetName() const { return Name; }
protected:
///! Contains the names of the global generators support by this generator.
std::vector<std::string> SupportedGlobalGenerators;
///! the global generator which creates the makefiles
const cmGlobalGenerator* GlobalGenerator;
std::string Name;
};
class cmExternalMakefileProjectGeneratorFactory
{
public:
cmExternalMakefileProjectGeneratorFactory(const std::string& n,
const std::string& doc);
virtual ~cmExternalMakefileProjectGeneratorFactory();
std::string GetName() const;
std::string GetDocumentation() const;
std::vector<std::string> GetSupportedGlobalGenerators() const;
std::vector<std::string> Aliases;
virtual cmExternalMakefileProjectGenerator*
CreateExternalMakefileProjectGenerator() const = 0;
void AddSupportedGlobalGenerator(const std::string& base);
private:
std::string Name;
std::string Documentation;
std::vector<std::string> SupportedGlobalGenerators;
};
template <class T>
class cmExternalMakefileProjectGeneratorSimpleFactory
: public cmExternalMakefileProjectGeneratorFactory
{
public:
cmExternalMakefileProjectGeneratorSimpleFactory(const std::string& n,
const std::string& doc)
: cmExternalMakefileProjectGeneratorFactory(n, doc)
{
}
cmExternalMakefileProjectGenerator* CreateExternalMakefileProjectGenerator()
const
{
T* p = new T;
p->SetName(GetName());
return p;
}
};
#endif