aboutsummaryrefslogtreecommitdiff
path: root/odb/relational/inline.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-07-04 17:53:47 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-07-04 17:53:47 +0200
commit932cd7a53b3996468fee5cfa63c2b2998dbe971a (patch)
tree55424fe09a95310bc2b8e6d1473108b64107e06c /odb/relational/inline.hxx
parent1ac1ae65e6cbf42c002acb27615127bbc0b20d9e (diff)
Implement support for database operations callbacks
New object pragma: callback. New test: common/callback. New manual section: 10.1.4, "callback".
Diffstat (limited to 'odb/relational/inline.hxx')
-rw-r--r--odb/relational/inline.hxx90
1 files changed, 90 insertions, 0 deletions
diff --git a/odb/relational/inline.hxx b/odb/relational/inline.hxx
index 856965c..89fc720 100644
--- a/odb/relational/inline.hxx
+++ b/odb/relational/inline.hxx
@@ -13,6 +13,67 @@ namespace relational
{
namespace inline_
{
+ //
+ //
+ struct callback_calls: traversal::class_, virtual context
+ {
+ typedef callback_calls base;
+
+ callback_calls ()
+ {
+ *this >> inherits_ >> *this;
+ }
+
+ callback_calls (callback_calls const&)
+ : root_context (), //@@ -Wextra
+ context ()
+ {
+ *this >> inherits_ >> *this;
+ }
+
+ virtual void
+ traverse (type& c, bool constant)
+ {
+ const_ = constant;
+ traverse (c);
+ }
+
+ virtual void
+ traverse (type& c)
+ {
+ // Ignore transient bases.
+ //
+ if (!c.count ("object"))
+ return;
+
+ if (c.count ("callback"))
+ {
+ string name (c.get<string> ("callback"));
+
+ // In case of the const object, we only generate the call if
+ // there is a const callback.
+ //
+ if (const_)
+ {
+ if (c.count ("callback-const"))
+ os << "static_cast< const " << c.fq_name () << "& > (obj)." <<
+ name << " (e, db);";
+ }
+ else
+ os << "static_cast< " << c.fq_name () << "& > (obj)." <<
+ name << " (e, db);";
+ }
+ else
+ inherits (c);
+ }
+
+ protected:
+ bool const_;
+ traversal::inherits inherits_;
+ };
+
+ //
+ //
struct class_: traversal::class_, virtual context
{
typedef class_ base;
@@ -113,6 +174,32 @@ namespace relational
if (abst)
return;
+ // callback ()
+ //
+ os << "inline" << endl
+ << "void " << traits << "::" << endl
+ << "callback (database& db, object_type& obj, callback_event e)"
+ << endl
+ << "{"
+ << "ODB_POTENTIALLY_UNUSED (db);"
+ << "ODB_POTENTIALLY_UNUSED (obj);"
+ << "ODB_POTENTIALLY_UNUSED (e);"
+ << endl;
+ callback_calls_->traverse (c, false);
+ os << "}";
+
+ os << "inline" << endl
+ << "void " << traits << "::" << endl
+ << "callback (database& db, const object_type& obj, " <<
+ "callback_event e)"
+ << "{"
+ << "ODB_POTENTIALLY_UNUSED (db);"
+ << "ODB_POTENTIALLY_UNUSED (obj);"
+ << "ODB_POTENTIALLY_UNUSED (e);"
+ << endl;
+ callback_calls_->traverse (c, true);
+ os << "}";
+
// query_type
//
if (options.generate_query ())
@@ -164,6 +251,9 @@ namespace relational
*/
}
+
+ private:
+ instance<callback_calls> callback_calls_;
};
}
}