// This file may be redistributed and modified only under the terms of // the GNU Lesser General Public License (See COPYING for details). // Copyright (C) 2000 Aloril // Copyright (C) 2005 Al Riddoch #ifndef ATLAS_OBJECTS_OBJECTFACTORY_H #define ATLAS_OBJECTS_OBJECTFACTORY_H #include #include #include #include #include namespace Atlas { namespace Objects { class NoSuchFactoryException : public Atlas::Exception { protected: std::string name; public: NoSuchFactoryException(const std::string& name) : Atlas::Exception("No factory for Objects type"), name(name) { } virtual ~NoSuchFactoryException() throw (); const std::string & getName() { return name; } }; template static SmartPtr factory(const std::string &, int) { SmartPtr obj; return obj; } SmartPtr generic_factory(const std::string & name, int no); SmartPtr anonymous_factory(const std::string & name, int no); typedef Root (*FactoryMethod)(const std::string &, int); typedef std::map > FactoryMap; class Factories { public: friend class AddFactories; Factories(); explicit Factories(const Factories &); bool hasFactory(const std::string& name); Root createObject(const std::string& name); Root createObject(const Atlas::Message::MapType & msg); std::list getKeys(); int addFactory(const std::string& name, FactoryMethod method); static Factories * instance(); private: FactoryMap m_factories; static Factories * m_instance; void addFactory(const std::string& name, FactoryMethod method, int classno); }; extern std::map objectDefinitions; } } // namespace Atlas::Objects #endif // ATLAS_OBJECTS_OBJECTFACTORY_H