Fixed auto4 script engine manager (hopefully)

Originally committed to SVN as r650.
This commit is contained in:
Niels Martin Hansen 2006-12-28 23:03:26 +00:00
parent e39bc37271
commit a6bebb3da7
2 changed files with 20 additions and 8 deletions

View File

@ -643,7 +643,7 @@ namespace Automation4 {
// ScriptFactory
std::vector<ScriptFactory*> ScriptFactory::factories;
std::vector<ScriptFactory*> *ScriptFactory::factories = 0;
const wxString& ScriptFactory::GetEngineName() const
{
@ -657,19 +657,25 @@ namespace Automation4 {
void ScriptFactory::Register(ScriptFactory *factory)
{
for (std::vector<ScriptFactory*>::iterator i = factories.begin(); i != factories.end(); ++i) {
if (!factories)
factories = new std::vector<ScriptFactory*>();
for (std::vector<ScriptFactory*>::iterator i = factories->begin(); i != factories->end(); ++i) {
if (*i == factory) {
throw _T("Automation 4: Attempt to register the same script factory multiple times.");
}
}
factories.push_back(factory);
factories->push_back(factory);
}
void ScriptFactory::Unregister(ScriptFactory *factory)
{
for (std::vector<ScriptFactory*>::iterator i = factories.begin(); i != factories.end(); ++i) {
if (!factories)
factories = new std::vector<ScriptFactory*>();
for (std::vector<ScriptFactory*>::iterator i = factories->begin(); i != factories->end(); ++i) {
if (*i == factory) {
factories.erase(i);
factories->erase(i);
return;
}
}
@ -677,7 +683,10 @@ namespace Automation4 {
Script* ScriptFactory::CreateFromFile(const wxString &filename)
{
for (std::vector<ScriptFactory*>::iterator i = factories.begin(); i != factories.end(); ++i) {
if (!factories)
factories = new std::vector<ScriptFactory*>();
for (std::vector<ScriptFactory*>::iterator i = factories->begin(); i != factories->end(); ++i) {
Script *s = (*i)->Produce(filename);
if (s) return s;
}
@ -686,7 +695,10 @@ namespace Automation4 {
const std::vector<ScriptFactory*>& ScriptFactory::GetFactories()
{
return factories;
if (!factories)
factories = new std::vector<ScriptFactory*>();
return *factories;
}

View File

@ -335,7 +335,7 @@ namespace Automation4 {
// This is used to create Script objects from a file.
class ScriptFactory {
private:
static std::vector<ScriptFactory*> factories;
static std::vector<ScriptFactory*> *factories;
protected:
ScriptFactory() { }
wxString engine_name;