From 8e69f40ab32dc8604b68f360ae30fa961ba036ee Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 4 Feb 2015 17:23:54 +0200 Subject: Implement object loading views See section 10.2 in the manual for details. --- odb/context.hxx | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'odb/context.hxx') diff --git a/odb/context.hxx b/odb/context.hxx index 9538389..34f9692 100644 --- a/odb/context.hxx +++ b/odb/context.hxx @@ -84,7 +84,13 @@ enum class_kind // that lead all the way from the object member to the innermost // composite value member. // -typedef std::vector data_member_path; +struct data_member_path: std::vector +{ + data_member_path () {} + + explicit + data_member_path (semantics::data_member& m) {push_back (&m);} +}; // Class inheritance chain, from the most derived to base. // @@ -162,6 +168,7 @@ struct view_object tree scope; location_t loc; semantics::class_* obj; + semantics::data_member* ptr; // Corresponding object pointer, if any. cxx_tokens cond; // Join condition tokens. }; @@ -173,6 +180,21 @@ typedef std::vector view_objects; typedef std::map view_alias_map; typedef std::map view_object_map; +// Collection of relationships via which the objects are joined. +// We need this information to figure out which alias/table +// names to use for columns corresponding to inverse object +// pointers inside objects that this view may be loading. +// +// The first object is the pointer (i.e., the one containing +// this data member) while the other is the pointee. In other +// words, first -> second. We always store the direct (i.e., +// non-inverse) side of the relationship. Note also that there +// could be multiple objects joined using the same relationship. +// +typedef +std::multimap > +view_relationship_map; + // // struct view_query @@ -232,8 +254,8 @@ struct column_expr: std::vector // struct member_access { - member_access (const location& l, bool s) - : loc (l), synthesized (s), by_value (false) {} + member_access (const location& l, const char* k, bool s) + : loc (l), kind (k), synthesized (s), by_value (false) {} // Return true of we have the (?) placeholder. // @@ -249,11 +271,21 @@ struct member_access return synthesized && expr.size () == 3; // this.member } + bool + empty () const + { + return expr.empty (); + } + + // Issues diagnostics and throws operation_failed if expression is + // empty. + // std::string translate (std::string const& obj, std::string const& val = std::string ()) const; location loc; + const char* kind; // accessor/modifier; used for diagnostics. bool synthesized; // If true, then this is a synthesized expression. cxx_tokens expr; bool by_value; // True if accessor returns by value. False doesn't @@ -623,6 +655,14 @@ public: return t.count ("view"); } + // Direct member of a view. + // + static bool + view_member (semantics::data_member& m) + { + return view (dynamic_cast (m.scope ())); + } + // Check whether the type is a wrapper. Return the wrapped type if // it is a wrapper and NULL otherwise. Note that the returned type // may be cvr-qualified. -- cgit v1.1