Skip to content

Commit

Permalink
Merge branch '3.1-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xdg committed Nov 29, 2016
2 parents 4506b41 + 22f6034 commit 0a61fae
Show file tree
Hide file tree
Showing 137 changed files with 5,773 additions and 951 deletions.
33 changes: 16 additions & 17 deletions .mci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ tasks:
commands:
- func: "install_c_driver"
vars:
MONGOC_VERSION: 1.4.2
MONGOC_VERSION: 1.5.0
- func: "compile"
- func: "test"

Expand Down Expand Up @@ -327,22 +327,21 @@ buildvariants:
- name: compile_and_test_with_mongoc_current
- name: compile_and_test_with_mongoc_master

# Doesn't have cmake BUILD-2154
# - name: ubuntu1604-zseries
# display_name: "s390x Ubuntu 16.04"
# batchtime: 1440 # 1 day
# expansions:
# build_type: "Release"
# source: *ubuntu_s390x_source
# tar_options: *linux_tar_options
# compile_concurrency: *linux_compile_concurrency
# cdriver_configure_flags: *linux_cdriver_configure_flags
# cmake_path: *ubuntu_zap_cmake_path
# run_on:
# - ubuntu1604-zseries-small
# tasks:
# - name: compile_and_test_with_mongoc_current
# - name: compile_and_test_with_mongoc_master
- name: ubuntu1604-zseries
display_name: "s390x Ubuntu 16.04"
batchtime: 1440 # 1 day
expansions:
build_type: "Release"
source: *ubuntu_s390x_source
tar_options: *linux_tar_options
compile_concurrency: *linux_compile_concurrency
cdriver_configure_flags: *linux_cdriver_configure_flags
cmake_path: *ubuntu_zap_cmake_path
run_on:
- ubuntu1604-zseries-small
tasks:
- name: compile_and_test_with_mongoc_current
- name: compile_and_test_with_mongoc_master

- name: power8-ubuntu1604
display_name: "ppc64le Ubuntu 16.04"
Expand Down
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ before_install:
- sudo apt-get update -qq

# Mongo C Driver
# TODO switch master (branch for current 1.3 dev) to r1.3 when released
- git clone -b '1.3.4' --single-branch https://github.com/mongodb/mongo-c-driver.git
- git clone https://github.com/mongodb/mongo-c-driver.git

install:
# GCC
Expand All @@ -59,7 +58,14 @@ install:
- sudo apt-get install cmake

# Install Mongo C Driver
- pushd mongo-c-driver; ./autogen.sh --enable-tests=no --enable-examples=no --with-libbson=bundled; make; sudo make install; popd;
- pushd mongo-c-driver

# TODO: Update this to our real minimum for the C++11 driver 3.1 release, once known.
- git checkout 1.5.0

- ./autogen.sh --enable-tests=no --enable-examples=no --with-libbson=bundled; make; sudo make install

- popd

before_script:
- $CC --version
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ set(CMAKE_CXX_EXTENSIONS OFF)
include(GenerateExportHeader)
include(InstallRequiredSystemLibraries)

# Allow the user to decie whether to install the shared libaries. Note that we always build them,
# since otherwise it makes the CMake logic very complex, but setting BUILD_SHARED_LIBS=Off will at
# least disable installing them.
option(BUILD_SHARED_LIBS "Install shared libraries" ON)

# If the user did not customize the install prefix,
# set it to live under build so we don't inadverently pollute /usr/local
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# MongoDB C++ Driver [![Build Status](https://travis-ci.org/mongodb/mongo-cxx-driver.svg?branch=master)](https://travis-ci.org/mongodb/mongo-cxx-driver)[![Windows Build Status](https://ci.appveyor.com/api/projects/status/w95xuowdjpr0img1/branch/master?svg=true)](https://ci.appveyor.com/project/markbenvenuto/mongo-cxx-driver)
# MongoDB C++ Driver [![Build Status](https://travis-ci.org/mongodb/mongo-cxx-driver.svg?branch=3.1-dev)](https://travis-ci.org/mongodb/mongo-cxx-driver)[![Windows Build Status](https://ci.appveyor.com/api/projects/status/w95xuowdjpr0img1/branch/3.1-dev?svg=true)](https://ci.appveyor.com/project/markbenvenuto/mongo-cxx-driver)

Welcome to the MongoDB C++ Driver!

This branch contains `mongocxx`, the new C++11 driver, and is the recommended
branch for all users.
This branch contains work-in-progress for `mongocxx` version 3.1.

End-users should use a tagged release or the `master` branch instead.

## Resources

Expand Down
4 changes: 3 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ os: Visual Studio 2015
test: off

