Code Monkey home page Code Monkey logo

boost_mongo's Introduction

A MongoDB/JSON Boost Serialization Archive

Build Status

MongoDB is a popular document database and boost::serialization a great C++ marshalling library. Wouldn't it be even greater to patch these two together? - This is where boost_mongo comes in.

boost_mongo serializes all your custom data types into mongo collections in human readable format. It can be used like any other boost archive and if your code already works with xml archives, you are good to go. Besides, the json_archives can be used for serialization to and from plain JSON files.

Usage

The mongo archives can be used just like the boost xml archives. This means, that members need to be wrapped as name-value-pairs for serialization (see http://www.boost.org/doc/libs/1_54_0/libs/serialization/doc/wrappers.html#nvp for more detail).

This is a simple example, illustrating how boost_mongo serialization looks like:

struct A
{
	int a;

private:
	friend class boost::serialization::access;
	template<typename Archive>
	void serialize(Archive& ar, unsigned int const)
	{
		ar & BOOST_SERIALIZATION_NVP(a);
	}
};

// ...
A a;
mongo::BSONObjBuilder builder;
mongo_oarchive out(builder);
out << boost::serialization::make_nvp("myData", a);
// ...

The mongo_oarchive and mongo_iarchve expect a mongo::BSONObjBuilder and a mongo::BSONObj, respectively. These containers can then be handled by the mongo C++ client drivers.

Testing

boost_mongo passes all tests shipped with the boost distribution. There are also many dedicated boost_mongo tests, including CI and code coverage.

Requirements

  • boost (>=1.46)
  • mongo C++ client driver

Licensing

Copyright 2013, Sebastian Jeltsch ([email protected])

boost_mongo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

boost_mongo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with boost_mongo. If not, see http://www.gnu.org/licenses/.

boost_mongo's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

boost_mongo's Issues

Compiling Error

When trying to compile my test program I get the following error:

../mongodb_test/boost/archive/mongo_oarchive.hpp:67:3: error: invalid static_cast from type 'const boost::archive::object_id_type' to type 'const type& {aka const unsigned int&}'
../mongodb_test/boost/archive/mongo_oarchive.hpp: In instantiation of 'typename std::enable_if<typename boost::fusion::result_of::has_key<boost::fusion::map<boost::fusion::pair<boost::archive::class_id_type, short int>, boost::fusion::pair<boost::archive::class_id_optional_type, short int>, boost::fusion::pair<boost::archive::class_id_reference_type, short int>, boost::fusion::pair<boost::archive::object_id_type, unsigned int>, boost::fusion::pair<boost::archive::object_reference_type, short unsigned int>, boost::fusion::pair<boost::archive::version_type, unsigned int>, boost::fusion::pair<boost::archive::tracking_type, bool> >, T>::type:: value>::type boost::archive::mongo_oarchive::save_override(const T&, int) [with T = boost::archive::object_id_type; typename std::enable_if<typename boost::fusion::result_of::has_key<boost::fusion::map<boost::fusion::pair<boost::archive::class_id_type, short int>, boost::fusion::pair<boost::archive::class_id_optional_type, short int>, boost::fusion::pair<boost::archive::class_id_reference_type, short int>, boost::fusion::pair<boost::archive::object_id_type, unsigned int>, boost::fusion::pair<boost::archive::object_reference_type, short unsigned int>, boost::fusion::pair<boost::archive::version_type, unsigned int>, boost::fusion::pair<boost::archive::tracking_type, bool> >, T>::type:: value>::type = void]':
/usr/include/boost/archive/detail/interface_oarchive.hpp:63:9:   required from 'Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = const boost::archive::object_id_type; Archive = boost::archive::mongo_oarchive]'
/usr/include/boost/archive/detail/common_oarchive.hpp:45:9:   required from 'void boost::archive::detail::common_oarchive<Archive>::vsave(boost::archive::object_id_type) [with Archive = boost::archive::mongo_oarchive]'
../mongodb_test/data/person.cpp:5:1:   required from here

Compiled on arch-linux 64bit - g++ version 4.7.2 - Boost version 1.50

Serializing bool types

The serialization in for bools for the json archive follows the path of a double, resulting in all bool values being set to false even if they should be true

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.