Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the catalog facade API to allow usage outside gaiac #761

Merged
merged 4 commits into from
Jun 25, 2021

Conversation

simone-gaia
Copy link
Contributor

The catalog facade API provides simplified access to the catalog and so far has been used only by gaiac. This PR (#756) introduced a similar concept in gaiat.

@daxhaw pointed out that we could refactor this into a public (internal), and subclass the facade to address specific use cases. I agreed with this approach but to make the #756 lighter, I decided to create a separate PR.

Comments on PR-756:

Note: This API is by no means perfect or final. The idea is that logic to generate code should be placed here (eg. class names, namespaces, etc...). Suggestions, improvements etc.. are all welcome.

@simone-gaia simone-gaia requested a review from daxhaw June 25, 2021 17:04
{
return true;
}
}
return false;
}

std::vector<link_facade_t> table_facade_t::incoming_links() const
Copy link
Contributor Author

@simone-gaia simone-gaia Jun 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an initial version of this change, these methods were templated. This allows specifying different subclasses:

    template <class T_link_type = link_facade_t>
    std::vector<T_link_type> incoming_links() const
    {
        auto links = std::vector<T_link_type>();

        for (const gaia_relationship_t& relationship : m_table.incoming_relationships())
        {
            links.emplace_back(relationship, false);
        }

        return links;
    }

So that you can write:

 for (auto& link : m_table.outgoing_links<gaiac_outgoing_link_facade_t>())
{
    ...
}

Where gaiac_outgoing_link_facade_t is a subclass of link_facade_t.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I did not go with this approach is that you need to expose the implementation of each method... Because you know.. templates :) If anyone likes this approach we can re-evaluate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid templates unless they are absolutely required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's what I thought.

#include "gaia_internal/catalog/gaia_catalog.h"

/*
* Contains classes that make it simpler to generate code from the
* catalog types. Each Catalog class has its own "facade".
* Eg. gaia_table_t -> table_facade_t.
*
* The only user of this class is edc_generator.
* Each generator (eg. gaiat, gaiac) may decide to subclass one of
* these classes to provide more specific logics.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: logics -> logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume (and like) that the subclasses are meant to add new methods and not override existing functionality. No need to add virtual functions if we don't expect to use it as a polymorphic type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: logics -> logic.

Done.

I assume (and like) that the subclasses are meant to add new methods and not override existing functionality. No need to add virtual functions if we don't expect to use it as a polymorphic type.

That's correct.

Copy link
Contributor

@daxhaw daxhaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Only one nit comment on a comment.

@simone-gaia simone-gaia merged commit 0ddeb42 into master Jun 25, 2021
@simone-gaia simone-gaia deleted the rondelli-catalog-facade-refactor-2 branch June 25, 2021 23:39
std::string generate_incoming_relationships_accessors_cpp();
std::string generate_outgoing_relationships_accessors();
std::string generate_outgoing_relationships_accessors_cpp();
std::string generate_incoming_links_accessors();
Copy link
Contributor

@LaurentiuCristofor LaurentiuCristofor Jul 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So when do we say "link" and when do we say "relationship"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
auto links = std::vector<link_facade_t>();

for (const gaia_relationship_t& relationship : m_table.incoming_relationships())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should gaia_relationship_t become gaia_link_t?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gaia_relationship_t should remain as-is. The difference is that we should add gaia_link_t to the relationship.

Eachgaia_relationship_t has 2 gaia_link_t (the forward link and the backward link).

}
else
{
ASSERT_UNREACHABLE("Unsupported relationship cardinality!");
Copy link
Contributor

@LaurentiuCristofor LaurentiuCristofor Jul 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relationship->link in assert message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIll try to address in next PR.


std::string gaiac_incoming_link_facade_t::next_offset() const
{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIll try to address in next PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants