diff options
-rw-r--r-- | raul/RDFWorld.hpp | 2 | ||||
-rw-r--r-- | raul/Table.hpp | 22 | ||||
-rw-r--r-- | raul/TableImpl.hpp | 6 | ||||
-rw-r--r-- | src/RDFWorld.cpp | 8 | ||||
-rw-r--r-- | 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 <vector> #include <algorithm> +#include <boost/utility.hpp> +#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 <typename K, typename T> -class Table { +class Table : public boost::noncopyable { public: Table<K, T>() : _entries() {} Table<K, T>(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<K,T>& t, size_t i) : _table(t), _index(i) {} - inline const std::pair<const K, T> operator*() const { return _table._entries[_index]; } - inline const std::pair<const K, T>* operator->() const { return (std::pair<const K, T>*)&_table._entries[_index]; } + const_iterator(const Table<K,T>& t, size_t i) : _table(&t), _index(i) {} + inline const std::pair<const K, T> operator*() const { return _table->_entries[_index]; } + inline const std::pair<const K, T>* operator->() const { return (std::pair<const K, T>*)&_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<K,T>; - const Table<K,T>& _table; + const Table<K,T>* _table; size_t _index; }; struct iterator { - iterator(Table<K,T>& t, size_t i) : _table(t), _index(i) {} - inline std::pair<K, T>& operator*() const { return (std::pair<K, T>&)_table._entries[_index]; } - inline std::pair<K, T>* operator->() const { return (std::pair<K, T>*)&_table._entries[_index]; } + iterator(Table<K,T>& t, size_t i) : _table(&t), _index(i) {} + inline std::pair<K, T>& operator*() const { return (std::pair<K, T>&)_table->_entries[_index]; } + inline std::pair<K, T>* operator->() const { return (std::pair<K, T>*)&_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<K,T>; - Table<K,T>& _table; + Table<K,T>* _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<K, T> yank(iterator start, iterator end); + SharedPtr< Table<K, T> > yank(iterator start, iterator end); std::pair<iterator, bool> cram(const Table<K, T>& 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<K,T>::find_range_end(iterator start, bool (*comp)(const K&,const K&)) /** Erase and return a range of entries */ template <typename K, typename T> -Table<K, T> +SharedPtr< Table<K, T> > Table<K, T>::yank(iterator start, iterator end) { - Table<K, T> ret(end._index - start._index); + SharedPtr< Table<K, T> > ret(new Table<K, T>(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<char>::iterator quux_end = pt.find_descendants_end(quux ); assert(quux_end != quux); - Table<Path,char> yanked = pt.yank(quux, quux_end); + SharedPtr< Table<Path,char> > yanked = pt.yank(quux, quux_end); cout << "Yanked " << yank_path << endl; for (PathTable<char>::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<char>::const_iterator i = pt.begin(); i != pt.end(); ++i) |