diff options
Diffstat (limited to 'odb/database.cxx')
-rw-r--r-- | odb/database.cxx | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/odb/database.cxx b/odb/database.cxx new file mode 100644 index 0000000..d094397 --- /dev/null +++ b/odb/database.cxx @@ -0,0 +1,51 @@ +// file : odb/database.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include <string> +#include <istream> +#include <ostream> +#include <algorithm> // std::lower_bound + +#include <odb/database.hxx> + +using namespace std; + +static const char* str[] = +{ + "mysql", + "tracer" +}; + +const char* database:: +string () const +{ + return str[v_]; +} + +istream& +operator>> (istream& is, database& db) +{ + string s; + is >> s; + + if (!is.fail ()) + { + const char** e (str + sizeof (str) / sizeof (char*)); + const char** i (lower_bound (str, e, s)); + + if (i != e && *i == s) + db = database::value (i - str); + else + is.setstate (istream::failbit); + } + + return is; +} + +ostream& +operator<< (ostream& os, database db) +{ + return os << db.string (); +} |