diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/matcher/path.h | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/matcher/path.h')
-rw-r--r-- | src/mongo/db/matcher/path.h | 216 |
1 files changed, 118 insertions, 98 deletions
diff --git a/src/mongo/db/matcher/path.h b/src/mongo/db/matcher/path.h index 11fec9ff673..471a1af47e6 100644 --- a/src/mongo/db/matcher/path.h +++ b/src/mongo/db/matcher/path.h @@ -38,132 +38,152 @@ namespace mongo { - class ElementPath { +class ElementPath { +public: + Status init(StringData path); + + void setTraverseNonleafArrays(bool b) { + _shouldTraverseNonleafArrays = b; + } + void setTraverseLeafArray(bool b) { + _shouldTraverseLeafArray = b; + } + + const FieldRef& fieldRef() const { + return _fieldRef; + } + bool shouldTraverseNonleafArrays() const { + return _shouldTraverseNonleafArrays; + } + bool shouldTraverseLeafArray() const { + return _shouldTraverseLeafArray; + } + +private: + FieldRef _fieldRef; + bool _shouldTraverseNonleafArrays; + bool _shouldTraverseLeafArray; +}; + +class ElementIterator { +public: + class Context { public: - Status init( StringData path ); + void reset(); - void setTraverseNonleafArrays( bool b ) { _shouldTraverseNonleafArrays = b; } - void setTraverseLeafArray( bool b ) { _shouldTraverseLeafArray = b; } + void reset(BSONElement element, BSONElement arrayOffset, bool outerArray); - const FieldRef& fieldRef() const { return _fieldRef; } - bool shouldTraverseNonleafArrays() const { return _shouldTraverseNonleafArrays; } - bool shouldTraverseLeafArray() const { return _shouldTraverseLeafArray; } + void setArrayOffset(BSONElement e) { + _arrayOffset = e; + } + + BSONElement element() const { + return _element; + } + BSONElement arrayOffset() const { + return _arrayOffset; + } + bool outerArray() const { + return _outerArray; + } private: - FieldRef _fieldRef; - bool _shouldTraverseNonleafArrays; - bool _shouldTraverseLeafArray; + BSONElement _element; + BSONElement _arrayOffset; + bool _outerArray; }; - class ElementIterator { - public: - class Context { - public: + virtual ~ElementIterator(); - void reset(); + virtual bool more() = 0; + virtual Context next() = 0; +}; - void reset( BSONElement element, BSONElement arrayOffset, bool outerArray ); +// --------------------------------------------------------------- - void setArrayOffset( BSONElement e ) { _arrayOffset = e; } +class SingleElementElementIterator : public ElementIterator { +public: + explicit SingleElementElementIterator(BSONElement e) : _seen(false) { + _element.reset(e, BSONElement(), false); + } + virtual ~SingleElementElementIterator() {} - BSONElement element() const { return _element; } - BSONElement arrayOffset() const { return _arrayOffset; } - bool outerArray() const { return _outerArray; } + virtual bool more() { + return !_seen; + } + virtual Context next() { + _seen = true; + return _element; + } - private: - BSONElement _element; - BSONElement _arrayOffset; - bool _outerArray; - }; +private: + bool _seen; + ElementIterator::Context _element; +}; - virtual ~ElementIterator(); +class SimpleArrayElementIterator : public ElementIterator { +public: + SimpleArrayElementIterator(const BSONElement& theArray, bool returnArrayLast); - virtual bool more() = 0; - virtual Context next() = 0; + virtual bool more(); + virtual Context next(); - }; +private: + BSONElement _theArray; + bool _returnArrayLast; + BSONObjIterator _iterator; +}; - // --------------------------------------------------------------- +class BSONElementIterator : public ElementIterator { +public: + BSONElementIterator(); + BSONElementIterator(const ElementPath* path, const BSONObj& context); - class SingleElementElementIterator : public ElementIterator { - public: - explicit SingleElementElementIterator( BSONElement e ) - : _seen( false ) { - _element.reset( e, BSONElement(), false ); - } - virtual ~SingleElementElementIterator(){} + virtual ~BSONElementIterator(); - virtual bool more() { return !_seen; } - virtual Context next() { _seen = true; return _element; } + void reset(const ElementPath* path, const BSONObj& context); - private: - bool _seen; - ElementIterator::Context _element; - }; + bool more(); + Context next(); - class SimpleArrayElementIterator : public ElementIterator { - public: - SimpleArrayElementIterator( const BSONElement& theArray, bool returnArrayLast ); - - virtual bool more(); - virtual Context next(); - - private: - BSONElement _theArray; - bool _returnArrayLast; - BSONObjIterator _iterator; - }; +private: + /** + * Helper for more(). Recurs on _subCursor (which traverses the remainder of a path through + * subdocuments of an array). + */ + bool subCursorHasMore(); - class BSONElementIterator : public ElementIterator { - public: - BSONElementIterator(); - BSONElementIterator( const ElementPath* path, const BSONObj& context ); + const ElementPath* _path; + BSONObj _context; - virtual ~BSONElementIterator(); + enum State { BEGIN, IN_ARRAY, DONE } _state; + Context _next; - void reset( const ElementPath* path, const BSONObj& context ); + struct ArrayIterationState { + void reset(const FieldRef& ref, int start); + void startIterator(BSONElement theArray); bool more(); - Context next(); - - private: - /** - * Helper for more(). Recurs on _subCursor (which traverses the remainder of a path through - * subdocuments of an array). - */ - bool subCursorHasMore(); - - const ElementPath* _path; - BSONObj _context; - - enum State { BEGIN, IN_ARRAY, DONE } _state; - Context _next; - - struct ArrayIterationState { + BSONElement next(); - void reset( const FieldRef& ref, int start ); - void startIterator( BSONElement theArray ); - - bool more(); - BSONElement next(); - - bool isArrayOffsetMatch( StringData fieldName ) const; - bool nextEntireRest() const { return nextPieceOfPath.size() == restOfPath.size(); } - - std::string restOfPath; - bool hasMore; - StringData nextPieceOfPath; - bool nextPieceOfPathIsNumber; - - BSONElement _theArray; - BSONElement _current; - std::unique_ptr<BSONObjIterator> _iterator; - }; + bool isArrayOffsetMatch(StringData fieldName) const; + bool nextEntireRest() const { + return nextPieceOfPath.size() == restOfPath.size(); + } - ArrayIterationState _arrayIterationState; + std::string restOfPath; + bool hasMore; + StringData nextPieceOfPath; + bool nextPieceOfPathIsNumber; - std::unique_ptr<ElementIterator> _subCursor; - std::unique_ptr<ElementPath> _subCursorPath; + BSONElement _theArray; + BSONElement _current; + std::unique_ptr<BSONObjIterator> _iterator; }; + ArrayIterationState _arrayIterationState; + + std::unique_ptr<ElementIterator> _subCursor; + std::unique_ptr<ElementPath> _subCursorPath; +}; } |