From d1e3c9f3e084b5bfd48949ab9421ac86c8aa0fc9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 10 Oct 2007 05:45:04 +0000 Subject: Fix recursive patch problems (all objects recursively appearing as direct child of root). Use slightly more human friendly names for blank nodes in patch files. Fix memory management semantics of engine side objects (fix crash on subpatch delete). Make Raul::Table a boost::noncopyable; related changes trickled down from that. git-svn-id: http://svn.drobilla.net/lad/raul@865 a436a847-0d15-0410-975c-d299462d15a1 --- raul/RDFWorld.hpp | 2 +- raul/Table.hpp | 22 ++++++++++++---------- raul/TableImpl.hpp | 6 +++--- src/RDFWorld.cpp | 8 ++++++-- tests/table_test.cpp | 4 ++-- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/raul/RDFWorld.hpp b/raul/RDFWorld.hpp index 45b30f6..baad711 100644 --- a/raul/RDFWorld.hpp +++ b/raul/RDFWorld.hpp @@ -35,7 +35,7 @@ public: World(); ~World(); - Node blank_id(); + Node blank_id(const std::string base_name=""); void add_prefix(const std::string& prefix, const std::string& uri); std::string expand_uri(const std::string& uri) const; diff --git a/raul/Table.hpp b/raul/Table.hpp index a7f7c39..40386e5 100644 --- a/raul/Table.hpp +++ b/raul/Table.hpp @@ -20,6 +20,8 @@ #include #include +#include +#include "SharedPtr.hpp" //#define TABLE_SORT_DEBUG @@ -33,7 +35,7 @@ namespace Raul { * data being in a single chunk of memory, cache optimized, etc. */ template -class Table { +class Table : public boost::noncopyable { public: Table() : _entries() {} Table(size_t capacity) : _entries(capacity) {} @@ -43,9 +45,9 @@ public: void reserve(size_t n) { _entries.reserve(n); } struct const_iterator { - const_iterator(const Table& t, size_t i) : _table(t), _index(i) {} - inline const std::pair operator*() const { return _table._entries[_index]; } - inline const std::pair* operator->() const { return (std::pair*)&_table._entries[_index]; } + const_iterator(const Table& t, size_t i) : _table(&t), _index(i) {} + inline const std::pair operator*() const { return _table->_entries[_index]; } + inline const std::pair* operator->() const { return (std::pair*)&_table->_entries[_index]; } inline const_iterator& operator++() { ++_index; return *this; } inline const_iterator& operator--() { --_index; return *this; } inline bool operator==(const const_iterator& i) const { return _index == i._index; } @@ -53,14 +55,14 @@ public: void operator=(const const_iterator& i) { _table = i._table; _index = i._index; } private: friend class Table; - const Table& _table; + const Table* _table; size_t _index; }; struct iterator { - iterator(Table& t, size_t i) : _table(t), _index(i) {} - inline std::pair& operator*() const { return (std::pair&)_table._entries[_index]; } - inline std::pair* operator->() const { return (std::pair*)&_table._entries[_index]; } + iterator(Table& t, size_t i) : _table(&t), _index(i) {} + inline std::pair& operator*() const { return (std::pair&)_table->_entries[_index]; } + inline std::pair* operator->() const { return (std::pair*)&_table->_entries[_index]; } inline iterator& operator++() { ++_index; return *this; } inline iterator& operator--() { --_index; return *this; } inline bool operator==(const iterator& i) const { return _index == i._index; } @@ -69,7 +71,7 @@ public: iterator& operator=(const iterator& i) { _table = i._table; _index = i._index; return *this; } private: friend class Table; - Table& _table; + Table* _table; size_t _index; }; @@ -82,7 +84,7 @@ public: void erase(iterator start, iterator end); void erase_by_index(size_t start, size_t end); - Table yank(iterator start, iterator end); + SharedPtr< Table > yank(iterator start, iterator end); std::pair cram(const Table& range); diff --git a/raul/TableImpl.hpp b/raul/TableImpl.hpp index 4ccf7f3..4d6be6d 100644 --- a/raul/TableImpl.hpp +++ b/raul/TableImpl.hpp @@ -198,12 +198,12 @@ Table::find_range_end(iterator start, bool (*comp)(const K&,const K&)) /** Erase and return a range of entries */ template -Table +SharedPtr< Table > Table::yank(iterator start, iterator end) { - Table ret(end._index - start._index); + SharedPtr< Table > ret(new Table(end._index - start._index)); for (size_t i=start._index; i < end._index; ++i) - ret._entries.at(i - start._index) = _entries[i]; + ret->_entries.at(i - start._index) = _entries[i]; erase(start, end); return ret; } diff --git a/src/RDFWorld.cpp b/src/RDFWorld.cpp index 71a231c..30db439 100644 --- a/src/RDFWorld.cpp +++ b/src/RDFWorld.cpp @@ -83,10 +83,14 @@ World::qualify(const string& uri) const Node -World::blank_id() +World::blank_id(const string base_name) { std::ostringstream ss; - ss << "n" << _next_blank_id++; + ss << "b" << _next_blank_id++ << "_"; + + if (base_name != "") + ss << base_name; + Node result = Node(*this, Node::BLANK, ss.str()); assert(result.to_string() == ss.str()); return result; diff --git a/tests/table_test.cpp b/tests/table_test.cpp index d411d12..f0d1883 100644 --- a/tests/table_test.cpp +++ b/tests/table_test.cpp @@ -142,14 +142,14 @@ main(int argc, char** argv) PathTable::iterator quux_end = pt.find_descendants_end(quux ); assert(quux_end != quux); - Table yanked = pt.yank(quux, quux_end); + SharedPtr< Table > yanked = pt.yank(quux, quux_end); cout << "Yanked " << yank_path << endl; for (PathTable::const_iterator i = pt.begin(); i != pt.end(); ++i) cout << i->first << " "; cout << endl; - pt.cram(yanked); + pt.cram(*yanked.get()); cout << "Crammed " << yank_path << endl; for (PathTable::const_iterator i = pt.begin(); i != pt.end(); ++i) -- cgit v1.2.1