00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #pragma once
00019
00020 #include "pch.h"
00021 #include "jsobj.h"
00022
00023 namespace mongo {
00024
00030 class Projection {
00031 public:
00032
00033 class KeyOnly {
00034 public:
00035
00036 KeyOnly() : _stringSize(0) {}
00037
00038 BSONObj hydrate( const BSONObj& key ) const;
00039
00040 void addNo() { _add( false , "" ); }
00041 void addYes( const string& name ) { _add( true , name ); }
00042
00043 private:
00044
00045 void _add( bool b , const string& name ) {
00046 _include.push_back( b );
00047 _names.push_back( name );
00048 _stringSize += name.size();
00049 }
00050
00051 vector<bool> _include;
00052 vector<string> _names;
00053
00054 int _stringSize;
00055 };
00056
00057 Projection() :
00058 _include(true) ,
00059 _special(false) ,
00060 _includeID(true) ,
00061 _skip(0) ,
00062 _limit(-1) ,
00063 _hasNonSimple(false) {
00064 }
00065
00070 void init( const BSONObj& spec );
00071
00075 BSONObj getSpec() const { return _source; }
00076
00080 BSONObj transform( const BSONObj& in ) const;
00081
00082
00086 void transform( const BSONObj& in , BSONObjBuilder& b ) const;
00087
00088
00095 KeyOnly* checkKey( const BSONObj& keyPattern ) const;
00096
00097 private:
00098
00103 void append( BSONObjBuilder& b , const BSONElement& e ) const;
00104
00105
00106 void add( const string& field, bool include );
00107 void add( const string& field, int skip, int limit );
00108 void appendArray( BSONObjBuilder& b , const BSONObj& a , bool nested=false) const;
00109
00110 bool _include;
00111 bool _special;
00112
00113
00114 typedef map<string, boost::shared_ptr<Projection> > FieldMap;
00115 FieldMap _fields;
00116 BSONObj _source;
00117 bool _includeID;
00118
00119
00120 int _skip;
00121 int _limit;
00122
00123 bool _hasNonSimple;
00124 };
00125
00126
00127 }