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
{
25 typedef QMap
<QString
, ComponentPtr
> ComponentMap
;
26 ComponentMap m_components
;
31 * Add a new component to the repository at the specified path.
32 * If a component already exists at that path, it will be silently
35 void addComponent(const QString
& path
, ComponentPtr component
);
38 * Retrieve a component from a given path.
39 * @return The component at path @a path, or a null pointer if
40 * no component exists at that path.
42 ComponentPtr
getComponent(const QString
& path
) const;
45 * Remove a component from a given path. Do nothing if no
46 * component exists at that path.
47 * @return The component removed from path @a path.
49 ComponentPtr
takeComponent(const QString
& path
);
52 * Determine the list of components living inside a given namespace.
53 * Nested namespaces will be silently ignored.
55 QList
<ComponentPtr
> listComponents(const QString
& path
) const;
58 // template <typename Interface>
59 // Interface* requestInterface(Component* component) {
60 // Interface* iface = dynamic_cast<Interface*>(component);
64 // return new typename Interface::Adaptor(iface);
67 template <typename Interface
>
68 Interface
* requestInterface(Component
* component
) {
69 return dynamic_cast<Interface
*>(component
);
72 #endif // CORE__REPOSITORY_H