From fa508bc933b7d45110be3ab64d193653bd876336 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 30 Mar 2011 09:27:11 +0200 Subject: Add support for database-specific profiles --- odb/odb.cxx | 86 +++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 37 deletions(-) (limited to 'odb/odb.cxx') diff --git a/odb/odb.cxx b/odb/odb.cxx index 87638a6..e70c368 100644 --- a/odb/odb.cxx +++ b/odb/odb.cxx @@ -393,7 +393,8 @@ main (int argc, char* argv[]) e << " " << *i << endl; } - // Parse plugin options. + // Parse plugin options. We have to do it twice to get the target + // database which is need while loading profiles. // vector av; av.push_back (argv[0]); @@ -406,57 +407,68 @@ main (int argc, char* argv[]) int ac (static_cast (av.size ())); - profile_data pd (prof_paths, argv[0]); cli::argv_file_scanner::option_info oi[3]; oi[0].option = "--options-file"; oi[0].search_func = 0; oi[1].option = "-p"; - oi[1].search_func = &profile_search; - oi[1].arg = &pd; oi[2].option = "--profile"; - oi[2].search_func = &profile_search; - oi[2].arg = &pd; - cli::argv_file_scanner scan (ac, &av[0], oi, 3); + database db; + { + oi[1].search_func = &profile_search_ignore; + oi[2].search_func = &profile_search_ignore; - options ops (scan); + cli::argv_file_scanner scan (ac, &av[0], oi, 3); + options ops (scan); - // Handle --version. - // - if (ops.version ()) - { - e << "ODB object-relational mapping (ORM) compiler for C++ " - ODB_COMPILER_VERSION_STR << endl - << "Copyright (c) 2009-2011 Code Synthesis Tools CC" << endl; + // Handle --version. + // + if (ops.version ()) + { + e << "ODB object-relational mapping (ORM) compiler for C++ " + ODB_COMPILER_VERSION_STR << endl + << "Copyright (c) 2009-2011 Code Synthesis Tools CC" << endl; - e << "This is free software; see the source for copying conditions. " - << "There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS " - << "FOR A PARTICULAR PURPOSE." << endl; + e << "This is free software; see the source for copying conditions. " + << "There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS " + << "FOR A PARTICULAR PURPOSE." << endl; - return 0; - } + return 0; + } - // Handle --help. - // - if (ops.help ()) - { - e << "Usage: " << argv[0] << " [options] file [file ...]" - << endl - << "Options:" << endl; + // Handle --help. + // + if (ops.help ()) + { + e << "Usage: " << argv[0] << " [options] file [file ...]" + << endl + << "Options:" << endl; - options::print_usage (e); - return 0; - } + options::print_usage (e); + return 0; + } - // Check that required options were specifed. - // - if (!ops.database_specified ()) - { - e << argv[0] << ": error: no database specified with the --database " - << "option" << endl; - return 1; + // Check that required options were specifed. + // + if (!ops.database_specified ()) + { + e << argv[0] << ": error: no database specified with the --database " + << "option" << endl; + return 1; + } + + db = ops.database (); } + profile_data pd (prof_paths, db, argv[0]); + oi[1].search_func = &profile_search; + oi[2].search_func = &profile_search; + oi[1].arg = &pd; + oi[2].arg = &pd; + + cli::argv_file_scanner scan (ac, &av[0], oi, 3); + options ops (scan); + size_t end (scan.end () - 1); // We have one less in plugin_args. if (end == plugin_args.size ()) -- cgit v1.1