summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/database.h
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2015-09-18 17:04:36 -0400
committerMathias Stearn <mathias@10gen.com>2015-09-18 21:42:28 -0400
commited8216e62dafd1c3384e591b27813ca300e44e86 (patch)
tree9ce8fee20108c1daeea1f076305c9a8f553602a6 /src/mongo/db/catalog/database.h
parentc65186ed2ed3d0c9581b8e04b0cc9295947b7e6f (diff)
downloadmongo-ed8216e62dafd1c3384e591b27813ca300e44e86.tar.gz
SERVER-20507 Make Database objects iterable
Diffstat (limited to 'src/mongo/db/catalog/database.h')
-rw-r--r--src/mongo/db/catalog/database.h68
1 files changed, 60 insertions, 8 deletions
diff --git a/src/mongo/db/catalog/database.h b/src/mongo/db/catalog/database.h
index 7f07371ceff..9cb607ea4f6 100644
--- a/src/mongo/db/catalog/database.h
+++ b/src/mongo/db/catalog/database.h
@@ -49,17 +49,73 @@ class NamespaceDetails;
class OperationContext;
/**
- * Database represents a database database
- * Each database database has its own set of files -- dbname.ns, dbname.0, dbname.1, ...
- * NOT memory mapped
-*/
+ * Represents a logical database containing Collections.
+ *
+ * The semantics for a const Database are that you can mutate individual collections but not add or
+ * remove them.
+ */
class Database {
public:
+ typedef StringMap<Collection*> CollectionMap;
+
+ /**
+ * Iterating over a Database yields Collection* pointers.
+ */
+ class iterator {
+ public:
+ using iterator_category = std::forward_iterator_tag;
+ using value_type = Collection*;
+ using pointer = const value_type*;
+ using reference = const value_type&;
+ using difference_type = ptrdiff_t;
+
+ iterator() = default;
+ iterator(CollectionMap::const_iterator it) : _it(it) {}
+
+ reference operator*() const {
+ return _it->second;
+ }
+
+ pointer operator->() const {
+ return &_it->second;
+ }
+
+ bool operator==(const iterator& other) {
+ return _it == other._it;
+ }
+
+ bool operator!=(const iterator& other) {
+ return _it != other._it;
+ }
+
+ iterator& operator++() {
+ ++_it;
+ return *this;
+ }
+
+ iterator operator++(int) {
+ auto oldPosition = *this;
+ ++_it;
+ return oldPosition;
+ }
+
+ private:
+ CollectionMap::const_iterator _it;
+ };
+
Database(OperationContext* txn, StringData name, DatabaseCatalogEntry* dbEntry);
// must call close first
~Database();
+ iterator begin() const {
+ return iterator(_collections.begin());
+ }
+
+ iterator end() const {
+ return iterator(_collections.end());
+ }
+
// closes files and other cleanup see below.
void close(OperationContext* txn);
@@ -154,10 +210,6 @@ private:
int _profile; // 0=off.
- // TODO: make sure deletes go through
- // this in some ways is a dupe of _namespaceIndex
- // but it points to a much more useful data structure
- typedef StringMap<Collection*> CollectionMap;
CollectionMap _collections;
friend class Collection;