diff options
Diffstat (limited to 'odb/relational/mysql')
-rw-r--r-- | odb/relational/mysql/context.cxx | 13 | ||||
-rw-r--r-- | odb/relational/mysql/context.hxx | 27 |
2 files changed, 28 insertions, 12 deletions
diff --git a/odb/relational/mysql/context.cxx b/odb/relational/mysql/context.cxx index 545f889..90f5766 100644 --- a/odb/relational/mysql/context.cxx +++ b/odb/relational/mysql/context.cxx @@ -3,6 +3,7 @@ // copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC // license : GNU GPL v3; see accompanying LICENSE file +#include <cassert> #include <sstream> #include <odb/sql-token.hxx> @@ -53,12 +54,24 @@ namespace relational }; } + context* context::current_; + + context:: + ~context () + { + if (current_ == this) + current_ = 0; + } + context:: context (ostream& os, semantics::unit& u, options_type const& ops) : root_context (os, u, ops, data_ptr (new (shared) data (os))), base_context (static_cast<data*> (root_context::data_.get ())), data_ (static_cast<data*> (base_context::data_)) { + assert (current_ == 0); + current_ = this; + // Populate the C++ type to DB type map. // for (size_t i (0); i < sizeof (type_map) / sizeof (type_map_entry); ++i) diff --git a/odb/relational/mysql/context.hxx b/odb/relational/mysql/context.hxx index a54803d..159fe46 100644 --- a/odb/relational/mysql/context.hxx +++ b/odb/relational/mysql/context.hxx @@ -101,26 +101,29 @@ namespace relational string const& type, semantics::context&, column_type_flags); - private: - struct data: base_context::data - { - data (std::ostream& os): base_context::data (os) {} - }; - - private: - data* data_; public: + virtual + ~context (); + context (); + context (std::ostream&, semantics::unit&, options_type const&); + static context& current () { - return dynamic_cast<context&> (base_context::current ()); + return *current_; } - context (std::ostream&, semantics::unit&, options_type const&); + private: + static context* current_; - protected: - context (); + private: + struct data: base_context::data + { + data (std::ostream& os): base_context::data (os) {} + }; + + data* data_; }; } } |