diff options
Diffstat (limited to 'src/mongo/db/namespace.h')
| -rw-r--r-- | src/mongo/db/namespace.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/mongo/db/namespace.h b/src/mongo/db/namespace.h new file mode 100644 index 00000000000..b0907a58acc --- /dev/null +++ b/src/mongo/db/namespace.h @@ -0,0 +1,62 @@ +// namespace.h + +/** +* Copyright (C) 2008 10gen Inc. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License, version 3, +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once + +#include "mongo/pch.h" + +#include <cstring> +#include <string> + +namespace mongo { + +#pragma pack(1) + class Namespace { + public: + explicit Namespace(const char *ns) { *this = ns; } + Namespace& operator=(const char *ns); + + bool hasDollarSign() const { return strchr( buf , '$' ) > 0; } + void kill() { buf[0] = 0x7f; } + bool operator==(const char *r) const { return strcmp(buf, r) == 0; } + bool operator==(const Namespace& r) const { return strcmp(buf, r.buf) == 0; } + int hash() const; // value returned is always > 0 + + size_t size() const { return strlen( buf ); } + + string toString() const { return buf; } + operator string() const { return buf; } + + /* NamespaceDetails::Extra was added after fact to allow chaining of data blocks to support more than 10 indexes + (more than 10 IndexDetails). It's a bit hacky because of this late addition with backward + file support. */ + string extraName(int i) const; + bool isExtra() const; /* ends with $extr... -- when true an extra block not a normal NamespaceDetails block */ + + /** ( foo.bar ).getSisterNS( "blah" ) == foo.blah + perhaps this should move to the NamespaceString helper? + */ + string getSisterNS( const char * local ) const; + + enum MaxNsLenValue { MaxNsLen = 128 }; + private: + char buf[MaxNsLen]; + }; +#pragma pack() + +} // namespace mongo |
