write.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. #pragma once
  15. #include <cstdint>
  16. #include <bsoncxx/stdx/optional.hpp>
  17. #include <mongocxx/model/delete_many.hpp>
  18. #include <mongocxx/model/delete_one.hpp>
  19. #include <mongocxx/model/insert_one.hpp>
  20. #include <mongocxx/model/replace_one.hpp>
  21. #include <mongocxx/model/update_many.hpp>
  22. #include <mongocxx/model/update_one.hpp>
  23. #include <mongocxx/write_type.hpp>
  24. #include <mongocxx/config/prelude.hpp>
  25. namespace mongocxx {
  26. MONGOCXX_INLINE_NAMESPACE_BEGIN
  27. namespace model {
  28. ///
  29. /// Models a single write operation within a mongocxx::bulk_write.
  30. ///
  31. class MONGOCXX_API write {
  32. public:
  33. ///
  34. /// Constructs a write from a model::insert_one.
  35. ///
  36. write(insert_one value);
  37. ///
  38. /// Constructs a write from a model::update_one.
  39. ///
  40. write(update_one value);
  41. ///
  42. /// Constructs a write from a model::update_many.
  43. ///
  44. write(update_many value);
  45. ///
  46. /// Constructs a write from a model::delete_one.
  47. ///
  48. write(delete_one value);
  49. ///
  50. /// Constructs a write from a model::delete_many.
  51. ///
  52. write(delete_many value);
  53. ///
  54. /// Constructs a write from a model::replace_one.
  55. ///
  56. write(replace_one value);
  57. ///
  58. /// Move constructs a write.
  59. ///
  60. write(write&& rhs) noexcept;
  61. ///
  62. /// Move assigns a write.
  63. ///
  64. write& operator=(write&& rhs) noexcept;
  65. write(const write& rhs) = delete;
  66. write& operator=(const write& rhs) = delete;
  67. ///
  68. /// Destroys a write.
  69. ///
  70. ~write();
  71. ///
  72. /// Returns the current type of this write. You must call this
  73. /// method before calling any of the get methods below.
  74. ///
  75. write_type type() const;
  76. ///
  77. /// Accesses the write as a model::insert_one. It is illegal to call
  78. /// this method if the return of type() does not indicate
  79. /// that this object currently contains the applicable type.
  80. ///
  81. const insert_one& get_insert_one() const;
  82. ///
  83. /// Accesses the write as an model::update_one. It is illegal to call
  84. /// this method if the return of type() does not indicate
  85. /// that this object currently contains the applicable type.
  86. ///
  87. const update_one& get_update_one() const;
  88. ///
  89. /// Accesses the write as an model::update_many. It is illegal to call
  90. /// this method if the return of type() does not indicate
  91. /// that this object currently contains the applicable type.
  92. ///
  93. const update_many& get_update_many() const;
  94. ///
  95. /// Accesses the write as a model::delete_one. It is illegal to call
  96. /// this method if the return of type() does not indicate
  97. /// that this object currently contains the applicable type.
  98. ///
  99. const delete_one& get_delete_one() const;
  100. ///
  101. /// Accesses the write as a model::delete_many. It is illegal to call
  102. /// this method if the return of type() does not indicate
  103. /// that this object currently contains the applicable type.
  104. ///
  105. const delete_many& get_delete_many() const;
  106. ///
  107. /// Accesses the write as a model::replace_one. It is illegal to call
  108. /// this method if the return of type() does not indicate
  109. /// that this object currently contains the applicable type.
  110. ///
  111. const replace_one& get_replace_one() const;
  112. private:
  113. MONGOCXX_PRIVATE void destroy_member() noexcept;
  114. write_type _type;
  115. union {
  116. insert_one _insert_one;
  117. update_one _update_one;
  118. update_many _update_many;
  119. delete_one _delete_one;
  120. delete_many _delete_many;
  121. replace_one _replace_one;
  122. };
  123. };
  124. } // namespace model
  125. MONGOCXX_INLINE_NAMESPACE_END
  126. } // namespace mongocxx
  127. #include <mongocxx/config/postlude.hpp>