Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • M mantle-api
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 17
    • Issues 17
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 7
    • Merge requests 7
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Eclipse ProjectsEclipse Projects
  • Eclipse openpass
  • mantle-api
  • Merge requests
  • !9

Interface function IEntityRepository::Get is returning an optional reference to query an IEntity.

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Jupp Tscheak requested to merge jtschea/scenario_api:mb_proposal_entity_repository into master Jul 15, 2021
  • Overview 10
  • Commits 3
  • Changes 1

1. Use optional reference as return value for IEntity query.
In order to check whether an IEntity with a certain name/id exists, function IEntityRepository::Contains could be used to query this information. If IEntityRepository::Get is called on a non-existing name/id, the function would throw, so for defensive programming reasons a IEntityRepository::Contains should always be done before actually calling IEntityRepository::Get. The good thing about plain old C-pointers is that assignment and existence check can be done in one call. Since C++17 the same functionality is managed by std::optional.

Another disadvantage of using a plain reference to IEntity is when it is used as a class member, where it needs to be initialized when an object of that class is defined. It might be that during construction time this IEntity is not known/existing yet. Of cource, a plain old C-pointer could be used in this case, but it wouldn't be a consistant usage.

The proposal is to use std::optional<std::reference_wrapper> as return value for IEntityRepository::Get.

Please also see @rparisha2 's code snippet.

2. Possibility to register functions that are called on entity creatiion/deletion.
If scenario domain entities are having references to the same IEntity, it might be that another instance is deleting this IEntity invalidating all references pointing to it. Those situations could be handled using the callback mechanism.

The program was tested solely for our own use cases, which might differ from yours.

Jupp Tscheak jupp.tscheak@daimler.com, Mercedes-Benz AG on behalf of Daimler TSS GmbH

https://github.com/Daimler/daimler-foss/blob/master/PROVIDER_INFORMATION.md

Edited Aug 10, 2021 by Jupp Tscheak
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: mb_proposal_entity_repository

Copyright © Eclipse Foundation, Inc. All Rights Reserved.     Privacy Policy | Terms of Use | Copyright Agent