Initial porting to the new component API.
[tagua/yd.git] / src / core / repository.h
blob3d2284adc0a3a2488742e5d2f61f2669c4b4c2ad
1 #ifndef CORE__REPOSITORY_H
2 #define CORE__REPOSITORY_H
4 #include <QMap>
5 #include <QString>
6 #include "component.h"
7 #include "export.h"
9 /**
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;
27 public:
28 Repository();
30 /**
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
33 * overwritten.
35 void addComponent(const QString& path, ComponentPtr component);
37 /**
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;
44 /**
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);
51 /**
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);
61 // if (iface)
62 // return iface;
63 // else
64 // return new typename Interface::Adaptor(iface);
65 // }
67 template <typename Interface>
68 Interface* requestInterface(Component* component) {
69 return dynamic_cast<Interface*>(component);
72 #endif // CORE__REPOSITORY_H