More thorough assertion checking in CountedPtr;

Adding plugins to subpatches working.


git-svn-id: http://svn.drobilla.net/lad@46 a436a847-0d15-0410-975c-d299462d15a1
This commit is contained in:
dave 2006-06-16 23:17:46 +00:00
parent 3984a63094
commit 494ef337cf
4 changed files with 37 additions and 27 deletions

View File

@ -73,6 +73,8 @@ public:
if (copy)
retain(copy._counter);
assert(_counter == copy._counter);
}
/** Copy a CountedPtr to a valid base class.
@ -90,12 +92,15 @@ public:
#else
T* const casted_y = static_cast<T* const>(y._counter->ptr);
#endif
if (casted_y != NULL) {
if (casted_y) {
assert(casted_y == y._counter->ptr);
//release(); // FIXME: leak?
retain((Counter*)y._counter);
assert(_counter == (Counter*)y._counter);
}
}
assert(_counter == NULL || _counter == (Counter*)y._counter);
}
/** Assign to the value of a CountedPtr of the same type. */
@ -106,6 +111,7 @@ public:
release();
retain(copy._counter);
}
assert(_counter == copy._counter);
return *this;
}
@ -118,6 +124,7 @@ public:
release();
retain(y._counter);
}
assert(_counter == y._counter);
return *this;
}
@ -179,7 +186,7 @@ private:
assert(_counter == NULL || _counter == c);
_counter = c;
if (_counter)
++c->count;
++(c->count);
}
/** Decrement the count, delete if we're the last reference */

View File

@ -101,7 +101,6 @@ Store::patch(const string& path)
if (i == m_objects.end())
return NULL;
else
//return dynamic_cast<PatchModel*>((*i).second.get());
return (CountedPtr<PatchModel>)(*i).second; // FIXME
}
@ -207,18 +206,16 @@ Store::new_patch_event(const string& path, uint32_t poly)
// FIXME: What to do with a conflict?
if (m_objects.find(path) == m_objects.end()) {
PatchModel* const p = new PatchModel(path, poly);
CountedPtr<PatchModel> p(new PatchModel(path, poly));
add_object(p);
std::map<string, CountedPtr<ObjectModel> >::iterator pi = m_objects.find(p->path().parent());
if (pi != m_objects.end()) {
CountedPtr<PatchModel> parent = (*pi).second;
if (parent) {
p->set_parent(parent);
parent->add_node(p);
} else {
cerr << "ERROR: new patch with no parent" << endl;
}
CountedPtr<PatchModel> parent = object(p->path().parent());
if (parent) {
p->set_parent(parent);
parent->add_node(p);
assert(p->parent() == parent);
} else {
cerr << "ERROR: new patch with no parent" << endl;
}
}
}
@ -239,15 +236,16 @@ Store::new_node_event(const string& plugin_type, const string& plugin_uri, const
// FIXME: num_ports unused
add_object(n);
std::map<string, CountedPtr<ObjectModel> >::iterator pi = m_objects.find(n->path().parent());
if (pi != m_objects.end()) {
CountedPtr<PatchModel> parent = (*pi).second;
if (parent) {
n->set_parent(parent);
parent->add_node(n);
} else {
cerr << "ERROR: new node with no parent" << endl;
}
//std::map<string, CountedPtr<ObjectModel> >::iterator pi = m_objects.find(n->path().parent());
//if (pi != m_objects.end()) {
CountedPtr<PatchModel> parent = object(n->path().parent());
if (parent) {
n->set_parent(parent);
assert(n->parent() == parent);
parent->add_node(n);
assert(n->parent() == parent);
} else {
cerr << "ERROR: new node with no parent" << endl;
}
}
}
@ -289,10 +287,12 @@ Store::new_port_event(const string& path, const string& type, bool is_output)
if (pi != m_objects.end()) {
CountedPtr<NodeModel> parent = (*pi).second;
p->set_parent(parent);
if (parent)
if (parent) {
parent->add_port(p);
else
assert(p->parent() == parent);
} else {
cerr << "ERROR: new port with no parent" << endl;
}
}
}
}

View File

@ -21,6 +21,7 @@
#include <string>
#include <map>
#include "util/CountedPtr.h"
#include <sigc++/sigc++.h>
using std::string; using std::map;
namespace LibOmClient {
@ -36,7 +37,7 @@ class PortModel;
*
* \ingroup OmGtk
*/
class Store {
class Store : public sigc::trackable { // FIXME: is trackable necessary?
public:
CountedPtr<PluginModel> plugin(const string& uri);
CountedPtr<ObjectModel> object(const string& path);
@ -46,7 +47,6 @@ public:
size_t num_objects() { return m_objects.size(); }
const map<string, CountedPtr<PluginModel> >& plugins() const { return m_plugins; }
static void instantiate(SigClientInterface& emitter)

View File

@ -63,6 +63,7 @@ PatchController::PatchController(CountedPtr<PatchModel> model)
{
assert(model->path().length() > 0);
assert(model->controller() == this); // NodeController() does this
assert(m_patch_model == model);
/* FIXME if (model->path() != "/") {
PatchController* parent = Store::instance().patch(model->path().parent());
@ -412,8 +413,8 @@ void
PatchController::add_node(CountedPtr<NodeModel> object)
{
assert(object);
assert(object->parent() == m_patch_model);
assert(object->path().parent() == m_patch_model->path());
assert(object->parent() == m_patch_model);
/*if (patch_model()->get_node(nm->name()) != NULL) {
cerr << "Ignoring existing\n";
@ -423,6 +424,7 @@ PatchController::add_node(CountedPtr<NodeModel> object)
CountedPtr<NodeModel> node(object);
assert(node == object);
if (node) {
assert(node->parent() == m_patch_model);
@ -430,6 +432,7 @@ PatchController::add_node(CountedPtr<NodeModel> object)
CountedPtr<PatchModel> patch(node);
if (patch) {
assert(patch == node == object);
assert(patch->parent() == m_patch_model);
nc = new PatchController(patch);
} else {