sub_array.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 <bsoncxx/builder/basic/helpers.hpp>
  16. #include <bsoncxx/builder/concatenate.hpp>
  17. #include <bsoncxx/builder/core.hpp>
  18. #include <bsoncxx/config/prelude.hpp>
  19. namespace bsoncxx {
  20. BSONCXX_INLINE_NAMESPACE_BEGIN
  21. namespace builder {
  22. namespace basic {
  23. namespace impl {
  24. template <typename T>
  25. void value_append(core* core, T&& t);
  26. } // namespace impl
  27. ///
  28. /// An internal class of builder::basic.
  29. /// Users should almost always construct a builder::basic::array instead.
  30. ///
  31. class sub_array {
  32. public:
  33. ///
  34. /// Default constructor
  35. ///
  36. BSONCXX_INLINE sub_array(core* core) : _core(core) {}
  37. ///
  38. /// Appends multiple BSON values.
  39. ///
  40. template <typename Arg, typename... Args>
  41. BSONCXX_INLINE void append(Arg&& a, Args&&... args) {
  42. append_(std::forward<Arg>(a));
  43. append(std::forward<Args>(args)...);
  44. }
  45. ///
  46. /// Inductive base-case for the variadic append(...)
  47. ///
  48. BSONCXX_INLINE
  49. void append() {}
  50. private:
  51. //
  52. // Appends a BSON value.
  53. //
  54. template <typename T>
  55. BSONCXX_INLINE void append_(T&& t) {
  56. impl::value_append(_core, std::forward<T>(t));
  57. }
  58. //
  59. // Concatenates another bson array directly.
  60. //
  61. BSONCXX_INLINE
  62. void append_(concatenate_array array) {
  63. _core->concatenate(array.view());
  64. }
  65. core* _core;
  66. };
  67. } // namespace basic
  68. } // namespace builder
  69. BSONCXX_INLINE_NAMESPACE_END
  70. } // namespace bsoncxx
  71. #include <bsoncxx/config/postlude.hpp>