build_script:
- cmd: git clone -b "1.3.4" --single-branch https://github.com/mongodb/mongo-c-driver.git
- cmd: git clone https://github.com/mongodb/mongo-c-driver.git
- cmd: cd mongo-c-driver
# TODO: Update this to our real minimum for the C++11 driver 3.1 release, once known.
- cmd: git checkout 1.5.0
- cmd: git submodule init
- cmd: git submodule update
- cmd: cd src\libbson
Expand Down
2 changes: 1 addition & 1 deletion docs/content/mongocxx-v3/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The mongocxx driver builds on top of the MongoDB C driver.

* For mongocxx-3.0.x, we recommend the latest stable version of libmongoc
(currently version 1.4.2 at the time this page was written).
* For mongocxx-3.1.0-beta0 or later, libmongoc 1.5.0-rc6 or later is
* For mongocxx-3.1.0-beta0 or later, libmongoc 1.5.0 or later is
required.

Unless you know that your package manager offers a high-enough version, you
Expand Down
19 changes: 19 additions & 0 deletions docs/content/mongocxx-v3/working-with-bson.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,22 @@ if (store_ele) {
```

This feature is shown in more detail in [this example](https://github.com/mongodb/mongo-cxx-driver/blob/master/examples/bsoncxx/getting_values.cpp) and [this example](https://github.com/mongodb/mongo-cxx-driver/blob/master/examples/bsoncxx/view_and_value.cpp).

### BSON Types

The [BSON specification](http://bsonspec.org/spec.html) provides a list
of supported types. These are represented in C++ using the
[b_xxx](https://mongodb.github.io/mongo-cxx-driver/api/current/classes.html#letter_B)
type wrappers.

Some BSON types don't necessarily have a native representation to wrap and
are implemented via special classes.

#### Decimal128

The `bsoncxx::decimal128` class represents a 128-bit IEEE 754-2008 decimal
floating point value. We expect users to convert these to and from
strings, but provide access to the low and high 64-bit values if users need
to convert to a native decimal128 type.

You can see how to work with `bsoncxx::decimal128` in [this example](https://github.com/mongodb/mongo-cxx-driver/blob/master/examples/bsoncxx/decimal128.cpp).
1 change: 1 addition & 0 deletions examples/bsoncxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(BSONCXX_EXAMPLES
builder_basic.cpp
builder_stream.cpp
builder_stream_customization.cpp
decimal128.cpp
getting_values.cpp
view_and_value.cpp
)
Expand Down
49 changes: 49 additions & 0 deletions examples/bsoncxx/decimal128.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2015 MongoDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <cstdlib>
#include <iostream>

#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/decimal128.hpp>
#include <bsoncxx/exception/exception.hpp>
#include <bsoncxx/types.hpp>

using namespace bsoncxx;

int main(int, char**) {
// Convert a string to BSON Decimal128.
decimal128 d128;
try {
d128 = decimal128{"1.234E+3456"};
} catch (const bsoncxx::exception& e) {
// The example won't fail, but in general, arbitrary strings
// might not convert properly.
return EXIT_FAILURE;
}

// Add it to a BSON document.
builder::stream::document build_doc;
build_doc << "counter" << d128;
auto doc = document::value{build_doc.extract()};

// Extract a BSON Decimal128 from a document view.
auto view = doc.view();
auto d128copy = view["counter"].get_decimal128().value;

// Convert it back to a string.
std::cout << "Counter is " << d128copy.to_string() << std::endl;

return EXIT_SUCCESS;
}
23 changes: 13 additions & 10 deletions src/bsoncxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ project(BSONCXX)
# Update these as needed.
# TODO: read from file
set(BSONCXX_VERSION_MAJOR 3)
set(BSONCXX_VERSION_MINOR 0)
set(BSONCXX_VERSION_PATCH 4)
set(BSONCXX_VERSION_EXTRA "-pre")
set(BSONCXX_VERSION_MINOR 1)
set(BSONCXX_VERSION_PATCH 0)
set(BSONCXX_VERSION_EXTRA "-rc0-pre")
set(BSONCXX_ABI_VERSION _noabi)

set(BSONCXX_POLY_USE_MNMLSTC_DEFAULT ON)
Expand Down Expand Up @@ -62,7 +62,7 @@ set(BSONCXX_VERSION ${BSONCXX_VERSION_MAJOR}.${BSONCXX_VERSION_MINOR}.${BSONCXX_
set(BSONCXX_INLINE_NAMESPACE "v${BSONCXX_ABI_VERSION}")
set(BSONCXX_HEADER_INSTALL_DIR "include/bsoncxx/${BSONCXX_INLINE_NAMESPACE}" CACHE INTERNAL "")

set(LIBBSON_REQUIRED_VERSION 1.3.4)
set(LIBBSON_REQUIRED_VERSION 1.5.0)
set(LIBBSON_REQUIRED_ABI_VERSION 1.0)
find_package(LibBSON ${LIBBSON_REQUIRED_VERSION} REQUIRED)

Expand All @@ -74,6 +74,7 @@ set(bsoncxx_sources
array/value.cpp
array/view.cpp
builder/core.cpp
decimal128.cpp
document/element.cpp
document/value.cpp
document/view.cpp
Expand Down Expand Up @@ -167,12 +168,14 @@ install(FILES
COMPONENT dev
)

install(TARGETS
bsoncxx
RUNTIME DESTINATION bin COMPONENT runtime
LIBRARY DESTINATION lib COMPONENT runtime
ARCHIVE DESTINATION lib COMPONENT dev
)
if (BUILD_SHARED_LIBS)
install(TARGETS
bsoncxx
RUNTIME DESTINATION bin COMPONENT runtime
LIBRARY DESTINATION lib COMPONENT runtime
ARCHIVE DESTINATION lib COMPONENT dev
)
endif()

install(TARGETS
bsoncxx_static
Expand Down
1 change: 1 addition & 0 deletions src/bsoncxx/array/element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class BSONCXX_API element : private document::element {
using document::element::get_int32;
using document::element::get_timestamp;
using document::element::get_int64;
using document::element::get_decimal128;
using document::element::get_minkey;
using document::element::get_maxkey;

Expand Down
13 changes: 13 additions & 0 deletions src/bsoncxx/builder/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ void core::append(const types::b_int64& value) {
bson_append_int64(_impl->back(), key.data(), key.length(), value.value);
}

void core::append(const types::b_decimal128& value) {
stdx::string_view key = _impl->next_key();
bson_decimal128_t d128;
d128.high = value.value.high();
d128.low = value.value.low();

bson_append_decimal128(_impl->back(), key.data(), key.length(), &d128);
}

void core::append(const types::b_minkey&) {
stdx::string_view key = _impl->next_key();

Expand Down Expand Up @@ -375,6 +384,10 @@ void core::append(const oid& value) {
append(types::b_oid{value});
}

void core::append(decimal128 value) {
append(types::b_decimal128{value});
}

void core::append(const document::view view) {
append(types::b_document{view});
}
Expand Down
10 changes: 10 additions & 0 deletions src/bsoncxx/builder/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ class BSONCXX_API core {
///
void append(const types::b_int64& value);

///
/// Append a BSON Decimal128.
///
void append(const types::b_decimal128& value);

///
/// Append a BSON min-key.
///
Expand Down Expand Up @@ -262,6 +267,11 @@ class BSONCXX_API core {
///
void append(const oid& value);

///
/// Append a decimal128 object as a BSON Decimal128.
///
void append(decimal128 value);

///
/// Append the given document view.
///
Expand Down
4 changes: 2 additions & 2 deletions src/bsoncxx/config/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
#pragma warning(push)
#pragma warning(disable : 4251 4275)

#define BSONCXX_INLINE inline __forceinline BSONCXX_PRIVATE
#define BSONCXX_INLINE inline BSONCXX_PRIVATE

#define BSONCXX_CALL __cdecl

#else

#define BSONCXX_INLINE inline __attribute__((__always_inline__)) BSONCXX_PRIVATE
#define BSONCXX_INLINE inline BSONCXX_PRIVATE

#define BSONCXX_CALL

Expand Down
2 changes: 2 additions & 0 deletions src/bsoncxx/config/private/config.hh.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#cmakedefine MONGOCXX_ENABLE_SSL
54 changes: 54 additions & 0 deletions src/bsoncxx/decimal128.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2016 MongoDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <bsoncxx/decimal128.hpp>
#include <bsoncxx/exception/error_code.hpp>
#include <bsoncxx/exception/exception.hpp>
#include <bsoncxx/stdx/string_view.hpp>

#include <bson.h>

#include <bsoncxx/config/private/prelude.hh>

namespace bsoncxx {
BSONCXX_INLINE_NAMESPACE_BEGIN

decimal128::decimal128(stdx::string_view str) {
bson_decimal128_t d128;
if (!bson_decimal128_from_string(str.to_string().c_str(), &d128)) {
throw bsoncxx::exception{error_code::k_invalid_decimal128};
}
_high = d128.high;
_low = d128.low;
}

std::string decimal128::to_string() const {
bson_decimal128_t d128;
d128.high = _high;
d128.low = _low;
char str[BSON_DECIMAL128_STRING];
bson_decimal128_to_string(&d128, str);
return {str};
}

bool operator==(const decimal128& lhs, const decimal128& rhs) {
return lhs._high == rhs._high && lhs._low == rhs._low;
}

bool operator!=(const decimal128& lhs, const decimal128& rhs) {
return !(lhs == rhs);
}

BSONCXX_INLINE_NAMESPACE_END
} // namespace bsoncxx
Loading

0 comments on commit 0a61fae

Please sign in to comment.