From 6508eb18a20a2f0bc48374f3f0a352f1195cc95b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 15 Oct 2011 11:33:40 +0200 Subject: Add support for readonly members New pragma: readonly. New test: readonly. --- odb/relational/pgsql/source.cxx | 77 +++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 19 deletions(-) (limited to 'odb/relational/pgsql') diff --git a/odb/relational/pgsql/source.cxx b/odb/relational/pgsql/source.cxx index c5df9bd..8547df3 100644 --- a/odb/relational/pgsql/source.cxx +++ b/odb/relational/pgsql/source.cxx @@ -118,7 +118,8 @@ namespace relational if (inverse (m) && sk_ != statement_select) return false; - if ((id (m) || readonly (m)) && sk_ == statement_update) + if ((id (m) || readonly (member_path_, member_scope_)) && + sk_ == statement_update) return false; if (!first) @@ -166,9 +167,19 @@ namespace relational if (inverse (mi.m, key_prefix_)) os << "if (sk == statement_select)" << "{"; - else if (id (mi.m) || readonly (mi.m)) - os << "if (sk != statement_update)" - << "{"; + // If the whole class is readonly, then we will never be + // called with sk == statement_update. + // + else if (!readonly (*context::top_object)) + { + semantics::class_* c; + + if (id (mi.m) || + readonly (mi.m) || + ((c = composite (mi.t)) && readonly (*c))) + os << "if (sk != statement_update)" + << "{"; + } } return true; @@ -179,8 +190,11 @@ namespace relational { if (var_override_.empty ()) { - if (semantics::class_* c = composite (mi.t)) + semantics::class_* c; + + if ((c = composite (mi.t))) { + bool ro (readonly (*c)); column_count_type const& cc (column_count (*c)); os << "n += " << cc.total << "UL"; @@ -189,7 +203,7 @@ namespace relational // insert = total - inverse // update = total - inverse - readonly // - if (cc.inverse != 0 || cc.readonly != 0) + if (cc.inverse != 0 || (!ro && cc.readonly != 0)) { os << " - (" << endl << "sk == statement_select ? 0 : "; @@ -197,7 +211,7 @@ namespace relational if (cc.inverse != 0) os << cc.inverse << "UL" << endl; - if (cc.readonly != 0) + if (!ro && cc.readonly != 0) { if (cc.inverse != 0) os << " + "; @@ -215,7 +229,23 @@ namespace relational else os << "n++;"; - if (inverse (mi.m, key_prefix_) || id (mi.m) || readonly (mi.m)) + bool block (false); + + // The same logic as in pre(). + // + if (inverse (mi.m, key_prefix_)) + block = true; + else if (!readonly (*context::top_object)) + { + semantics::class_* c; + + if (id (mi.m) || + readonly (mi.m) || + ((c = composite (mi.t)) && readonly (*c))) + block = true; + } + + if (block) os << "}"; else os << endl; @@ -469,10 +499,18 @@ namespace relational os << "// " << name << endl << "//" << endl; - if (id (mi.m) || readonly (mi.m)) - // The block scope is added later, if necessary. - // - os << "if (sk == statement_insert)"; + // If the whole class is readonly, then we will never be + // called with sk == statement_update. + // + if (!readonly (*context::top_object)) + { + semantics::class_* c; + + if (id (mi.m) || + readonly (mi.m) || + ((c = composite (mi.t)) && readonly (*c))) + os << "if (sk == statement_insert)"; + } } // If this is a wrapped composite value, then we need to @@ -488,7 +526,10 @@ namespace relational } if (composite (mi.t)) + { + os << "{"; traits = "composite_value_traits< " + mi.fq_type () + " >"; + } else { // When handling a pointer, mi.t is the id type of the referenced @@ -560,7 +601,9 @@ namespace relational virtual void post (member_info& mi) { - if (!composite (mi.t)) + if (composite (mi.t)) + os << "}"; + else { // When handling a pointer, mi.t is the id type of the referenced // object. @@ -582,15 +625,11 @@ namespace relational virtual void traverse_composite (member_info& mi) { - // Should be a single statement or a block. - // os << "if (" << traits << "::init (" << endl << "i." << mi.var << "value," << endl << member << "," << endl - << "sk))" - << "{" - << "grew = true;" - << "}"; + << "sk))" << endl + << "grew = true;"; } virtual void -- cgit v1.1