00001 // This file may be redistributed and modified only under the terms of 00002 // the GNU Lesser General Public License (See COPYING for details). 00003 // Copyright (C) 2000 Aloril 00004 // Copyright (C) 2005 Al Riddoch 00005 00006 #ifndef ATLAS_OBJECTS_OBJECTFACTORY_H 00007 #define ATLAS_OBJECTS_OBJECTFACTORY_H 00008 00009 #include <Atlas/Objects/Root.h> 00010 #include <Atlas/Objects/SmartPtr.h> 00011 00012 #include <string> 00013 #include <list> 00014 #include <map> 00015 00016 namespace Atlas { namespace Objects { 00017 00018 class NoSuchFactoryException : public Atlas::Exception 00019 { 00020 protected: 00021 std::string name; 00022 public: 00023 NoSuchFactoryException(const std::string& name) : 00024 Atlas::Exception("No factory for Objects type"), name(name) { } 00025 virtual ~NoSuchFactoryException() throw (); 00026 const std::string & getName() { 00027 return name; 00028 } 00029 }; 00030 00031 template <class T> 00032 static SmartPtr<RootData> factory(const std::string &, int) 00033 { 00034 SmartPtr<T> obj; 00035 return obj; 00036 } 00037 00038 SmartPtr<RootData> generic_factory(const std::string & name, int no); 00039 SmartPtr<RootData> anonymous_factory(const std::string & name, int no); 00040 00041 typedef Root (*FactoryMethod)(const std::string &, int); 00042 typedef std::map<const std::string, std::pair<FactoryMethod, int> > FactoryMap; 00043 00044 class Factories 00045 { 00046 public: 00047 friend class AddFactories; 00048 00049 Factories(); 00050 explicit Factories(const Factories &); 00051 00052 bool hasFactory(const std::string& name); 00053 Root createObject(const std::string& name); 00054 Root createObject(const Atlas::Message::MapType & msg); 00055 std::list<std::string> getKeys(); 00056 int addFactory(const std::string& name, FactoryMethod method); 00057 00058 static Factories * instance(); 00059 private: 00060 FactoryMap m_factories; 00061 static Factories * m_instance; 00062 00063 void addFactory(const std::string& name, FactoryMethod method, int classno); 00064 }; 00065 00066 extern std::map<const std::string, Root> objectDefinitions; 00067 00068 } } // namespace Atlas::Objects 00069 00070 #endif // ATLAS_OBJECTS_OBJECTFACTORY_H
Copyright 2000-2004 the respective authors.
This document can be licensed under the terms of the GNU Free Documentation License or the GNU General Public License and may be freely distributed under the terms given by one of these licenses.