1 #ifndef _CLASSREGISTER_H_
2 #define _CLASSREGISTER_H_
10 class TypeProxyBase
; // forward declaration
13 * Register of Oberon/BlackBox types.
14 * Each type has a registered name, which refers to the full BlackBox type name (including any modules).
15 * It also (optionally) has a supertype (also referred to by the full BlackBox type name).
18 static TypeRegister
*s_instance
;
20 std::map
<std::string
, TypeProxyBase
*> d_map
;
23 TypeRegister(const TypeRegister
&other
); // NI
24 TypeRegister
&operator=(const TypeRegister
&other
); // NI
28 * Get an instance of the type register (singleton pattern).
30 static TypeRegister
&getInstance();
33 * Register a new type.
35 void add(const std::string
&name
, TypeProxyBase
*proxy
);
40 const TypeProxyBase
*get(const std::string
&name
);
44 * Proxy to represent a BlackBox type. Has a name and optional supertype name.
45 * Can instantiate new instances of the type.
50 * Create a new TypeProxy and register it with the TypeRegister.
52 TypeProxyBase(const std::string
&name
);
54 * @return The full BlackBox type name (including modules).
56 virtual const std::string
&getName() const = 0;
58 * @return The full BlackBox type name of the supertype (if applicable, otherwise a 0-pointer).
60 virtual const std::string
*getSuper() const = 0;
62 * @return A new instance of the type, with the given ID.
64 virtual Store
*newInstance(INTEGER id
) const = 0;
68 * Proxy for a toplevel type (no supertype).
69 * T: the class to proxy for.
70 * Requires T to have a static const std::string TYPENAME.
72 template <class T
> class TopTypeProxy
: public TypeProxyBase
{
74 TopTypeProxy(): TypeProxyBase(T::TYPENAME
) {}
75 virtual const std::string
&getName() const {
78 virtual const std::string
*getSuper() const {
81 virtual Store
*newInstance(INTEGER id
) const {
87 * Proxy for a derived type (with supertype).
88 * T: the class to proxy for.
90 * Requires T, S to have a static const std::string TYPENAME.
92 template <class T
, class S
> class TypeProxy
: public TypeProxyBase
{
94 TypeProxy(): TypeProxyBase(T::TYPENAME
) {}
95 virtual const std::string
&getName() const {
98 virtual const std::string
*getSuper() const {
101 virtual Store
*newInstance(INTEGER id
) const {
107 #endif // _CLASSREGISTER_H_