From 72f0237f3310a69fd566f1d2c25ca805f677199a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 5 Jul 2011 18:39:09 +0200 Subject: Add support for multi-pass database schema generation --- odb/schema-catalog-impl.hxx | 3 ++- odb/schema-catalog.cxx | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/odb/schema-catalog-impl.hxx b/odb/schema-catalog-impl.hxx index 782536a..51a4902 100644 --- a/odb/schema-catalog-impl.hxx +++ b/odb/schema-catalog-impl.hxx @@ -35,7 +35,8 @@ namespace odb // struct LIBODB_EXPORT schema_catalog_entry { - schema_catalog_entry (const char* name, void (*entry) (database&)); + schema_catalog_entry (const char* name, + bool (*entry) (database&, unsigned short pass)); }; } diff --git a/odb/schema-catalog.cxx b/odb/schema-catalog.cxx index 5332cce..2d8415f 100644 --- a/odb/schema-catalog.cxx +++ b/odb/schema-catalog.cxx @@ -14,7 +14,7 @@ using namespace std; namespace odb { - typedef void (*create_function) (database&); + typedef bool (*create_function) (database&, unsigned short pass); typedef vector create_functions; struct schema_catalog_impl: map {}; @@ -33,9 +33,23 @@ namespace odb const create_functions& fs (i->second); - for (create_functions::const_iterator j (fs.begin ()), e (fs.end ()); - j != e; ++j) - (*j) (db); + // Run the passes until we ran them all or all the functions + // return false, which means no more passes necessary. + // + for (unsigned short pass (0); pass < 3; ++pass) + { + bool done (true); + + for (create_functions::const_iterator j (fs.begin ()), e (fs.end ()); + j != e; ++j) + { + if ((*j) (db, pass)) + done = false; + } + + if (done) + break; + } } // schema_catalog_init -- cgit v1.1