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

[meta] Getter interface for primitive opaque types #1403

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

jpeletier
Copy link
Contributor

This PR adds support for reading opaque types that map to primitives without having to invoke a serializer that may output an unwanted type.

The opaque interface now has "get" callbacks that allow to define a function that will retrieve the value from the opaque.

Opaques are now transparent 😅 to cursors.

  struct MyOpaque {
    int value = 0;
  };

  auto my_component = ecs.component<MyOpaque>();
  my_component.opaque(flecs::I32)
      // will be called when setting an int:    
      .assign_int([](MyOpaque *data, int64_t value) {
             data->value = value;
      })
      // **new** will be called when trying to read as an int:
      .get_int([](const MyOpaque *data) -> int64_t {
            return data->value;
      });

  MyOpaque instance;

  flecs::cursor cur(ecs, my_component, &instance);

  cur.set_int(79);
  std::cout << "value = " 
      << cur.get_int()  // **new** this now will work.  
      << std::endl;  // value = 79

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.

1 participant