diff options
-rw-r--r-- | db/index.cpp | 11 | ||||
-rw-r--r-- | db/index.h | 22 |
2 files changed, 31 insertions, 2 deletions
diff --git a/db/index.cpp b/db/index.cpp index ddd97bb91ac..038cb4f0ce8 100644 --- a/db/index.cpp +++ b/db/index.cpp @@ -27,6 +27,11 @@ namespace mongo { map<string,IndexPlugin*> * IndexPlugin::_plugins; + IndexType::IndexType( const IndexPlugin * plugin ) + : _plugin( plugin ){ + + } + IndexType::~IndexType(){ } @@ -69,6 +74,10 @@ namespace mongo { } } + const IndexSpec& IndexDetails::getSpec() const { + return NamespaceDetailsTransient::get_w( info.obj()["ns"].valuestr() ).getIndexSpec( this ); + } + /* delete this index. does NOT clean up the system catalog (system.indexes or system.namespaces) -- only NamespaceIndex. */ @@ -229,7 +238,7 @@ namespace mongo { Keys will be left empty if key not found in the object. */ void IndexDetails::getKeysFromObject( const BSONObj& obj, BSONObjSetDefaultOrder& keys) const { - NamespaceDetailsTransient::get_w( info.obj()["ns"].valuestr() ).getIndexSpec( this ).getKeys( obj, keys ); + getSpec().getKeys( obj, keys ); } void setDifference(BSONObjSetDefaultOrder &l, BSONObjSetDefaultOrder &r, vector<BSONObj*> &diff) { diff --git a/db/index.h b/db/index.h index 7708afd644c..573a9770eac 100644 --- a/db/index.h +++ b/db/index.h @@ -27,6 +27,7 @@ namespace mongo { class IndexSpec; class IndexType; // TODO: this name sucks + class IndexPlugin; /** * this represents an instance of a index plugin @@ -36,10 +37,16 @@ namespace mongo { */ class IndexType : boost::noncopyable { public: + IndexType( const IndexPlugin * plugin ); virtual ~IndexType(); + virtual void getKeys( const BSONObj &obj, BSONObjSetDefaultOrder &keys ) const = 0; virtual int compare( const IndexSpec& spec , const BSONObj& l , const BSONObj& r ) const; - + + const IndexPlugin * getPlugin() const { return _plugin; } + + protected: + const IndexPlugin * _plugin; }; /** @@ -63,6 +70,8 @@ namespace mongo { return 0; return i->second; } + + string getName() const { return _name; } private: string _name; static map<string,IndexPlugin*> * _plugins; @@ -105,7 +114,16 @@ namespace mongo { void getKeys( const BSONObj &obj, BSONObjSetDefaultOrder &keys ) const; BSONElement missingField() const { return _nullElt; } + + string getTypeName() const { + if ( _indexType.get() ) + return _indexType->getPlugin()->getName(); + return ""; + } + IndexType* getType() const { + return _indexType.get(); + } protected: void _getKeys( vector<const char*> fieldNames , vector<BSONElement> fixed , const BSONObj &obj, BSONObjSetDefaultOrder &keys ) const; @@ -226,6 +244,8 @@ namespace mongo { (system.indexes or system.namespaces) -- only NamespaceIndex. */ void kill_idx(); + + const IndexSpec& getSpec() const; operator string() const { return info.obj().toString(); |