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

Reflection Queries #2

Open
SK83RJOSH opened this issue Oct 19, 2022 · 1 comment · Fixed by #6
Open

Reflection Queries #2

SK83RJOSH opened this issue Oct 19, 2022 · 1 comment · Fixed by #6
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@SK83RJOSH
Copy link
Owner

SK83RJOSH commented Oct 19, 2022

Now that file parsing and reflection are complete it's time to improve ergonomics. After some discussions with friends, I think a query api will be a nice starting point.

Queries

Types and blocks should expose a set of Query functions. These functions will accept a std::string_view containing a query. Queries will be transformed (preferably at compile time) into a set of operations on the given BlendType "hierarchy".

BlendType::QueryValue(std::span, std::string_view query)

This template would allow you query a value of T from the given span. Would primarily be used internally.

using Vec3f = Vec2<float>;
auto mesh = blend.GetBlock(BLOCK_CODE_ME);
auto mesh_type = blend.GetBlockType(*mesh);
auto totlayer = mesh_type->QueryValue<Vec3f>(mesh.header.data, "size"); // size is an array of the fundamental type float

BlendType::QueryValue(const Block& block, std::string_view query)

This template would allow you query a value of T from the block Block. Would primarily be used internally.

auto mesh = blend.GetBlock(BLOCK_CODE_ME);
auto mesh_type = blend.GetBlockType(*mesh);
auto totlayer = mesh_type->QueryValue<int>(mesh, "vdata.totlayer"); // vdata is an aggregate field, and totlayer is a fundamental field

BlendBlock::QueryValue(std::string_view query)

This template would allow you query a value of T from the given Block.

auto mesh = blend.GetBlock(BLOCK_CODE_ME);
auto totlayer = mesh->QueryValue<int>("totvert"); // totvert is a fundamental field

Query Language

The query language should be as simple as possible while still being robust.

Aggregates

Aggregate fields can be indexed directly by name.

mesh->QueryValue<SymmetryMode>("symmetry");

Arrays

Arrays can be returned by value.

mesh->QueryValue<Vec3f>("size");
mesh->QueryValue<float[3]>("size");
mesh->QueryValue<std::array<float, 8>>("size");

Arrays values can be directly addressed.

mesh->QueryValue<float>("loc[0]");
mesh->QueryValue<float>("loc[1]");
mesh->QueryValue<float>("loc[2]");

Pointers

Pointers are treated as if they are references with safety.

mesh->QueryValue("vdata.data");

Pointers can be indexed as arrays without safety.

mesh->QueryValue<Vertex>("vdata.data[0]");

Pointers can be read as arrays without safety.

mesh->QueryValue<Vertex[8]>("vdata.data[0]");
@SK83RJOSH
Copy link
Owner Author

SK83RJOSH commented Oct 20, 2022

Open questions:

  • Can we give type hints via the QL for void* fields?
  • Can we make pointer[0] accesses safe by referencing other fields?
  • Should we expose raw pointer access?
  • Should we ditch MemoryTable via pointer patching before reflection?

@SK83RJOSH SK83RJOSH added the enhancement New feature or request label Nov 4, 2022
@SK83RJOSH SK83RJOSH self-assigned this Nov 4, 2022
@SK83RJOSH SK83RJOSH linked a pull request Nov 4, 2022 that will close this issue
@SK83RJOSH SK83RJOSH added this to the v0.0.1 milestone Nov 4, 2022
@SK83RJOSH SK83RJOSH removed a link to a pull request Nov 6, 2022
@SK83RJOSH SK83RJOSH modified the milestones: v0.0.1, v0.0.2 Nov 6, 2022
@SK83RJOSH SK83RJOSH modified the milestones: v0.0.1, v0.0.2 Nov 6, 2022
@SK83RJOSH SK83RJOSH reopened this Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant