USRefl
1.0.0
__ __ _______..______ _______ _______ __
| | | | / || _ | ____|| ____|| |
| | | | | (----`| |_) | | |__ | |__ | |
| | | | | / | __| | __| | |
| `--' | .----) | | | ----.| |____ | | | `----.
______/ |_______/ | _| `._____||_______||__| |_______|
Github에 우리를 별표하십시오 - 도움이됩니다!
u bpa s tatic refection
헤더 전용, 작은 (99 라인) 및 강력한 C ++ 20 정적 반사 라이브러리.
온라인으로 실행하십시오 : 컴파일러 탐색기
struct Vec 반영해야한다고 가정합니다
struct Vec {
float x;
float y;
float norm () const { return std::sqrt (x*x + y*y); }
}; template <>
struct Ubpa ::USRefl::TypeInfo<Vec> :
TypeInfoBase<Vec>
{
static constexpr AttrList attrs = {};
static constexpr FieldList fields = {
Field { TSTR ( " x " ) , &Type::x },
Field { TSTR ( " y " ) , &Type::y },
Field { TSTR ( " norm " ), &Type::norm},
};
};99 라인 버전을 사용하는 경우 라인을 추가해야합니다.
static constexpr std::string_view name = " ... " ;
TypeInfo<Vec>::fields.ForEach([]( const auto & field) {
std::cout << field. name << std::endl;
}); std::invoke (TypeInfo<Vec>::fields.Find(TSTR( " y " )).value, v) = 4.f;
std::invoke (TypeInfo<Vec>::fields.Find(TSTR( " x " )).value, v) = 3.f;
std::cout
<< " x: "
<< std::invoke(TypeInfo<Vec>::fields.Find(TSTR( " x " )).value, v)
<< std::endl;std::cout
<< " norm: "
<< std::invoke(TypeInfo<Vec>::fields.Find(TSTR( " norm " )).value, v)
<< std::endl;TypeInfo<Vec>::ForEachVarOf(v, []( const auto & field, const auto & var) {
std::cout << field. name << " : " << var << std::endl;
});다음 두 가지 방법 중 하나를 선택할 수 있습니다
find package(USRefl REQUIRED) 를 사용하여 가져 오기 대상 Ubpa::USRefl_core 아래에서 라이센스 요약을 복사하여 붙여 넣을 수 있습니다.
MIT License
Copyright (c) 2020 Ubpa
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.