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) if (copy)
retain(copy._counter); retain(copy._counter);
assert(_counter == copy._counter);
} }
/** Copy a CountedPtr to a valid base class. /** Copy a CountedPtr to a valid base class.
@ -90,12 +92,15 @@ public:
#else #else
T* const casted_y = static_cast<T* const>(y._counter->ptr); T* const casted_y = static_cast<T* const>(y._counter->ptr);
#endif #endif
if (casted_y != NULL) { if (casted_y) {
assert(casted_y == y._counter->ptr); assert(casted_y == y._counter->ptr);
//release(); // FIXME: leak? //release(); // FIXME: leak?
retain((Counter*)y._counter); 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. */ /** Assign to the value of a CountedPtr of the same type. */
@ -106,6 +111,7 @@ public:
release(); release();
retain(copy._counter); retain(copy._counter);
} }
assert(_counter == copy._counter);
return *this; return *this;
} }
@ -118,6 +124,7 @@ public:
release(); release();
retain(y._counter); retain(y._counter);
} }
assert(_counter == y._counter);
return *this; return *this;
} }
@ -179,7 +186,7 @@ private:
assert(_counter == NULL || _counter == c); assert(_counter == NULL || _counter == c);
_counter = c; _counter = c;
if (_counter) if (_counter)
++c->count; ++(c->count);
} }
/** Decrement the count, delete if we're the last reference */ /** 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()) if (i == m_objects.end())
return NULL; return NULL;
else else
//return dynamic_cast<PatchModel*>((*i).second.get());
return (CountedPtr<PatchModel>)(*i).second; // FIXME 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? // FIXME: What to do with a conflict?
if (m_objects.find(path) == m_objects.end()) { 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); add_object(p);
std::map<string, CountedPtr<ObjectModel> >::iterator pi = m_objects.find(p->path().parent()); CountedPtr<PatchModel> parent = object(p->path().parent());
if (pi != m_objects.end()) { if (parent) {
CountedPtr<PatchModel> parent = (*pi).second; p->set_parent(parent);
if (parent) { parent->add_node(p);
p->set_parent(parent); assert(p->parent() == parent);
parent->add_node(p); } else {
} else { cerr << "ERROR: new patch with no parent" << endl;
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 // FIXME: num_ports unused
add_object(n); add_object(n);
std::map<string, CountedPtr<ObjectModel> >::iterator pi = m_objects.find(n->path().parent()); //std::map<string, CountedPtr<ObjectModel> >::iterator pi = m_objects.find(n->path().parent());
if (pi != m_objects.end()) { //if (pi != m_objects.end()) {
CountedPtr<PatchModel> parent = (*pi).second; CountedPtr<PatchModel> parent = object(n->path().parent());
if (parent) { if (parent) {
n->set_parent(parent); n->set_parent(parent);
parent->add_node(n); assert(n->parent() == parent);
} else { parent->add_node(n);
cerr << "ERROR: new node with no parent" << endl; 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()) { if (pi != m_objects.end()) {
CountedPtr<NodeModel> parent = (*pi).second; CountedPtr<NodeModel> parent = (*pi).second;
p->set_parent(parent); p->set_parent(parent);
if (parent) if (parent) {
parent->add_port(p); parent->add_port(p);
else assert(p->parent() == parent);
} else {
cerr << "ERROR: new port with no parent" << endl; cerr << "ERROR: new port with no parent" << endl;
}
} }
} }
} }

View File

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

View File

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