diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-06-04 16:29:02 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-06-04 16:29:02 +0200 |
commit | bb76e9388009ed0bb2512034f8cd48a7d19aabb3 (patch) | |
tree | 0b43ebff1c36a35bf7cf66c670f04707d4334e38 /odb/database.cxx | |
parent | 633f9c5ac574750799efdfe5d1eb31db40a267da (diff) |
Next chunk of functionality
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 (); +} |