vir-reflect-light
lightweight macro based struct reflection
Science Score: 67.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 1 DOI reference(s) in README -
✓Academic publication links
Links to: zenodo.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.1%) to scientific vocabulary
Keywords
Repository
lightweight macro based struct reflection
Basic Info
Statistics
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 1
Topics
Metadata Files
README.md
vir-reflect-light
This package tries to be as light on compile-time as possible while enabling the following features:
List the number of data members.
Provide the variable names (identifiers) of the data members as
constexpr_string(which can be used asstd::string_viewvia the.view()member onconstexpr_string.Access lvalue references to the data members of a given object using either an index or the variable name.
Supports any inheritance hierarchy.
Allow exposing only a subset of the data members.
Installation
sh
make install prefix=/usr
Usage
The macro VIR_MAKE_REFLECTABLE
Add this macro in the public section of a class definition to make all listed class data members reflectable. The members that are not listed will be ignored and not be reflectable.
VIR_MAKE_REFLECTABLE(<class name>, [<data member name>, [<data member name>,
[...]]])
Example:
```c++
template
struct Point : Base
namespace yours
{
template
public: VIRMAKEREFLECTABLE(Person, height, weight); }; } ```
In the above yours::Person<T> example, note that:
VIRMAKEREFLECTABLE needs to be public.
The class name
Personin the macro can also be spelled asyours::Person<T>, orPerson<T>but not asyours::Person.first_nameandlast_namewill not be seen by thevir::refl::API. It is no error to omit them here if you want to hide them from the reflection API.
vir::refl::reflectable<T>
Concept that is satisfied if the class T definition contains a valid
(public) VIR_MAKE_REFLECTABLE expansion.
vir::refl::nttp_name<X>
A vir::constexpr_string object identifying the value/name of X. For
integers this will be a string representation of the value. For enums it is
equivalent to the following facility.
vir::refl::enum_name<X>
A vir::constexpr_string object identifying the name of X. This name
includes namespaces. For the name of the enum type use the following facility:
vir::refl::type_name<T>
A vir::constexpr_string object identifying the name of T. This name
includes namespaces and template arguments.
vir::refl::class_name<T>
A vir::constexpr_string object identifying the class name of T. This name
includes namespaces but no template arguments.
vir::refl::base_type<T>
Alias for the reflectable base type of the type T. If no base type exists (is
known) an alias for void.
There is no support for inheriting from multiple reflectable base classes. But multiple inheritance is otherwise not a problem. The derived class can also make members of the non-reflectable base type reflectable.
Given the above definition of Point and Base:
vir::refl::base_type<Point>is an alias forBase<Point>.vir::refl::base_type<Base>is an alias forvoid.
vir::refl::data_member_count<T>
A std::size_t value identifying the number of reflectable data members.
vir::refl::data_member_count<Point>is4.vir::refl::data_member_count<Base<Point>>is1.
vir::refl::data_member_name<T, Idx>
vir::refl::data_member_name<Base<Point>, 0>isvir::constexpr_string("id").vir::refl::data_member_name<Point, 0>isvir::constexpr_string("id").vir::refl::data_member_name<Point, 1>isvir::constexpr_string("x")....
vir::refl::data_member_index<T, Name>
The index value of the data member with the name Name of class T.
The name must match the name returned by data_member_name. It can be given as
a string literal or vir::fixed_string.
vir::refl::data_member_type<T, Idx> / data_member_type<T, Name>
Alias for the type of the data member with index Idx or name Name of class
T. data_member_index<T, Name> is used for mapping a name to an index.
vir::refl::data_member<Idx>(obj) / data_member<Name>(obj)
Returns a (const) lvalue-reference to the member of obj at the given index
Idx / with the given name Name. data_member_index<T, Name> is used for
mapping a name to an index.
vir::refl::all_data_members(obj)
Returns a vir::simple_tuple<...> of references to all the reflectable data
members of obj.
vir::refl::find_data_members<T, Predicate>
A constexpr std::array<size_t, N> identifying all data member indices that
match Predicate. Predicate needs to be a template with two template
arguments:
- A
typenamethat simply passes theTargument fromfind_data_memberson. - A
size_tindex identifying the data member to consider.
Example:
```c++ struct A { int foo; double x, y, z; float angle; };
template
constexpr std::array idxs = vir::refl::finddatamembers; // => idxs == {0, 4}
template
constexpr std::array idx2 = vir::refl::finddatamembers; // => idx2 == {0, 4} ```
vir::refl::find_data_members_by_type<T, Predicate>
Shorthand for the above so that standard type traits can be used as
Predicate. Predicate<data_member_type<T, Idx>> determines whether the index
Idx is returned from the array. The above sizeof4 predicate can thus be
written as:
```c++
template
constexpr std::array idxs = vir::refl::finddatamembersbytype; // => idxs == {0, 4} ```
vir::refl::data_member_types<T, IndexArray = /*all*/>
Alias for a vir::simple_tuple<...> type where the tuple types are equal to
the data member types of T at the indexes given by IndexArray. If
IndexArray is omitted, all data members will be listed.
vir::refl::for_each_data_member_index<T>(callable)
Calls the function callable with one argument of type
std::integral_constant<std::size_t, i>. The function is called for each i
in the half-open range 0 to data_member_count<T>.
Owner
- Name: Matthias Kretz
- Login: mattkretz
- Kind: user
- Location: Darmstadt, Germany
- Company: GSI Helmholtzzentrum für Schwerionenforschung
- Website: https://mattkretz.github.io/
- Repositories: 32
- Profile: https://github.com/mattkretz
C++ Committee Numerics Chair, SIMD specialist, CS PhD, Dipl.-Phys, High Energy Physics Software, former KDE core developer, ORCID: 0000-0002-0867-243X
Citation (CITATION.cff)
# This CITATION.cff file was initially generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!
#
# SPDX-FileCopyrightText: 2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
# SPDX-License-Identifier: CC0-1.0
cff-version: 1.2.0
title: vir-reflect-light
message: >-
If you use this software, please cite it using the metadata from
this file.
type: software
authors:
- given-names: Matthias
family-names: Kretz
email: m.kretz@gsi.de
affiliation: GSI Helmholtz Centre for Heavy Ion Research
orcid: 'https://orcid.org/0000-0002-0867-243X'
doi: 10.5281/zenodo.13762632
version: 0.0.190
date-released: 2024-09-14
identifiers:
- type: doi
value: 10.5281/zenodo.13762632
description: Version 0.0.190
repository-code: 'https://github.com/mattkretz/vir-simd'
keywords:
- C++
- reflection
- library
license: LGPL-3.0-or-later
GitHub Events
Total
Last Year
Committers
Last synced: 11 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Matthias Kretz | m****z@g****e | 65 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 10 months ago
All Time
- Total issues: 0
- Total pull requests: 1
- Average time to close issues: N/A
- Average time to close pull requests: about 22 hours
- Total issue authors: 0
- Total pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 1
- Average time to close issues: N/A
- Average time to close pull requests: about 22 hours
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
- mattkretz (2)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- actions/checkout v3 composite
- fair-software/howfairis-github-action 0.2.1 composite
- actions/checkout v4 composite
- fsfe/reuse-action v4 composite