1 #ifndef CORE__REPOSITORY_H
2 #define CORE__REPOSITORY_H
10 * @brief A hierarchical collection of component defining a variant.
12 * Components of a variant are maintained in a hierarchical structure
13 * called repository. All components have a path that uniquely identifies
14 * them inside a given variant.
16 * Non-leaf nodes are not actual components, and are called namespaces.
17 * Namespaces can be nested.
19 * Since the number of components inside a repository is not likely to
20 * grow over a dozen or so, there is not practical need for this structure
21 * to reflect its hierarchical representation, so we simply maintain all
22 * components inside a path -> component association.
24 class TAGUA_EXPORT Repository
{
26 typedef QMap
<QString
, ComponentPtr
> ComponentMap
;
28 ComponentMap m_components
;
34 * Add a new component to the repository at the specified path.
35 * If a component already exists at that path, it will be silently
38 void addComponent(const QString
& path
, ComponentPtr component
);
41 * Retrieve a component from a given path.
42 * @return The component at path @a path, or a null pointer if
43 * no component exists at that path.
45 ComponentPtr
getComponent(const QString
& path
) const;
48 * Remove a component from a given path. Do nothing if no
49 * component exists at that path.
50 * @return The component removed from path @a path.
52 ComponentPtr
takeComponent(const QString
& path
);
55 * Determine the list of components living inside a given namespace.
56 * Nested namespaces will be silently ignored.
58 ComponentMap
listComponents(QString path
) const;
61 * Add a proxy repository, that will be queried when a component
64 void setProxy(Repository
* proxy
);
67 // template <typename Interface>
68 // Interface* requestInterface(Component* component) {
69 // Interface* iface = dynamic_cast<Interface*>(component);
73 // return new typename Interface::Adaptor(iface);
76 template <typename Interface
>
77 Interface
* requestInterface(Component
* component
) {
78 return dynamic_cast<Interface
*>(component
);
81 #endif // CORE__REPOSITORY_H