diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-09-03 12:02:30 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-09-03 12:02:30 +0200 |
commit | bb48c54f1080874f5a10907714f5fbae0b985ce9 (patch) | |
tree | 8d15b4c6a569a49d22074391440bb5424b7311ef /boost | |
parent | 92ebb8c861c4986e10d38d949a024aee205b14b2 (diff) |
Add support for Boost Multi-Index container in Boost profile
Diffstat (limited to 'boost')
-rw-r--r-- | boost/common/makefile | 1 | ||||
-rw-r--r-- | boost/common/multi-index/driver.cxx | 190 | ||||
-rw-r--r-- | boost/common/multi-index/makefile | 124 | ||||
-rw-r--r-- | boost/common/multi-index/test.hxx | 114 | ||||
-rw-r--r-- | boost/common/multi-index/test.std | 0 |
5 files changed, 429 insertions, 0 deletions
diff --git a/boost/common/makefile b/boost/common/makefile index 1c41fa8..59c4537 100644 --- a/boost/common/makefile +++ b/boost/common/makefile @@ -5,6 +5,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make tests := \ +multi-index \ optional \ smart-ptr \ template \ diff --git a/boost/common/multi-index/driver.cxx b/boost/common/multi-index/driver.cxx new file mode 100644 index 0000000..f8a87f4 --- /dev/null +++ b/boost/common/multi-index/driver.cxx @@ -0,0 +1,190 @@ +// file : boost/common/multi-index/driver.cxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test Boost multi-index container persistence. +// + +#include <memory> // std::auto_ptr +#include <cassert> +#include <iostream> + +#include <odb/database.hxx> +#include <odb/transaction.hxx> + +#include <common/common.hxx> + +#include "test.hxx" +#include "test-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + { + using namespace odb; + + assert (access::container_traits<int_lst>::kind == ck_ordered); + assert (access::container_traits<int_vec>::kind == ck_ordered); + assert (access::container_traits<int_set>::kind == ck_set); + + assert (access::container_traits<int_lst_set>::kind == ck_ordered); + assert (access::container_traits<comp_set_vec>::kind == ck_ordered); + assert (access::container_traits<comp_set_set>::kind == ck_set); + } + + try + { + auto_ptr<database> db (create_database (argc, argv)); + + for (unsigned short i (0); i < 2; ++i) + { + object empty ("empty"), med ("medium"), full ("full"); + + // + // empty + // + + // + // med + // + med.il.push_back (234); + med.il.push_back (123); + + med.iv.push_back (234); + med.iv.push_back (123); + + med.is.insert (234); + med.is.insert (123); + + med.ils.push_back (234); + med.ils.push_back (123); + + med.csv.insert (comp (234, "bcd")); + med.csv.insert (comp (123, "abc")); + + med.css.insert (comp (234, "bcd")); + med.css.insert (comp (123, "abc")); + + // + // full + // + full.il.push_back (2345); + full.il.push_back (1234); + full.il.push_back (3456); + + full.iv.push_back (2345); + full.iv.push_back (1234); + full.iv.push_back (3456); + + full.is.insert (2345); + full.is.insert (1234); + full.is.insert (3456); + + full.ils.push_back (2345); + full.ils.push_back (1234); + full.ils.push_back (3456); + + full.csv.insert (comp (234, "bcde")); + full.csv.insert (comp (123, "abcd")); + full.csv.insert (comp (234, "cdef")); + + full.css.insert (comp (234, "bcde")); + full.css.insert (comp (123, "abcd")); + full.css.insert (comp (234, "cdef")); + + // persist + // + { + transaction t (db->begin ()); + db->persist (empty); + db->persist (med); + db->persist (full); + t.commit (); + } + + // load & check + // + { + transaction t (db->begin ()); + auto_ptr<object> e (db->load<object> ("empty")); + auto_ptr<object> m (db->load<object> ("medium")); + auto_ptr<object> f (db->load<object> ("full")); + t.commit (); + + assert (empty == *e); + assert (med == *m); + assert (full == *f); + } + + // empty + // + empty.il.push_back (12); + empty.iv.push_back (12); + empty.is.insert (12); + empty.ils.push_back (12); + empty.csv.insert (comp (12, "ab")); + empty.css.insert (comp (12, "ab")); + + // med + // + med.il.clear (); + med.iv.clear (); + med.is.clear (); + med.ils.clear (); + med.csv.clear (); + med.css.clear (); + + // full + // + full.il.push_back (4567); + full.iv.push_back (4567); + full.is.insert (4567); + full.ils.push_back (4567); + full.csv.insert (comp (4567, "defg")); + full.css.insert (comp (4567, "defg")); + + // update + // + { + transaction t (db->begin ()); + db->update (empty); + db->update (med); + db->update (full); + t.commit (); + } + + // load & check + // + { + transaction t (db->begin ()); + auto_ptr<object> e (db->load<object> ("empty")); + auto_ptr<object> m (db->load<object> ("medium")); + auto_ptr<object> f (db->load<object> ("full")); + t.commit (); + + assert (empty == *e); + assert (med == *m); + assert (full == *f); + } + + // erase + // + if (i == 0) + { + transaction t (db->begin ()); + db->erase<object> ("empty"); + db->erase<object> ("medium"); + db->erase<object> ("full"); + t.commit (); + } + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/boost/common/multi-index/makefile b/boost/common/multi-index/makefile new file mode 100644 index 0000000..96f4b66 --- /dev/null +++ b/boost/common/multi-index/makefile @@ -0,0 +1,124 @@ +# file : boost/common/multi-index/makefile +# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx_tun := driver.cxx +odb_hdr := test.hxx +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +common.l := $(out_root)/libcommon/common/common.l +common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options + +driver := $(out_base)/driver +dist := $(out_base)/.dist +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Import. +# +$(call import,\ + $(scf_root)/import/odb/stub.make,\ + odb: odb,odb-rules: odb_rules) + +$(call import,\ + $(scf_root)/import/libodb-boost/stub.make,\ + l: odb_boost.l,cpp-options: odb_boost.l.cpp-options) + +$(call import,\ + $(scf_root)/import/libboost/header-only/stub.make,\ + cpp-options: boost.l.cpp-options) + +# Build. +# +$(driver): $(cxx_obj) $(odb_boost.l) $(common.l) +$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) +$(cxx_obj) $(cxx_od): $(common.l.cpp-options) $(odb_boost.l.cpp-options) \ +$(boost.l.cpp-options) + +genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(odb) +$(gen): odb := $(odb) +$(gen) $(dist): export odb_options += --database $(db_id) \ +--profile boost/multi-index --generate-schema \ +--table-prefix boost_multi_index_ +$(gen): cpp_options := -I$(src_base) +$(gen): $(common.l.cpp-options) $(odb_boost.l.cpp-options) \ +$(boost.l.cpp-options) + +$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) + +# Alias for default target. +# +$(out_base)/: $(driver) + +# Dist +# +name := $(subst /,-,$(subst $(src_root)/boost/common/,,$(src_base))) + +$(dist): db_id := @database@ +$(dist): sources := $(cxx_tun) +$(dist): headers := $(odb_hdr) +$(dist): data_dist := test.std +$(dist): export name := $(name) +$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \ +$(call vc10projs,$(name)) +$(dist): + $(call dist-data,$(sources) $(headers) $(data_dist)) + $(call meta-automake,../template/Makefile.am) + $(call meta-vc9projs,../template/template,$(name)) + $(call meta-vc10projs,../template/template,$(name)) + +# Test. +# +$(test): $(driver) $(src_base)/test.std + $(call schema) + $(call message,test $<,$< --options-file $(dcf_root)/db.options \ +>$(out_base)/test.out) + $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out) + $(call message,,rm -f $(out_base)/test.out) + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) \ + $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) + $(call message,,rm -f $(out_base)/test.out) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(genf) +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + +# How to. +# +$(call include,$(bld_root)/dist.make) +$(call include,$(bld_root)/meta/vc9proj.make) +$(call include,$(bld_root)/meta/vc10proj.make) +$(call include,$(bld_root)/meta/automake.make) + +$(call include,$(bld_root)/cxx/standard.make) # cxx_standard +ifdef cxx_standard +$(gen): odb_options += --std $(cxx_standard) +$(call include,$(odb_rules)) +endif + +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/o-e.make) + +# Dependencies. +# +$(call import,$(src_root)/libcommon/makefile) diff --git a/boost/common/multi-index/test.hxx b/boost/common/multi-index/test.hxx new file mode 100644 index 0000000..4018b61 --- /dev/null +++ b/boost/common/multi-index/test.hxx @@ -0,0 +1,114 @@ +// file : boost/common/multi-index/test.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#include <boost/multi_index_container.hpp> +#include <boost/multi_index/member.hpp> +#include <boost/multi_index/identity.hpp> +#include <boost/multi_index/ordered_index.hpp> +#include <boost/multi_index/sequenced_index.hpp> +#include <boost/multi_index/random_access_index.hpp> + +#include <odb/core.hxx> + +namespace mi = boost::multi_index; + +#pragma db value +struct comp +{ + comp () {} + comp (int n, const std::string& s) : num (n), str (s) {} + + #pragma db column("number") + int num; + std::string str; +}; + +inline bool +operator== (const comp& x, const comp& y) +{ + return x.num == y.num && x.str == y.str; +} + +typedef +mi::multi_index_container< + int, + mi::indexed_by<mi::sequenced<> > +> int_lst; + +typedef +mi::multi_index_container< + int, + mi::indexed_by<mi::random_access<> > +> int_vec; + +typedef +mi::multi_index_container< + int, + mi::indexed_by<mi::ordered_unique<mi::identity<int> > > +> int_set; + +typedef +mi::multi_index_container< + int, + mi::indexed_by< + mi::sequenced<>, + mi::ordered_unique<mi::identity<int> > + > +> int_lst_set; + +typedef +mi::multi_index_container< + comp, + mi::indexed_by< + mi::ordered_unique<mi::member<comp, std::string, &comp::str> >, + mi::random_access<> + > +> comp_set_vec; + +typedef +mi::multi_index_container< + comp, + mi::indexed_by< + mi::ordered_unique<mi::member<comp, int, &comp::num> >, + mi::ordered_unique<mi::member<comp, std::string, &comp::str> > + > +> comp_set_set; + +#pragma db object +struct object +{ + object () {} + object (const std::string& id): id (id) {} + + #pragma db id + std::string id; + + int_lst il; + int_lst iv; + int_set is; + + int_lst_set ils; + comp_set_vec csv; + comp_set_set css; +}; + +inline bool +operator== (const object& x, const object& y) +{ + return + x.id == y.id && + + x.il == y.il && + x.iv == y.iv && + x.is == y.is && + + x.ils == y.ils && + x.csv == y.csv && + x.css == y.css; +} + +#endif // TEST_HXX diff --git a/boost/common/multi-index/test.std b/boost/common/multi-index/test.std new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/boost/common/multi-index/test.std |