MongoDB C++ Driver  mongocxx-3.2.0
bucket.hpp
1 // Copyright 2017 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 #pragma once
16 
17 #include <istream>
18 #include <memory>
19 #include <ostream>
20 
21 #include <bsoncxx/document/view_or_value.hpp>
22 #include <bsoncxx/stdx/string_view.hpp>
23 #include <bsoncxx/types/value.hpp>
24 #include <mongocxx/cursor.hpp>
25 #include <mongocxx/gridfs/downloader.hpp>
26 #include <mongocxx/gridfs/uploader.hpp>
27 #include <mongocxx/options/find.hpp>
28 #include <mongocxx/options/gridfs/bucket.hpp>
29 #include <mongocxx/options/gridfs/upload.hpp>
30 #include <mongocxx/result/gridfs/upload.hpp>
31 #include <mongocxx/stdx.hpp>
32 
33 #include <mongocxx/config/prelude.hpp>
34 
35 namespace mongocxx {
36 MONGOCXX_INLINE_NAMESPACE_BEGIN
37 
38 class database;
39 
40 namespace gridfs {
41 
62 class MONGOCXX_API bucket {
63  public:
69  bucket() noexcept;
70 
74  bucket(bucket&&) noexcept;
75 
79  bucket& operator=(bucket&&) noexcept;
80 
84  bucket(const bucket&);
85 
89  bucket& operator=(const bucket&);
90 
94  ~bucket();
95 
99  explicit operator bool() const noexcept;
100 
126  uploader open_upload_stream(stdx::string_view filename,
127  const options::gridfs::upload& options = {});
128 
156  uploader open_upload_stream_with_id(bsoncxx::types::value id,
157  stdx::string_view filename,
158  const options::gridfs::upload& options = {});
159 
200  result::gridfs::upload upload_from_stream(stdx::string_view filename,
201  std::istream* source,
202  const options::gridfs::upload& options = {});
203 
244  void upload_from_stream_with_id(bsoncxx::types::value id,
245  stdx::string_view filename,
246  std::istream* source,
247  const options::gridfs::upload& options = {});
248 
264  downloader open_download_stream(bsoncxx::types::value id);
265 
286  void download_to_stream(bsoncxx::types::value id, std::ostream* destination);
287 
299  void delete_file(bsoncxx::types::value id);
300 
319  cursor find(bsoncxx::document::view_or_value filter, const options::find& options = {});
320 
327  stdx::string_view bucket_name() const;
328 
329  private:
330  friend class mongocxx::database;
331 
332  // Constructs a new GridFS bucket. Throws if options are invalid.
333  MONGOCXX_PRIVATE bucket(const database& db, const options::gridfs::bucket& options);
334 
335  MONGOCXX_PRIVATE void create_indexes_if_nonexistent();
336 
337  class MONGOCXX_PRIVATE impl;
338 
339  MONGOCXX_PRIVATE impl& _get_impl();
340  MONGOCXX_PRIVATE const impl& _get_impl() const;
341 
342  std::unique_ptr<impl> _impl;
343 };
344 
345 } // namespace gridfs
346 MONGOCXX_INLINE_NAMESPACE_END
347 } // namespace mongocxx
348 
349 #include <mongocxx/config/postlude.hpp>
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:22
Class used to upload a GridFS file.
Definition: uploader.hpp:39
Class representing the optional arguments to a MongoDB query.
Definition: find.hpp:36
Class representing a pointer to the result set of a query on a MongoDB server.
Definition: cursor.hpp:36
Class used to download a GridFS file.
Definition: downloader.hpp:37
Class representing a GridFS bucket.
Definition: bucket.hpp:62
Class representing the result of a GridFS upload operation.
Definition: upload.hpp:28
Class representing a MongoDB database.
Definition: database.hpp:46
Class representing the optional arguments to a MongoDB GridFS bucket creation operation.
Definition: bucket.hpp:35
Class representing the optional arguments to a MongoDB GridFS upload operation.
Definition: upload.hpp:31
A variant that can contain any BSON type.
Definition: value.hpp:37