source: src/base/factory.hpp@ 66f24d

Last change on this file since 66f24d was 48b662, checked in by Olaf Lenz <olenz@…>, 14 years ago

Moved files in scafacos_fcs one level up.

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

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/**
2 * @file factory.hpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Tue Apr 5 20:40:41 2011
5 *
6 * @brief Factory class that holds commands and arbitrary objects.
7 *
8 *
9 */
10
11#ifndef COMMAND_FACTORY_HPP_
12#define COMMAND_FACTORY_HPP_
13
14#include <iostream>
15#include <map>
16#include <string>
17
18#include "base/object.hpp"
19#include "base/proxy.hpp"
20
21namespace VMG
22{
23
24class Object;
25
26class Factory
27{
28public:
29 typedef std::map<std::string, CommandProxyBase*>::iterator command_iterator;
30 typedef std::map<std::string, Command*>::iterator instance_iterator;
31 typedef std::map<std::string, Object*>::iterator object_iterator;
32
33 Factory();
34 virtual ~Factory();
35
36 void Destroy();
37
38 void RegisterCommand(CommandProxyBase* command); ///< Register a command
39 void RegisterObject(Object* object); ///< Register an object
40
41 /**
42 * Register an arbitrary object that is not derived from Object.
43 * Similar functionality can be achieved by calling
44 * "new ObjectStorage<T>(id, data);"
45 */
46 template <class T> void RegisterObjectStorage(std::string id, const T& data);
47 template <class T> T& GetObjectStorageVal(std::string id);
48
49 void DeleteCommand(std::string id); ///< Delete a command
50 void DeleteObject(std::string id); ///< Delete an object
51
52 Command* GetCommand(std::string id); ///< Returns a command.
53 Object* GetObject(std::string id); ///< Returns an object.
54
55 /**
56 * Checks for the correct number of arguments. This check is
57 * automatically performed, whenever a command is executed from
58 * a command list (if the library has not been compiled with NDEBUG).
59 */
60 bool CheckNumberOfArguments(std::string id, const int& num_arguments);
61
62 void PrintAvailableCommands(); ///< Prints the name of all commands that have been registered to the factory.
63 void PrintAvailableObjects(); ///< Prints the name of all objects that have been registered to the factory.
64
65private:
66 std::map<std::string, CommandProxyBase*> command_map;
67 std::map<std::string, Command*> command_instance_map;
68 std::map<std::string, Object*> object_map;
69};
70
71template <class T>
72void Factory::RegisterObjectStorage(std::string id, const T& data)
73{
74 new ObjectStorage<T>(id, data);
75}
76
77template <class T>
78T& Factory::GetObjectStorageVal(std::string id)
79{
80 return GetObject(id)->Cast< ObjectStorage<T> >()->Val();
81}
82
83}
84
85#endif /* COMMAND_FACTORY_HPP_ */
Note: See TracBrowser for help on using the repository browser.