Skip to content

Mapping of C++ object arrays to C++ types is not supported #32

Description

@karen-arutyunov

Let's consider the following attempt to map a C++ object array to a C++ type using ODB project in-source build.

$ cat <<EOF >test.hxx
struct object_id
{
  object_id (int v = 0): value (v) {}

  int value;
};

typedef object_id object_ids[1];

#pragma db map type(object_ids) as(int) \\
  to((?)[0].value)                      \\
  from(conversion_function(?))

#pragma db value
struct object_refs
{
  object_ids refs;
};
EOF

$ <odb-src-root>/odb/odb/odb --database pgsql -I<odb-src-root>/libodb test.hxx

$ cat test-odb.hxx
  ...

  void access::composite_value_traits< ::object_refs, id_pgsql >::
  init (value_type& o,
        const image_type&  i,
        database* db)
  {
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (db);

    // refs
    //
    {
      ::object_id* v =
        o.refs;

      int vt;

      pgsql::value_traits<
          int,
          pgsql::id_integer >::set_value (
        vt,
        i.refs_value,
        i.refs_null);

      // From test.hxx:10:12
      v = conversion_function (vt);
    }
  }

  ...

Note that in the above generated function definition, a reference to the object_refs::refs member is (naturally) defined as ::object_id*. However, there is no such a possible from() clause expression which, being specified on the right hand side of the above v = ...; assignment, would modify the object_refs::refs member the v variable points to.

One of the possible solutions could be inventing a placeholder for the variable referring to the member. So that (given such a placeholder is (!)) we could write the from() expression as follows:

from((!)[0] = (?))

And so the assignment in the generated code would turn into:

      // From test.hxx:10:12
      v[0] = (vt);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions