diff options
Diffstat (limited to 'src/mongo/db/matcher/expression_array.h')
-rw-r--r-- | src/mongo/db/matcher/expression_array.h | 179 |
1 files changed, 96 insertions, 83 deletions
diff --git a/src/mongo/db/matcher/expression_array.h b/src/mongo/db/matcher/expression_array.h index 4bc14230eb9..f9bcfd53167 100644 --- a/src/mongo/db/matcher/expression_array.h +++ b/src/mongo/db/matcher/expression_array.h @@ -40,124 +40,137 @@ namespace mongo { - class ArrayMatchingMatchExpression : public MatchExpression { - public: - ArrayMatchingMatchExpression( MatchType matchType ) : MatchExpression( matchType ){} - virtual ~ArrayMatchingMatchExpression(){} +class ArrayMatchingMatchExpression : public MatchExpression { +public: + ArrayMatchingMatchExpression(MatchType matchType) : MatchExpression(matchType) {} + virtual ~ArrayMatchingMatchExpression() {} - Status initPath( StringData path ); + Status initPath(StringData path); - virtual bool matches( const MatchableDocument* doc, MatchDetails* details ) const; + virtual bool matches(const MatchableDocument* doc, MatchDetails* details) const; - /** - * @param e - has to be an array. calls matchesArray with e as an array - */ - virtual bool matchesSingleElement( const BSONElement& e ) const; + /** + * @param e - has to be an array. calls matchesArray with e as an array + */ + virtual bool matchesSingleElement(const BSONElement& e) const; - virtual bool matchesArray( const BSONObj& anArray, MatchDetails* details ) const = 0; + virtual bool matchesArray(const BSONObj& anArray, MatchDetails* details) const = 0; - bool equivalent( const MatchExpression* other ) const; + bool equivalent(const MatchExpression* other) const; - const StringData path() const { return _path; } + const StringData path() const { + return _path; + } - private: - StringData _path; - ElementPath _elementPath; - }; +private: + StringData _path; + ElementPath _elementPath; +}; - class ElemMatchObjectMatchExpression : public ArrayMatchingMatchExpression { - public: - ElemMatchObjectMatchExpression() : ArrayMatchingMatchExpression( ELEM_MATCH_OBJECT ){} - Status init( StringData path, MatchExpression* sub ); +class ElemMatchObjectMatchExpression : public ArrayMatchingMatchExpression { +public: + ElemMatchObjectMatchExpression() : ArrayMatchingMatchExpression(ELEM_MATCH_OBJECT) {} + Status init(StringData path, MatchExpression* sub); - bool matchesArray( const BSONObj& anArray, MatchDetails* details ) const; + bool matchesArray(const BSONObj& anArray, MatchDetails* details) const; - virtual ElemMatchObjectMatchExpression* shallowClone() const { - ElemMatchObjectMatchExpression* e = new ElemMatchObjectMatchExpression(); - e->init(path(), _sub->shallowClone()); - if ( getTag() ) { - e->setTag(getTag()->clone()); - } - return e; + virtual ElemMatchObjectMatchExpression* shallowClone() const { + ElemMatchObjectMatchExpression* e = new ElemMatchObjectMatchExpression(); + e->init(path(), _sub->shallowClone()); + if (getTag()) { + e->setTag(getTag()->clone()); } + return e; + } - virtual void debugString( StringBuilder& debug, int level ) const; + virtual void debugString(StringBuilder& debug, int level) const; - virtual void toBSON(BSONObjBuilder* out) const; + virtual void toBSON(BSONObjBuilder* out) const; - virtual size_t numChildren() const { return 1; } + virtual size_t numChildren() const { + return 1; + } - virtual MatchExpression* getChild( size_t i ) const { return _sub.get(); } + virtual MatchExpression* getChild(size_t i) const { + return _sub.get(); + } - private: - std::unique_ptr<MatchExpression> _sub; - }; +private: + std::unique_ptr<MatchExpression> _sub; +}; - class ElemMatchValueMatchExpression : public ArrayMatchingMatchExpression { - public: - ElemMatchValueMatchExpression() : ArrayMatchingMatchExpression( ELEM_MATCH_VALUE ){} - virtual ~ElemMatchValueMatchExpression(); +class ElemMatchValueMatchExpression : public ArrayMatchingMatchExpression { +public: + ElemMatchValueMatchExpression() : ArrayMatchingMatchExpression(ELEM_MATCH_VALUE) {} + virtual ~ElemMatchValueMatchExpression(); - Status init( StringData path ); - Status init( StringData path, MatchExpression* sub ); - void add( MatchExpression* sub ); + Status init(StringData path); + Status init(StringData path, MatchExpression* sub); + void add(MatchExpression* sub); - bool matchesArray( const BSONObj& anArray, MatchDetails* details ) const; + bool matchesArray(const BSONObj& anArray, MatchDetails* details) const; - virtual ElemMatchValueMatchExpression* shallowClone() const { - ElemMatchValueMatchExpression* e = new ElemMatchValueMatchExpression(); - e->init(path()); - for (size_t i = 0; i < _subs.size(); ++i) { - e->add(_subs[i]->shallowClone()); - } - if ( getTag() ) { - e->setTag(getTag()->clone()); - } - return e; + virtual ElemMatchValueMatchExpression* shallowClone() const { + ElemMatchValueMatchExpression* e = new ElemMatchValueMatchExpression(); + e->init(path()); + for (size_t i = 0; i < _subs.size(); ++i) { + e->add(_subs[i]->shallowClone()); } + if (getTag()) { + e->setTag(getTag()->clone()); + } + return e; + } - virtual void debugString( StringBuilder& debug, int level ) const; + virtual void debugString(StringBuilder& debug, int level) const; - virtual void toBSON(BSONObjBuilder* out) const; + virtual void toBSON(BSONObjBuilder* out) const; - virtual std::vector<MatchExpression*>* getChildVector() { return &_subs; } + virtual std::vector<MatchExpression*>* getChildVector() { + return &_subs; + } - virtual size_t numChildren() const { return _subs.size(); } + virtual size_t numChildren() const { + return _subs.size(); + } - virtual MatchExpression* getChild( size_t i ) const { return _subs[i]; } + virtual MatchExpression* getChild(size_t i) const { + return _subs[i]; + } - private: - bool _arrayElementMatchesAll( const BSONElement& e ) const; +private: + bool _arrayElementMatchesAll(const BSONElement& e) const; - std::vector<MatchExpression*> _subs; - }; + std::vector<MatchExpression*> _subs; +}; - class SizeMatchExpression : public ArrayMatchingMatchExpression { - public: - SizeMatchExpression() : ArrayMatchingMatchExpression( SIZE ){} - Status init( StringData path, int size ); +class SizeMatchExpression : public ArrayMatchingMatchExpression { +public: + SizeMatchExpression() : ArrayMatchingMatchExpression(SIZE) {} + Status init(StringData path, int size); - virtual SizeMatchExpression* shallowClone() const { - SizeMatchExpression* e = new SizeMatchExpression(); - e->init(path(), _size); - if ( getTag() ) { - e->setTag(getTag()->clone()); - } - return e; + virtual SizeMatchExpression* shallowClone() const { + SizeMatchExpression* e = new SizeMatchExpression(); + e->init(path(), _size); + if (getTag()) { + e->setTag(getTag()->clone()); } + return e; + } - virtual bool matchesArray( const BSONObj& anArray, MatchDetails* details ) const; - - virtual void debugString( StringBuilder& debug, int level ) const; + virtual bool matchesArray(const BSONObj& anArray, MatchDetails* details) const; - virtual void toBSON(BSONObjBuilder* out) const; + virtual void debugString(StringBuilder& debug, int level) const; - virtual bool equivalent( const MatchExpression* other ) const; + virtual void toBSON(BSONObjBuilder* out) const; - int getData() const { return _size; } + virtual bool equivalent(const MatchExpression* other) const; - private: - int _size; // >= 0 real, < 0, nothing will match - }; + int getData() const { + return _size; + } +private: + int _size; // >= 0 real, < 0, nothing will match +}; } |