MongoDB C++ Driver  mongocxx-3.4.0
index.hpp
1 // Copyright 2015 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 <chrono>
18 #include <memory>
19 
20 #include <bsoncxx/document/view.hpp>
21 #include <bsoncxx/stdx/optional.hpp>
22 #include <bsoncxx/string/view_or_value.hpp>
23 #include <mongocxx/stdx.hpp>
24 
25 #include <bsoncxx/document/value.hpp>
26 #include <bsoncxx/document/view_or_value.hpp>
27 #include <mongocxx/config/prelude.hpp>
28 
29 namespace mongocxx {
30 MONGOCXX_INLINE_NAMESPACE_BEGIN
31 
32 class collection;
33 
34 namespace options {
35 
41 class MONGOCXX_API index {
42  public:
46  class MONGOCXX_API base_storage_options {
47  public:
48  virtual ~base_storage_options();
49 
50  private:
51  friend class options::index;
52  MONGOCXX_PRIVATE virtual int type() const = 0;
53  };
54 
58  class MONGOCXX_API wiredtiger_storage_options final : public base_storage_options {
59  public:
60  ~wiredtiger_storage_options() override;
61 
68  void config_string(bsoncxx::string::view_or_value config_string);
69 
75  const stdx::optional<bsoncxx::string::view_or_value>& config_string() const;
76 
77  private:
78  friend collection;
79  MONGOCXX_PRIVATE int type() const override;
80  stdx::optional<bsoncxx::string::view_or_value> _config_string;
81  };
82 
83  index();
84 
98  index& background(bool background);
99 
105  const stdx::optional<bool>& background() const;
106 
120  index& unique(bool unique);
121 
127  const stdx::optional<bool>& unique() const;
128 
140 
146  const stdx::optional<bsoncxx::string::view_or_value>& name() const;
147 
161  index& collation(bsoncxx::document::view collation);
162 
172  const stdx::optional<bsoncxx::document::view>& collation() const;
173 
187  index& sparse(bool sparse);
188 
194  const stdx::optional<bool>& sparse() const;
195 
207  index& storage_options(std::unique_ptr<base_storage_options> storage_options);
208 
216  index& storage_options(std::unique_ptr<wiredtiger_storage_options> storage_options);
217 
231  index& expire_after(std::chrono::seconds seconds);
232 
238  const stdx::optional<std::chrono::seconds>& expire_after() const;
239 
250  index& version(std::int32_t v);
251 
257  const stdx::optional<std::int32_t>& version() const;
258 
270  index& weights(bsoncxx::document::view weights);
271 
277  const stdx::optional<bsoncxx::document::view>& weights() const;
278 
290  index& default_language(bsoncxx::string::view_or_value default_language);
291 
297  const stdx::optional<bsoncxx::string::view_or_value>& default_language() const;
298 
310  index& language_override(bsoncxx::string::view_or_value language_override);
311 
317  const stdx::optional<bsoncxx::string::view_or_value>& language_override() const;
318 
329  index& partial_filter_expression(bsoncxx::document::view partial_filter_expression);
330 
336  const stdx::optional<bsoncxx::document::view>& partial_filter_expression() const;
337 
348  index& twod_sphere_version(std::uint8_t twod_sphere_version);
349 
355  const stdx::optional<std::uint8_t>& twod_sphere_version() const;
356 
367  index& twod_bits_precision(std::uint8_t twod_bits_precision);
368 
374  const stdx::optional<std::uint8_t>& twod_bits_precision() const;
375 
386  index& twod_location_min(double twod_location_min);
387 
393  const stdx::optional<double>& twod_location_min() const;
394 
405  index& twod_location_max(double twod_location_max);
406 
412  const stdx::optional<double>& twod_location_max() const;
413 
428  index& haystack_bucket_size(double haystack_bucket_size);
429 
435  const stdx::optional<double>& haystack_bucket_size() const;
436 
445 
446  private:
447  friend collection;
448 
449  stdx::optional<bool> _background;
450  stdx::optional<bool> _unique;
451  stdx::optional<bsoncxx::string::view_or_value> _name;
452  stdx::optional<bsoncxx::document::view> _collation;
453  stdx::optional<bool> _sparse;
454  std::unique_ptr<base_storage_options> _storage_options;
455  stdx::optional<std::chrono::seconds> _expire_after;
456  stdx::optional<std::int32_t> _version;
457  stdx::optional<bsoncxx::document::view> _weights;
458  stdx::optional<bsoncxx::string::view_or_value> _default_language;
459  stdx::optional<bsoncxx::string::view_or_value> _language_override;
460  stdx::optional<bsoncxx::document::view> _partial_filter_expression;
461  stdx::optional<std::uint8_t> _twod_sphere_version;
462  stdx::optional<std::uint8_t> _twod_bits_precision;
463  stdx::optional<double> _twod_location_min;
464  stdx::optional<double> _twod_location_max;
465  stdx::optional<double> _haystack_bucket_size;
466 
467  //
468  // Return the current storage_options setting.
469  //
470  const std::unique_ptr<base_storage_options>& storage_options() const;
471 };
472 
473 } // namespace options
474 MONGOCXX_INLINE_NAMESPACE_END
475 } // namespace mongocxx
476 
477 #include <mongocxx/config/postlude.hpp>
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
Base class representing the optional storage engine options for indexes.
Definition: index.hpp:46
Class representing a view-or-value variant type for strings.
Definition: view_or_value.hpp:36
Class representing the optional arguments to a MongoDB create index operation.
Definition: index.hpp:41
Class representing the optional WiredTiger storage engine options for indexes.
Definition: index.hpp:58
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:85