/* Web Polygraph http://www.web-polygraph.org/ * (C) 2003-2006 The Measurement Factory * Licensed under the Apache License, Version 2.0 */ #ifndef POLYGRAPH__RUNTIME_MODULEREGISTRY_H #define POLYGRAPH__RUNTIME_MODULEREGISTRY_H #include "xstd/h/iostream.h" #include "xstd/Array.h" #include "xstd/String.h" #include "xstd/LibInit.h" // common interface of various module registries template class ModuleRegistry { public: typedef ModuleType Module; public: inline ModuleRegistry(const String &aKind); inline ~ModuleRegistry(); // calls clear() inline void clear(); // deletes registered modules // registers, absorbs, and returns a unique module index int add(Module *m); void report(ostream &os); // reports registered modules protected: Array theModules; String theKind; }; template inline ModuleRegistry::ModuleRegistry(const String &aKind): theKind(aKind) { } template inline ModuleRegistry::~ModuleRegistry() { clear(); } template inline void ModuleRegistry::clear() { while (theModules.count()) delete theModules.pop(); } template inline int ModuleRegistry::add(Module *m) { theModules.append(m); return theModules.count() - 1; } template inline void ModuleRegistry::report(ostream &os) { os << "registered " << theKind << ": " << theModules.count(); for (int i = 0; i < theModules.count(); ++i) { os << "\n\t" << theModules[i]->id() << ":\t "; theModules[i]->describe(os); os << endl; } } #endif