aboutsummaryrefslogtreecommitdiff
path: root/odb/option-types.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-03-01 11:56:33 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-03-01 11:56:33 +0200
commitfe69d94f3d2dcb37d69ac2d7a0f88ad5fce2ad5c (patch)
treed93f7ea21f66e9fe416c48766b99f987ad7b3804 /odb/option-types.cxx
parent6c97eb68924e7f9ea5b0d859182562ec8f812a1e (diff)
Add support for embedded database schemas
New options: --schema-format, --default-schema. New example: schema/embedded.
Diffstat (limited to 'odb/option-types.cxx')
-rw-r--r--odb/option-types.cxx93
1 files changed, 93 insertions, 0 deletions
diff --git a/odb/option-types.cxx b/odb/option-types.cxx
new file mode 100644
index 0000000..b05fead
--- /dev/null
+++ b/odb/option-types.cxx
@@ -0,0 +1,93 @@
+// file : odb/option-types.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#include <string>
+#include <istream>
+#include <ostream>
+#include <algorithm> // std::lower_bound
+
+#include <odb/option-types.hxx>
+
+using namespace std;
+
+// database
+//
+static const char* database_[] =
+{
+ "mysql",
+ "tracer"
+};
+
+const char* database::
+string () const
+{
+ return database_[v_];
+}
+
+istream&
+operator>> (istream& is, database& db)
+{
+ string s;
+ is >> s;
+
+ if (!is.fail ())
+ {
+ const char** e (database_ + sizeof (database_) / sizeof (char*));
+ const char** i (lower_bound (database_, e, s));
+
+ if (i != e && *i == s)
+ db = database::value (i - database_);
+ else
+ is.setstate (istream::failbit);
+ }
+
+ return is;
+}
+
+ostream&
+operator<< (ostream& os, database db)
+{
+ return os << db.string ();
+}
+
+// schema_format
+//
+static const char* schema_format_[] =
+{
+ "embedded",
+ "sql"
+};
+
+const char* schema_format::
+string () const
+{
+ return schema_format_[v_];
+}
+
+istream&
+operator>> (istream& is, schema_format& sf)
+{
+ string s;
+ is >> s;
+
+ if (!is.fail ())
+ {
+ const char** e (schema_format_ + sizeof (schema_format_) / sizeof (char*));
+ const char** i (lower_bound (schema_format_, e, s));
+
+ if (i != e && *i == s)
+ sf = schema_format::value (i - schema_format_);
+ else
+ is.setstate (istream::failbit);
+ }
+
+ return is;
+}
+
+ostream&
+operator<< (ostream& os, schema_format sf)
+{
+ return os << sf.string ();
+}