Address some valgrind-detected problems, flag others for later.
[tagua/yd.git] / src / core / repository.cpp
blob88b6096a572f267e6fab8e29ec5dd43b88a096ed
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 if (m_components.contains(path))
18 kError() << "NOT replacing component" << path <<
19 "in component" << component->objectName();
20 else
21 m_components[path] = component;
24 ComponentPtr Repository::getComponent(const QString& path) const {
25 ComponentPtr res = m_components.value(path);
26 if (!res && m_proxy)
27 res = m_proxy->getComponent(path);
28 return res;
31 ComponentPtr Repository::takeComponent(const QString& path) {
32 return m_components.take(path);
35 Repository::ComponentMap Repository::listComponents(QString path) const {
36 if (!path.endsWith("/")) path += "/";
38 ComponentMap res;
39 ComponentMap::const_iterator it = m_components.lowerBound(path);
40 ComponentMap::const_iterator end = m_components.end();
42 for ( ; it != end; ++it) {
43 if (it.key().startsWith(path))
44 res[it.key().mid(path.size())] = it.value();
45 else
46 break;
49 if (m_proxy)
50 res = res.unite(m_proxy->listComponents(path));
52 return res;
55 void Repository::setProxy(Repository* proxy) {
56 m_proxy = proxy;