source: src/base/factory.hpp@ a40eea

Last change on this file since a40eea was ac6d04, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Merge recent changes of the vmg library into ScaFaCos.

Includes a fix for the communication problems on Jugene.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1666 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[48b662]1/**
2 * @file factory.hpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Tue Apr 5 20:40:41 2011
[dfed1c]5 *
[48b662]6 * @brief Factory class that holds commands and arbitrary objects.
[dfed1c]7 *
8 *
[48b662]9 */
10
[dfed1c]11#ifndef FACTORY_HPP_
12#define FACTORY_HPP_
[48b662]13
14#include <map>
15#include <string>
16
17#include "base/object.hpp"
18
19namespace VMG
20{
21
[01be70]22class MG;
23
[48b662]24class Factory
25{
26public:
27 virtual ~Factory();
28
[dfed1c]29 void Register(Object* object); ///< Registers an object
30 template <class T> T& RegisterObjectStorage(std::string id, const T& val);
31 template <class T> T* RegisterObjectStorageArray(std::string id, const vmg_int& size);
[48b662]32
[dfed1c]33 Object* Get(std::string id); ///< Returns an object.
[48b662]34 template <class T> T& GetObjectStorageVal(std::string id);
[dfed1c]35 template <class T> T* GetObjectStorageArray(std::string id);
[48b662]36
[dfed1c]37 void Delete(std::string id); ///< Deletes an object
[48b662]38
39 void PrintAvailableObjects(); ///< Prints the name of all objects that have been registered to the factory.
40
[ac6d04]41 bool TestObject(std::string id) const; ///< Checks whether an object exists or not.
42
[48b662]43private:
[01be70]44 friend class MG;
45
46 Factory();
[48b662]47 std::map<std::string, Object*> object_map;
48};
49
50template <class T>
[dfed1c]51T& Factory::RegisterObjectStorage(std::string id, const T& val)
[48b662]52{
[dfed1c]53 Object* object = new ObjectStorage<T>(id, val);
54 return object->Cast< ObjectStorage<T> >()->Val();
55}
56
57template <class T>
58T* Factory::RegisterObjectStorageArray(std::string id, const vmg_int& size)
59{
60 Object* object = new ObjectStorageArray<T>(id, size);
61 return object->Cast< ObjectStorage<T*> >()->Val();
[48b662]62}
63
64template <class T>
65T& Factory::GetObjectStorageVal(std::string id)
66{
[dfed1c]67 return Get(id)->Cast< ObjectStorage<T> >()->Val();
68}
69
70template <class T>
71T* Factory::GetObjectStorageArray(std::string id)
72{
73 return Get(id)->Cast< ObjectStorage<T*> >()->Val();
[48b662]74}
75
76}
77
[dfed1c]78#endif /* FACTORY_HPP_ */
Note: See TracBrowser for help on using the repository browser.