From f7368e7850307de97b024238a4f520afe1150c8b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 26 Jul 2007 09:32:49 +0000 Subject: Add const find interface to Raul::Table, fix bugs. Use Raul::Table on Ingen client side instead of std::map for objects, plugins. Work on renaming (still broken). git-svn-id: http://svn.drobilla.net/lad/ingen@634 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/client/ObjectModel.cpp | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/libs/client/ObjectModel.cpp') diff --git a/src/libs/client/ObjectModel.cpp b/src/libs/client/ObjectModel.cpp index 699d1ce7..f1393232 100644 --- a/src/libs/client/ObjectModel.cpp +++ b/src/libs/client/ObjectModel.cpp @@ -16,6 +16,10 @@ */ #include "ObjectModel.hpp" +#include +#include + +using namespace std; namespace Ingen { namespace Client { @@ -31,6 +35,50 @@ ObjectModel::~ObjectModel() { } +SharedPtr +ObjectModel::get_child(const string& name) const +{ + assert(name.find("/") == string::npos); + Children::const_iterator i = _children.find(name); + return ((i != _children.end()) ? (*i).second : SharedPtr()); +} + +void +ObjectModel::add_child(SharedPtr o) +{ + assert(o); + assert(o->path().is_child_of(_path)); + assert(o->parent().get() == this); + +#ifndef NDEBUG + // Be sure there's no duplicates + Children::iterator existing = _children.find(o->path().name()); + assert(existing == _children.end()); +#endif + + _children.insert(make_pair(o->path().name(), o)); + new_child_sig.emit(o); +} + +bool +ObjectModel::remove_child(SharedPtr o) +{ + assert(o->path().is_child_of(_path)); + assert(o->parent().get() == this); + + Children::iterator i = _children.find(o->path().name()); + if (i != _children.end()) { + assert(i->second == o); + _children.erase(i); + removed_child_sig.emit(o); + return true; + } else { + cerr << "[ObjectModel::remove_child] " << _path + << ": failed to find child " << o->path().name() << endl; + return false; + } +} + /** Get a piece of metadata for this object. * * @return Metadata value with key @a key, empty string otherwise. -- cgit v1.2.1