Skip to content

Commit 0eddf74

Browse files
committed
working
1 parent c0d220b commit 0eddf74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2187
-1044
lines changed

TODO.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
- how do we integrate mongoc's memory management with c++'s memory management facilities
44
- header include discipline (eg. do we put package prefixes?)
55
- remove type tags on closing braces?
6+
- inlining pass for trivial methods / free functions
7+
- noexcept pass where possible
68

79
## Build
810
- find_libmongocxx cmake helper thing

src/bsoncxx/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,31 @@ configure_file (
3434
@ONLY
3535
)
3636

37-
file(GLOB bsoncxx-core_headers *.hpp)
38-
file(GLOB bsoncxx-core_sources *.cpp)
37+
file(GLOB bsoncxx-array_headers array/*.hpp)
38+
file(GLOB bsoncxx-array_sources array/*.cpp)
39+
file(GLOB bsoncxx-core_headers *.hpp types/*.hpp)
40+
file(GLOB bsoncxx-core_sources *.cpp types/*.cpp)
3941
file(GLOB bsoncxx-builder_headers builder/*.hpp)
4042
file(GLOB bsoncxx-builder_sources builder/*.cpp)
43+
file(GLOB bsoncxx-builder-stream_headers builder/stream/*.hpp)
44+
file(GLOB bsoncxx-builder-stream_sources builder/stream/*.cpp)
4145
file(GLOB bsoncxx-document_headers document/*.hpp)
4246
file(GLOB bsoncxx-document_sources document/*.cpp)
47+
file(GLOB bsoncxx-private_headers private/*.hpp)
48+
file(GLOB bsoncxx-private_sources private/*.cpp)
4349
file(GLOB bsoncxx-stdx_headers stdx/*.hpp)
4450
file(GLOB bsoncxx-stdx_sources stdx/*.cpp)
4551
# note that bson_ntop is a c-style header
4652
file(GLOB bsoncxx-util_headers util/*.hpp util/*.h)
4753
file(GLOB bsoncxx-util_sources util/*.cpp)
4854

4955
add_library(bsoncxx SHARED
56+
${bsoncxx-array_sources}
5057
${bsoncxx-core_sources}
5158
${bsoncxx-builder_sources}
59+
${bsoncxx-builder-stream_sources}
5260
${bsoncxx-document_sources}
61+
${bsoncxx-private_sources}
5362
${bsoncxx-stdx_sources}
5463
${bsoncxx-util_sources}
5564
)

src/bsoncxx/builder/impl.hpp renamed to src/bsoncxx/array/element.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,23 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#pragma once
15+
#include <cstdlib>
16+
#include <cstring>
17+
#include <stdexcept>
1618

17-
#include <bsoncxx/config/prelude.hpp>
18-
19-
#include <bsoncxx/builder/array_ctx.hpp>
20-
#include <bsoncxx/builder/value_ctx.hpp>
21-
#include <bsoncxx/builder/single_ctx.hpp>
19+
#include <bsoncxx/array/element.hpp>
2220

2321
namespace bsoncxx {
2422
BSONCXX_INLINE_NAMESPACE_BEGIN
25-
namespace builder {
23+
namespace array {
2624

27-
template <class T>
28-
array_ctx<T>::operator single_ctx() {
29-
return single_ctx(_concrete);
25+
element::element() : document::element() {
3026
}
3127

32-
template <class T>
33-
value_ctx<T>::operator single_ctx() {
34-
return single_ctx(_concrete);
28+
element::element(const std::uint8_t* raw, std::uint32_t length, std::uint32_t offset)
29+
: document::element(raw, length, offset) {
3530
}
3631

37-
} // namespace builder
32+
} // namespace document
3833
BSONCXX_INLINE_NAMESPACE_END
3934
} // namespace bsoncxx
40-
41-
#include <bsoncxx/config/postlude.hpp>

src/bsoncxx/array/element.hpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
#pragma once
16+
17+
#include <bsoncxx/config/prelude.hpp>
18+
19+
#include <cstddef>
20+
#include <cstdint>
21+
#include <iostream>
22+
#include <iterator>
23+
#include <type_traits>
24+
25+
#include <bsoncxx/document/element.hpp>
26+
27+
namespace bsoncxx {
28+
BSONCXX_INLINE_NAMESPACE_BEGIN
29+
30+
namespace array {
31+
32+
class BSONCXX_API element : private document::element {
33+
34+
public:
35+
element();
36+
37+
explicit element(const std::uint8_t* raw, std::uint32_t length, std::uint32_t offset);
38+
39+
using document::element::operator bool;
40+
41+
using document::element::type;
42+
43+
using document::element::get_double;
44+
using document::element::get_utf8;
45+
using document::element::get_document;
46+
using document::element::get_array;
47+
using document::element::get_binary;
48+
using document::element::get_undefined;
49+
using document::element::get_oid;
50+
using document::element::get_bool;
51+
using document::element::get_date;
52+
using document::element::get_null;
53+
using document::element::get_regex;
54+
using document::element::get_dbpointer;
55+
using document::element::get_code;
56+
using document::element::get_symbol;
57+
using document::element::get_codewscope;
58+
using document::element::get_int32;
59+
using document::element::get_timestamp;
60+
using document::element::get_int64;
61+
using document::element::get_minkey;
62+
using document::element::get_maxkey;
63+
64+
using document::element::get_value;
65+
66+
using document::element::raw;
67+
using document::element::length;
68+
using document::element::offset;
69+
};
70+
71+
} // namespace array
72+
73+
BSONCXX_INLINE_NAMESPACE_END
74+
} // namespace bsoncxx
75+
76+
#include <bsoncxx/config/postlude.hpp>

src/bsoncxx/array/value.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
#include <cstdlib>
16+
#include <cstring>
17+
18+
#include <bsoncxx/array/value.hpp>
19+
20+
namespace bsoncxx {
21+
BSONCXX_INLINE_NAMESPACE_BEGIN
22+
namespace array {
23+
24+
value::value(std::uint8_t* data, std::size_t length, deleter_type dtor)
25+
: _data(data, dtor), _length(length) {
26+
}
27+
28+
value::value(unique_ptr_type ptr, std::size_t length)
29+
: _data(std::move(ptr)), _length(length) {
30+
}
31+
32+
// TODO should we revisit generic new/delete
33+
value::value(array::view view)
34+
: _data(static_cast<std::uint8_t*>(operator new(static_cast<std::size_t>(view.length()))),
35+
operator delete),
36+
_length(view.length()) {
37+
std::copy(view.data(), view.data() + view.length(), _data.get());
38+
}
39+
40+
value::value(const value& rhs) : value(rhs.view()) {
41+
}
42+
43+
value& value::operator=(const value& rhs) {
44+
*this = std::move(value{rhs.view()});
45+
46+
return *this;
47+
}
48+
49+
value::unique_ptr_type value::release() {
50+
auto x = std::move(_data);
51+
52+
_data.release();
53+
54+
return std::move(x);
55+
}
56+
57+
} // namespace array
58+
BSONCXX_INLINE_NAMESPACE_END
59+
} // namespace bsoncxx

src/bsoncxx/array/value.hpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
#pragma once
16+
17+
#include <bsoncxx/config/prelude.hpp>
18+
19+
#include <cstdlib>
20+
#include <memory>
21+
22+
#include <bsoncxx/array/view.hpp>
23+
#include <bsoncxx/document/value.hpp>
24+
25+
namespace bsoncxx {
26+
BSONCXX_INLINE_NAMESPACE_BEGIN
27+
namespace array {
28+
29+
class BSONCXX_API value {
30+
31+
public:
32+
using deleter_type = void(*)(void*);
33+
using unique_ptr_type = std::unique_ptr<uint8_t, deleter_type>;
34+
35+
value(std::uint8_t* data, std::size_t length, deleter_type dtor);
36+
value(unique_ptr_type ptr, std::size_t length);
37+
explicit value(array::view view);
38+
39+
value(const value&);
40+
value& operator=(const value&);
41+
42+
value(value&&) = default;
43+
value& operator=(value&&) = default;
44+
45+
inline array::view view() const noexcept;
46+
inline operator array::view() const noexcept;
47+
48+
unique_ptr_type release();
49+
50+
private:
51+
unique_ptr_type _data;
52+
std::size_t _length;
53+
};
54+
55+
array::view value::view() const noexcept {
56+
return array::view{static_cast<uint8_t*>(_data.get()), _length};
57+
}
58+
59+
value::operator array::view() const noexcept {
60+
return view();
61+
}
62+
63+
} // namespace array
64+
BSONCXX_INLINE_NAMESPACE_END
65+
} // namespace bsoncxx
66+
67+
#include <bsoncxx/config/postlude.hpp>

0 commit comments

Comments
 (0)