Misc cleanups.
[tagua/yd.git] / src / core / repository.cpp
blob83a270dc5c9c077e1500c6c18dc7e6bb4790c608
1 /*
2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #include "repository.h"
13 Repository::Repository()
14 : m_proxy(0) { }
16 void Repository::addComponent(const QString& path, ComponentPtr component) {
17 m_components[path] = component;
20 ComponentPtr Repository::getComponent(const QString& path) const {
21 ComponentPtr res = m_components.value(path);
22 if (!res && m_proxy)
23 res = m_proxy->getComponent(path);
24 return res;
27 ComponentPtr Repository::takeComponent(const QString& path) {
28 return m_components.take(path);
31 Repository::ComponentMap Repository::listComponents(QString path) const {
32 if (!path.endsWith("/")) path += "/";
34 ComponentMap res;
35 ComponentMap::const_iterator it = m_components.lowerBound(path);
36 ComponentMap::const_iterator end = m_components.end();
38 for ( ; it != end; ++it) {
39 if (it.key().startsWith(path))
40 res[it.key().mid(path.size())] = it.value();
41 else
42 break;
45 if (m_proxy)
46 res = res.unite(m_proxy->listComponents(path));
48 return res;
51 void Repository::setProxy(Repository* proxy) {
52 m_proxy = proxy;