From 0f5a2bafb9f1c3f64256e1899857b2f5cb3d8982 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 18 Dec 2014 07:53:39 +0000 Subject: Work towards engine/GUI separation. git-svn-id: http://svn.drobilla.net/lad/trunk/machina@5495 a436a847-0d15-0410-975c-d299462d15a1 --- src/client/ClientModel.cpp | 34 ++++++++++++++++++++++++++++++---- src/client/ClientModel.hpp | 16 +++++++++++----- src/client/ClientObject.cpp | 5 +++-- src/client/ClientObject.hpp | 4 ++-- 4 files changed, 46 insertions(+), 13 deletions(-) (limited to 'src/client') diff --git a/src/client/ClientModel.cpp b/src/client/ClientModel.cpp index 17054d4..3a8770f 100644 --- a/src/client/ClientModel.cpp +++ b/src/client/ClientModel.cpp @@ -1,6 +1,6 @@ /* This file is part of Machina. - Copyright 2007-2013 David Robillard + Copyright 2007-2014 David Robillard Machina is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -31,13 +31,31 @@ ClientModel::find(uint64_t id) } } +SPtr +ClientModel::find(uint64_t id) const +{ + SPtr key(new ClientObjectKey(id)); + Objects::const_iterator i = _objects.find(key); + if (i != _objects.end()) { + return *i; + } else { + return SPtr(); + } +} + void -ClientModel::new_object(SPtr object) +ClientModel::new_object(uint64_t id, const Properties& properties) { - Objects::iterator i = _objects.find(object); + SPtr key(new ClientObjectKey(id)); + Objects::iterator i = _objects.find(key); if (i == _objects.end()) { + SPtr object(new ClientObject(id, properties)); _objects.insert(object); signal_new_object.emit(object); + } else { + for (const auto& p : properties) { + (*i)->set(p.first, p.second); + } } } @@ -56,7 +74,7 @@ ClientModel::erase_object(uint64_t id) } void -ClientModel::property(uint64_t id, URIInt key, const Atom& value) +ClientModel::set(uint64_t id, URIInt key, const Atom& value) { SPtr object = find(id); if (object) { @@ -64,5 +82,13 @@ ClientModel::property(uint64_t id, URIInt key, const Atom& value) } } +const Atom& +ClientModel::get(uint64_t id, URIInt key) const +{ + static const Atom null_atom; + SPtr object = find(id); + return object ? object->get(key) : null_atom; +} + } } diff --git a/src/client/ClientModel.hpp b/src/client/ClientModel.hpp index 6840c11..e65fb93 100644 --- a/src/client/ClientModel.hpp +++ b/src/client/ClientModel.hpp @@ -1,6 +1,6 @@ /* This file is part of Machina. - Copyright 2007-2013 David Robillard + Copyright 2007-2014 David Robillard Machina is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -21,6 +21,8 @@ #include +#include "machina/Model.hpp" + #include "ClientObject.hpp" namespace Raul { @@ -30,14 +32,18 @@ class Atom; namespace machina { namespace client { -class ClientModel +class ClientModel : public Model { public: - void new_object(SPtr object); + void new_object(uint64_t id, const Properties& properties); + void erase_object(uint64_t id); - void property(uint64_t id, URIInt key, const Atom& value); - SPtr find(uint64_t id); + SPtr find(uint64_t id); + SPtr find(uint64_t id) const; + + void set(uint64_t id, URIInt key, const Atom& value); + const Atom& get(uint64_t id, URIInt key) const; sigc::signal< void, SPtr > signal_new_object; sigc::signal< void, SPtr > signal_erase_object; diff --git a/src/client/ClientObject.cpp b/src/client/ClientObject.cpp index 9481d10..20b50a2 100644 --- a/src/client/ClientObject.cpp +++ b/src/client/ClientObject.cpp @@ -1,6 +1,6 @@ /* This file is part of Machina. - Copyright 2007-2013 David Robillard + Copyright 2007-2014 David Robillard Machina is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -21,9 +21,10 @@ namespace machina { namespace client { -ClientObject::ClientObject(uint64_t id) +ClientObject::ClientObject(uint64_t id, const Properties& properties) : _id(id) , _view(NULL) + , _properties(properties) {} ClientObject::ClientObject(const ClientObject& copy, uint64_t id) diff --git a/src/client/ClientObject.hpp b/src/client/ClientObject.hpp index cf00a2b..6520b11 100644 --- a/src/client/ClientObject.hpp +++ b/src/client/ClientObject.hpp @@ -1,6 +1,6 @@ /* This file is part of Machina. - Copyright 2007-2013 David Robillard + Copyright 2007-2014 David Robillard Machina is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -30,7 +30,7 @@ namespace client { class ClientObject { public: - explicit ClientObject(uint64_t id); + explicit ClientObject(uint64_t id, const Properties& properties={}); ClientObject(const ClientObject& copy, uint64_t id); inline uint64_t id() const { return _id; } -- cgit v1.2.1