aboutsummaryrefslogtreecommitdiff
path: root/odb/option-parsers.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-10-25 10:35:36 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-10-25 10:35:36 +0200
commitd1ad30f7a517e69bc87d1347224f1c9ab38493b3 (patch)
tree95189ae91fcce6366f0a121f67b483f3c1b962e7 /odb/option-parsers.hxx
parent7fc555e53f0a03c93fe31ad9850b1e5d885c44f6 (diff)
Static multi-database support
Add new options (--multi-database, --default-database). Generate common code to -odb.?xx files and database-specific to -odb-<db>.?xx.
Diffstat (limited to 'odb/option-parsers.hxx')
-rw-r--r--odb/option-parsers.hxx89
1 files changed, 89 insertions, 0 deletions
diff --git a/odb/option-parsers.hxx b/odb/option-parsers.hxx
new file mode 100644
index 0000000..a8fc1f5
--- /dev/null
+++ b/odb/option-parsers.hxx
@@ -0,0 +1,89 @@
+// file : odb/option-parsers.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#ifndef ODB_OPTION_PARSERS_HXX
+#define ODB_OPTION_PARSERS_HXX
+
+#include <sstream>
+
+#include <odb/option-types.hxx>
+#include <odb/options.hxx>
+
+namespace cli
+{
+ template <typename V>
+ struct parser<database_map<V> >
+ {
+ static void
+ parse (database_map<V>& m, bool& xs, scanner& s)
+ {
+ typedef database_map<V> map;
+
+ xs = true;
+ std::string o (s.next ());
+
+ if (s.more ())
+ {
+ std::string ov (s.next ());
+ std::string::size_type p = ov.find (':');
+
+ if (p != std::string::npos)
+ {
+ std::string kstr (ov, 0, p);
+ std::string vstr (ov, p + 1);
+
+ // See if this prefix resolves to the database name. If not,
+ // assume there is no prefix.
+ //
+ database k;
+ std::istringstream ks (kstr);
+
+ if (ks >> k && ks.eof ())
+ {
+ V v = V ();
+
+ if (!vstr.empty ())
+ {
+ std::istringstream vs (vstr);
+
+ if (!(vs >> v && vs.eof ()))
+ throw invalid_value (o, ov);
+ }
+
+ m[k] = v; // Override any old value.
+ return;
+ }
+ }
+
+ // No database prefix is specified which means it applies to
+ // all the databases.
+ //
+ V v = V ();
+
+ if (!ov.empty ())
+ {
+ std::istringstream vs (ov);
+
+ if (!(vs >> v && vs.eof ()))
+ throw invalid_value (o, ov);
+ }
+
+ // We don't want to override database-specific values, so use
+ // insert().
+ //
+ m.insert (typename map::value_type (database::common, v));
+ m.insert (typename map::value_type (database::mssql, v));
+ m.insert (typename map::value_type (database::mysql, v));
+ m.insert (typename map::value_type (database::oracle, v));
+ m.insert (typename map::value_type (database::pgsql, v));
+ m.insert (typename map::value_type (database::sqlite, v));
+ }
+ else
+ throw missing_value (o);
+ }
+ };
+}
+
+
+#endif // ODB_OPTION_PARSERS_HXX