MongoDB C++ Driver  legacy-1.1.2
write_operation.h
1 /* Copyright 2014 MongoDB Inc.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <string>
19 #include <vector>
20 
21 #include "mongo/bson/bsonobjbuilder.h"
22 #include "mongo/util/net/operation.h"
23 
24 namespace mongo {
25 
32 public:
33  virtual ~WriteOperation() {}
34 
39  virtual WriteOpType operationType() const = 0;
40 
44  virtual const char* batchName() const = 0;
45 
50  virtual int incrementalSize() const = 0;
51 
62  virtual void startRequest(const std::string& ns, bool ordered, BufBuilder* builder) const = 0;
63 
75  virtual void appendSelfToRequest(BufBuilder* builder) const = 0;
76 
85  virtual void startCommand(const std::string& ns, BSONObjBuilder* command) const = 0;
86 
97  virtual void appendSelfToCommand(BSONArrayBuilder* batch) const = 0;
98 
102  virtual void appendSelfToBSONObj(BSONObjBuilder* obj) const = 0;
103 
107  virtual void setBulkIndex(size_t index) = 0;
108 
112  virtual size_t getBulkIndex() const = 0;
113 };
114 
115 } // namespace mongo
Represents a single server side write operation and encapsulates the process for encoding the operati...
Definition: write_operation.h:31
virtual int incrementalSize() const =0
Returns the incremental size (in bytes) required to add this write operation to a batch...
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
virtual void startCommand(const std::string &ns, BSONObjBuilder *command) const =0
Appends the preamble for a write command into the supplied BSONObjBuilder.
virtual void startRequest(const std::string &ns, bool ordered, BufBuilder *builder) const =0
Appends the preamble for a wire protocol message into the supplied BufBuilder.
virtual void setBulkIndex(size_t index)=0
Sets the index of this WriteOperation in the context of a larger bulk operation.
Utility for creating a BSONObj.
Definition: bsonobjbuilder.h:53
virtual void appendSelfToCommand(BSONArrayBuilder *batch) const =0
Appends a single document that describes the write operation represented by an instance of this class...
virtual void appendSelfToRequest(BufBuilder *builder) const =0
Appends a document (or documents in the case of update) which describe the write operation represente...
virtual const char * batchName() const =0
Returns the name for a batch of this type of write operation.
Definition: bsonobjbuilder.h:765
virtual void appendSelfToBSONObj(BSONObjBuilder *obj) const =0
Appends the data represented by an instance of this class to a BSONObjBuilder.
virtual size_t getBulkIndex() const =0
The index of this WriteOperation in the context of a larger bulk operation.
virtual WriteOpType operationType() const =0
Returns the MongoDB wire protocol operation type represented by an instance of this particular write ...